CodeGraph MCP Server

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.

Category
访问服务器

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 typescript compiler API.
    • Python parsed using the standard library ast module.
    • We extract symbols (functions, classes, methods, variables, per-file modules) and edges (import, call, member_of, defines).
  • Graph format:

    • Simple JSON file at ./data/graph.json with symbols[] and edges[].
    • Easy to swap for SQLite or SCIP later.
  • 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 (./example with 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_symbol with { "q": "greet" }
  • graph.related with a returned symbol id
  • graph.impact_from_diff with 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.py uses ast to 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_diff refinements (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 ingest and confirm ./data/graph.json exists.
  • Windows path issues? Use absolute paths in the Claude config and wrap with quotes.
  • Python not found? Edit PYTHON_BIN in src/ingest/make_graph.ts to your interpreter path.

License: MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选