CodeGraph MCP Server
Enables querying and analyzing code relationships by building a lightweight graph of TypeScript and Python symbols. Supports symbol lookup, reference tracking, impact analysis from diffs, and code snippet retrieval through natural language.
README
nabi-codegraph-mcp — Minimal Code Graph + MCP Server (TS + Python)
This is a self-contained starter that builds a lightweight code graph over TypeScript and Python, then exposes it via an MCP server so agentic clients (Claude Desktop, Cursor, Copilot Studio, OpenAI Agents, Azure) can query it.
Design goals: tiny, pragmatic, easy to extend. No heavyweight LSIF/SCIP indexers required to get started (though you can integrate them later).
What you get
-
Ingestion (no build required):
- TypeScript parsed using the official
typescriptcompiler API. - Python parsed using the standard library
astmodule. - We extract symbols (functions, classes, methods, variables, per-file modules) and edges (
import,call,member_of,defines).
- TypeScript parsed using the official
-
Graph format:
- Simple JSON file at
./data/graph.jsonwithsymbols[]andedges[]. - Easy to swap for SQLite or SCIP later.
- Simple JSON file at
-
MCP Server (
code-graph):graph.resolve_symbol({ q })→ fuzzy lookup of symbols by name.graph.references({ id })→ inbound edges (who calls/imports this symbol).graph.related({ id, k })→ k neighbors (imports/calls).graph.impact_from_diff({ patch })→ changed files + 1‑hop neighbor impact set.- Resource:
code://file/{path}?s=..&e=..→ stream code snippets for context windows.
-
Example repo to test ingestion (
./examplewith TS + Py files).
Prereqs
- Node.js 20+ (recommended LTS).
- Python 3.10+ (standard library only).
Tip: This repo avoids native DB bindings for maximum portability. The graph is stored in JSON and loaded into memory by the server.
Quick start (5 minutes)
# 1) Install deps
npm install
# 2) Build a graph from the example code
npm run ingest -- --target ./example
# 3) Run the MCP server (stdio)
npm run dev:server
You should see code-graph start and announce tools.
Use with Claude Desktop (macOS/Linux/Windows)
Add an entry to your Claude Desktop config to register the MCP server via stdio.
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Use the included template and replace the absolute path to this folder:
{
"mcpServers": {
"code-graph": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/dist/mcp/server.js"],
"environment": {
"NABI_GRAPH_JSON": "/ABSOLUTE/PATH/TO/data/graph.json"
}
}
}
}
Restart Claude Desktop. In a new chat, ask it to connect to the code-graph MCP server and try tools like:
graph.resolve_symbolwith{ "q": "greet" }graph.relatedwith a returned symbolidgraph.impact_from_diffwith a pasted patch
Note: Clients differ in how they surface MCP tools. In Claude, you can view connected tools/resources in the session sidebar.
Commands & scripts
# Dev server (TypeScript via tsx)
npm run dev:server
# Compile to dist/ (pure JS ESM)
npm run build
npm start # runs the built server
# Ingest (scan target directory and build ./data/graph.json)
npm run ingest -- --target ./example
npm run ingest -- --target /path/to/your/repo
# Optional: re-run impact analysis from a diff file
cat my.patch | npm run impact
How ingestion works (tl;dr)
- TypeScript: We use the TS compiler API to walk each file’s AST, collect symbols (functions/classes/methods/variables), calls, and imports. We also create a per-file module symbol as an anchor.
- Python: A small
py/ingest_py.pyusesastto do the same. It prints NDJSON on stdout which the Node orchestrator reads and merges. - Edge resolution: Calls are matched to definitions by name with a simple heuristic (prefer same-file symbols first, otherwise the first match). This is intentionally simple—enough to bootstrap your graph and make MCP queries useful.
Later, you can plug in Tree‑sitter or SCIP for deeper, cross-repo precision.
Data model
type Range = { startLine: number; startCol: number; endLine: number; endCol: number };
type Symbol = {
id: string; kind: 'function'|'class'|'method'|'variable'|'module';
name: string; file: string; range: Range; language: 'typescript'|'python';
signature?: string; parentId?: string|null;
};
type EdgeType = 'defines'|'call'|'import'|'member_of';
type Edge = { src: string; type: EdgeType; dst: string };
type Graph = { symbols: Symbol[]; edges: Edge[] };
Roadmap: where to take it
- Add SCIP ingestion (scip-ts / scip-python) and merge edges alongside this AST path.
- Swap JSON storage for SQLite and add indexes for large monorepos.
- Add structural rewrites/codemods hooks and
graph.impact_from_diffrefinements (graph radius weighting, churn priors). - Expose a search resource:
graph://symbol?q=...that streams snippets directly.
Troubleshooting
- If the server prints “No graph loaded,” run
npm run ingestand confirm./data/graph.jsonexists. - Windows path issues? Use absolute paths in the Claude config and wrap with quotes.
- Python not found? Edit
PYTHON_BINinsrc/ingest/make_graph.tsto your interpreter path.
License: MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。