codegraph-mcp
Provides Claude Code with a repository symbol graph via tree-sitter, enabling instant symbol lookup, file skeletons, call-site analysis, and persistent notes, reducing token usage by reading signatures instead of whole files.
README
codegraph-mcp
Local MCP server that gives Claude Code (CLI and the VS Code extension) a queryable model of your codebase — where things are defined, who calls what, what depends on what, and what was decided in earlier sessions. Without it the agent rediscovers your architecture every session through grep and file-by-file reading; with it, structural questions get structural answers:
- Safer changes — before touching a function the agent sees its blast
radius (
analyze_impact), every call site (find_callers), every mention (find_references) and every dependent module (who_imports), instead of editing whatever grep happened to surface. - Faster orientation — one
repo_mapcall maps the project by import centrality;find_symbolandsemantic_search("where is auth token validated") land directly on the right code. - Continuity —
save_note/recall_notescarry decisions and gotchas across sessions, per repository. - Cheaper exploration — as a consequence of the above the agent reads
signatures instead of whole files (
file_skeleton,read_symbol), and a transparent proxy compresses conversation history at the wire level.usage_statsreports the measured savings.
100% portable: pure JavaScript + WASM grammars. No node-gyp, no native
compilation. npm install works identically on Windows, macOS and Linux.
Tools exposed to the agent
Understanding & navigation
| Tool | What it does |
|---|---|
repo_map |
Project map: languages, counts, key files by import centrality; html=true writes an interactive architecture map |
find_symbol |
Locate a function/class/method/type definition by name, repo-wide |
semantic_search |
Find code/notes by meaning ("where is auth token validated") |
Change safety
| Tool | What it does |
|---|---|
analyze_impact |
Transitive callers (blast radius) before changing a function |
find_references |
Every mention of an identifier — call sites marked [call] — with the enclosing symbol |
who_imports |
Direct dependents of a module (reverse import graph) |
Focused reading
| Tool | What it does |
|---|---|
file_skeleton |
Imports + all signatures of a file, no bodies (10–50× fewer tokens) |
read_symbol |
Read the full source of one symbol without reading the file |
Memory & operations
| Tool | What it does |
|---|---|
save_note / recall_notes |
Persistent per-repo notes that survive sessions |
reindex |
Force incremental or full re-scan |
usage_stats |
Calls per tool + tokens saved; dashboard=true also writes the HTML report |
Supported languages: JavaScript, TypeScript, TSX, Python, Go, Rust, Java,
Ruby, C, C++, C#, PHP, GDScript. Files the indexer cannot extract are counted
and reported by repo_map, so partial coverage is always visible.
Install
Requires Node.js ≥ 20 and Claude Code. Identical on Windows / macOS / Linux:
git clone https://github.com/denzharkov/codegraph-mcp
cd codegraph-mcp && npm install
node bin/codegraph-mcp.js install # registers in Claude Code (user scope)
That's it — the install command runs claude mcp add for you, and the
server works in the CLI and the VS Code extension (they share MCP
configuration). Verify with claude mcp list or /mcp inside Claude Code.
The server indexes the directory it is started in (Claude Code starts MCP
servers in the project directory), or the path given via --root /
CODEGRAPH_ROOT. To limit it to a single project instead of user scope, add
.mcp.json to that project:
{
"mcpServers": {
"codegraph": {
"command": "node",
"args": ["/absolute/path/to/codegraph-mcp/bin/codegraph-mcp.js"]
}
}
}
To remove: node bin/codegraph-mcp.js uninstall.
Zero configuration
No CLAUDE.md edits or prompt tweaks are needed: the server ships its usage
guidance ("run analyze_impact before changing a function, find_symbol
instead of grep, file_skeleton before reading a file, …") through the MCP
instructions field, which Claude Code injects into the agent's context
automatically on connect. Install, register, done.
Transparent proxy (guaranteed savings)
The MCP tools above save tokens only when the agent chooses to use them. The proxy layer works the other way — like ContextForge, it sits between Claude Code and the Anthropic API and compresses traffic regardless of agent behavior:
- History deduplication: when the conversation contains identical tool results (the same file read twice, repeated command output), every occurrence after the first is replaced with a short stub before the request leaves your machine. The first occurrence stays verbatim, so the model loses nothing it could actually use — and the prompt-cache prefix is preserved (only the new tail is ever rewritten, so dedup never causes cache misses on old turns).
- Stale-read skeletonization: when a file was read, edited, and read again, the older full copy in history is replaced by its tree-sitter signature skeleton (imports + declarations with line ranges); the newest read always stays verbatim. Non-code files fall back to head+tail truncation. Transforms are pure functions of the content, so repeated requests produce identical bytes and the prompt cache re-stabilizes after a single rewrite.
- Prompt grounding: your message is transformed before it reaches the
model — the safe way. The words are never rewritten; instead the proxy
appends a clearly-labeled block of verifiable facts about the identifiers
the message mentions (kind,
file:lines, one-line doc from the symbol graph). The model starts oriented instead of spending tool round-trips discovering the same facts. Only exact-case matches ground, only the newest message gets a fresh block, and blocks are memoized so history stays byte-stable for the prompt cache. - Auth headers pass through untouched (API key or OAuth). Anything the proxy cannot parse is forwarded verbatim. Streaming (SSE) is piped through.
codegraph-mcp wrap # like 'cf wrap claude': proxy + claude in one command
codegraph-mcp proxy --port 3210 # or run the proxy standalone
For the VS Code extension, run the proxy and point the extension at it via project or global settings:
{ "env": { "ANTHROPIC_BASE_URL": "http://127.0.0.1:3210" } }
Cumulative savings are tracked in ~/.codegraph/proxy-stats.json and printed
on proxy start.
CLI usage
node bin/codegraph-mcp.js index # index cwd, print stats
node bin/codegraph-mcp.js index --root ~/proj # index another directory
node bin/codegraph-mcp.js dashboard # HTML report, opens in browser
node bin/codegraph-mcp.js map # interactive architecture map
node bin/codegraph-mcp.js # start stdio MCP server (cwd)
The architecture map (.codegraph/map.html) is a layered, C4-style view of
the repo, fully derived from the index:
- Overview — subsystem cards (top-level directories) with weighted import edges between them, plus auto-derived starting points (hub, entry point, largest module);
- Subsystem — the files of one directory with their import edges and collapsed neighbor subsystems; click a file to trace dependents and dependencies, click again to drill in;
- File — its symbols with intra-file call arrows, importers and imports as navigable columns.
Every level narrates purpose, not just structure: descriptions are pulled
from the code's own documentation — module docstrings and header comments for
files and symbols, READMEs / __init__.py / index.* for folders and the
repo itself — and shown on folder cards, in tooltips and in the side panel.
Levels are deep-linkable (#d=src, #f=src/proxy.js), search with /,
Esc goes up a level, drag pans, wheel zooms. Self-contained HTML, offline.
The dashboard (--no-open to just write the file) lands in
.codegraph/dashboard.html: token savings, per-tool usage, indexed languages
and the most-imported files. Static HTML, no server, light/dark aware. The
agent can also generate it on request via usage_stats with dashboard=true.
How it works
- Files are parsed with tree-sitter WASM grammars (
tree-sitter-wasmspackage) viaweb-tree-sitter— no platform-specific binaries. - The extractor walks each AST once, collecting definitions, call edges and imports per language spec (src/languages.js).
- The graph persists to
.codegraph/index.jsoninside the target repo; refreshes are incremental (mtime+size) and throttled, so queries stay fast. node_modules, build output, vendored and minified files are skipped; simple root.gitignorepatterns are honored.semantic_searchuses a local embedding model (all-MiniLM-L6-v2 via transformers.js, an optional dependency). On first use it downloads ~25 MB into~/.codegraph/modelsand caches symbol vectors per repo in.codegraph/vectors.bin. Offline or without the dependency it silently falls back to keyword search — everything else works regardless.
Add .codegraph/ to your project's .gitignore (it's a cache plus your
private notes).
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 模型以安全和受控的方式获取实时的网络信息。