Skip to content

MCP Mode#388

Open
moigagoo wants to merge 85 commits intonim-lang:masterfrom
moigagoo:feature/mcp_server
Open

MCP Mode#388
moigagoo wants to merge 85 commits intonim-lang:masterfrom
moigagoo:feature/mcp_server

Conversation

@moigagoo
Copy link
Copy Markdown
Contributor

@moigagoo moigagoo commented Apr 4, 2026

This PR adds an MCP (Model Context Protocol) server mode to nimlangserver, enabling AI coding agents (GitHub Copilot, Gemini, Claude, etc.) to use the language server as an MCP tool provider in addition to its existing LSP role.

Five MCP tools are exposed, backed by nimsuggest:

┌─────────────────────┬────────────────────────────────────────────────────────────────────┐
│ Tool                │ Description                                                        │
├─────────────────────┼────────────────────────────────────────────────────────────────────┤
│ nimFindReferences   │ Find all references to the symbol at a given location              │
├─────────────────────┼────────────────────────────────────────────────────────────────────┤
│ nimFindSymbols      │ Search for symbols matching a query across the workspace           │
├─────────────────────┼────────────────────────────────────────────────────────────────────┤
│ nimListSymbols      │ List all symbols defined in a specific file                        │
├─────────────────────┼────────────────────────────────────────────────────────────────────┤
│ nimCheckProject     │ Run diagnostics on the entire project                              │
├─────────────────────┼────────────────────────────────────────────────────────────────────┤
│ nimCheckFile        │ Run diagnostics on a single file                                   │
└─────────────────────┴────────────────────────────────────────────────────────────────────┘

Tools return structured JSON conforming to MCP's outputSchema format.

  • New --mcp / --lsp CLI flags select the server mode at startup (--lsp is the default)
  • MCP uses stdio transport with newline-delimited JSON (distinct from LSP's Content-Length
    framing)
  • MCP and LSP modes share the same LanguageServer core and nimsuggest backend

Skill definitions instructs AI agents to prefer these MCP tools over grep/shell for all Nim symbol and diagnostics tasks, with guidance on Nim-specific terminology mapping.

MCP config files are included for Copilot CLI (.mcp.json), VS Code (.vscode/mcp.json), and Gemini (.gemini/settings.json).

Once nimlangserver is registered as an MCP server, AI agents can call the tools directly. For example, asking "check this project for errors" triggers nimCheckProject and returns structured diagnostics:

{
  "diags": [
    {
      "path": "/path/to/mymodule.nim",
      "line": 12,
      "column": 5,
      "severity": "Error",
      "message": "type mismatch: got 'string' but expected 'int'"
    }
  ]
}

Asking "find all usages of myProc" calls nimFindReferences at the symbol location and returns:

{
  "refs": [
    { "path": "/path/to/main.nim", "line": 7, "column": 3 },
    { "path": "/path/to/utils.nim", "line": 42, "column": 11 }
  ]
}

@moigagoo moigagoo changed the title Feature/mcp server MCP Mode Apr 23, 2026
@moigagoo moigagoo marked this pull request as ready for review April 23, 2026 12:19
Comment thread routes/mcp.nim
Comment thread routes/mcp.nim
Comment thread routes/mcp.nim
Comment thread utils.nim
@moigagoo moigagoo requested a review from jmgomez April 27, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants