CodeGraph Auto MCP
Languages: English | 中文 (Chinese)
A VS Code extension that automatically registers the CodeGraph MCP server when you open a project containing a .codegraph/ directory.
The Problem
CodeGraph provides an MCP (Model Context Protocol) server so that GitHub Copilot can use codegraph's code intelligence tools (codegraph_explore, codegraph_node, etc.). However, CodeGraph's MCP server is per-project — it needs the workspace root path to function correctly:
codegraph serve --mcp --path <workspace_root>
This creates two problems:
- Cannot use a global
mcp.json configuration — The --path argument varies per workspace, so a single global config can't cover all projects.
- VS Code bug #14166 — Even if you try to configure MCP servers via a global
mcp.json, VS Code has a bug where globally configured MCP servers do not auto-start. You have to manually reload the window or re-trigger MCP discovery every time.
The result: every time you open a project, you need to manually intervene to get CodeGraph working — a poor developer experience.
The Solution
This extension automatically registers the CodeGraph MCP server for each workspace using the official VS Code API registerMcpServerDefinitionProvider. When you open a project that has .codegraph/, the extension:
- Checks that
.codegraph/codegraph.db exists (project is indexed)
- Verifies the
codegraph CLI is available in PATH
- Registers the CodeGraph MCP server with the correct workspace root path — no manual
mcp.json configuration needed
The MCP server starts automatically with the right --path argument, and Copilot can immediately use codegraph tools.
Features
- 🔄 Auto-activation — activates when opening any project that has
.codegraph/ (using workspaceContains:.codegraph activation event)
- ✅ Dual validation — checks both that
codegraph.db exists and that the codegraph CLI is in PATH, preventing registration of a broken MCP server
- 🚀 Zero config — no
mcp.json editing, no manual steps, no reload required
- 🌐 Cross-platform — works on macOS, Linux, and Windows (automatically detects
codegraph.cmd on Windows)
- 📦 Lightweight — minimal code, zero runtime dependencies
Installation
From VSIX
- Download the latest
.vsix from Releases
- In VS Code, run Extensions: Install from VSIX...
- Select the downloaded file
From Source
git clone https://github.com/svenzhao/codegraph-auto-mcp.git
cd codegraph-auto-mcp
npm install
npm run build
Then press F5 in VS Code to start debugging, or install the extension manually:
npm run build
code --install-extension codegraph-auto-mcp-0.0.1.vsix
Usage
Once installed, the extension works automatically:
- Open any project that has a
.codegraph/ directory with a codegraph.db file
- Make sure the
codegraph CLI is available in your PATH
- The extension registers the CodeGraph MCP server — you can verify in VS Code's MCP server list
- GitHub Copilot can now use CodeGraph tools (
codegraph_explore, codegraph_search, codegraph_node, codegraph_callers) for code intelligence
Requirements
- VS Code ^1.106.0 (with Copilot Chat)
- CodeGraph CLI installed and in PATH
- A project with
.codegraph/ directory (initialized via codegraph init)
How It Works
flowchart LR
A[Open project<br/>with .codegraph/] --> B{Extension activates}
B --> C[Check .codegraph/<br/>codegraph.db exists]
B --> D[Find codegraph<br/>CLI in PATH]
C --> E[Register MCP server<br/>via registerMcpServerDefinitionProvider]
D --> E
E --> F[Copilot can now use<br/>CodeGraph tools]
The extension calls vscode.lm.registerMcpServerDefinitionProvider("codegraph", ...) with a provider that returns a McpStdioServerDefinition. This tells VS Code to start the CodeGraph MCP server using:
codegraph serve --mcp --no-watch --path <workspace_root>
The server is registered with the ID "codegraph", which matches the contribution in contributes.mcpServerDefinitionProviders.
Building
npm run build # compile TypeScript check + esbuild bundle
npm run compile # same as build
npm run watch # watch mode for development
License
MIT