code-graph-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@code-graph-mcptrace all callers of authenticate_user"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
code-graph-mcp
A high-performance code knowledge graph server implementing the Model Context Protocol (MCP). Indexes codebases into a structured AST knowledge graph with semantic search, call graph traversal, and HTTP route tracing — designed to give AI coding assistants deep, structured understanding of your code.
Features
Multi-language parsing — Tree-sitter AST extraction across tiers of depth:
Full (calls + imports + inheritance + test markers): TypeScript/TSX, JavaScript, Go, Python, Rust, Java. HTTP route extraction additionally covers TypeScript/TSX + JavaScript (Express/Connect), Go (
net/http), and Python (Flask/FastAPI) only — Rust and Java web frameworks are not yet route-extractedSmoke-tested (calls + imports + inheritance): C#, Kotlin, Ruby, PHP, Swift, Dart
Limited (functions + calls +
#includeimports + gtest test markers + C++ base-class inheritance;Class::methodscope qualification deferred): C, C++Scripting: Bash (functions + commands +
source/.imports), Markdown (headings)File-FTS only (no AST symbol extraction): HTML, CSS, JSON
Semantic code search — Hybrid BM25 full-text + vector semantic search with Reciprocal Rank Fusion (RRF), powered by sqlite-vec
Call graph traversal — Recursive CTE queries to trace callers/callees with cycle detection
HTTP route tracing — Map route paths to backend handler functions (Express, Flask/FastAPI, Go
net/http)Dead code detection — Find unreferenced symbols with smart Orphan/Exported-Unused classification
Impact analysis — Determine the blast radius of code changes by tracing all dependents
Incremental indexing — Merkle tree change detection with file system watcher for real-time updates. Smart event filtering skips metadata-only changes (chmod, xattr)
Context compression — Token-aware snippet extraction for LLM context windows (L0→full code, L1→summaries, L2→file groups, L3→directory overview). Compact JSON output saves 15-20% tokens
Embedding model — Optional local embedding via Candle (feature-gated
embed-model). Context reordered to prioritize structural relations over code for better embedding qualitySelf-healing — Automatic SQLite corruption recovery with rebuild. Startup repair for incomplete indexing (Phase 3 failures)
MCP protocol — JSON-RPC 2.0 over stdio, plug-and-play with Claude Code, Cursor, Windsurf, and other MCP clients
Claude Code Plugin — First-class plugin with slash commands (
/understand,/trace,/impact), agents, skills, auto-indexing hooks, StatusLine integration, and self-updating
Related MCP server: codebase-memory-mcp
Why code-graph-mcp?
Unlike naive full-text search or simple AST dumps, code-graph-mcp builds a structured knowledge graph that understands the relationships between symbols across your entire codebase.
Incremental by Design
BLAKE3 Merkle tree tracks every file's content hash. On re-index, only changed files are re-parsed — unchanged directory subtrees are skipped entirely via mtime cache. When a function signature changes, dirty propagation automatically regenerates context for all downstream callers across files.
Hybrid Search, Not Just Grep
Combines BM25 full-text ranking (FTS5) with vector semantic similarity (sqlite-vec) via Reciprocal Rank Fusion (RRF) with raw score blending — so searching "handle user login" finds the right function even if it's named authenticate_session. Results are auto-compressed to fit LLM context windows.
Scope-Aware Relation Extraction
The parser doesn't just find function calls — it tracks them within their proper scope context. Extracts calls, imports, inheritance, interface implementations, exports, and HTTP route bindings. Same-file targets are preferred over cross-file matches to minimize false-positive edges.
HTTP Request Flow Tracing
Unique to code-graph-mcp: trace from GET /api/users → route handler → service layer → database call in a single query. Supports Express, Flask/FastAPI, and Go HTTP frameworks.
Zero External Dependencies at Runtime
Single binary, embedded SQLite, bundled sqlite-vec extension, optional local embedding model via Candle — no database server, no cloud API, no Docker required. Runs entirely on your machine.
Built for AI Assistants
Every design decision — from token-aware compression to node_id-based snippet expansion — is optimized for LLM context windows. Works out of the box with Claude Code, Cursor, Windsurf, and any MCP-compatible client.
Performance
Metric | Value |
Indexing speed | 300+ files/second (single-threaded, release build) |
Incremental re-index | <250ms no-change detection via BLAKE3 Merkle tree |
FTS search P50 / P99 | <300us / <1ms |
Database overhead | ~3.5MB per 800 nodes |
Token savings | 5-20x fewer tokens per code understanding task vs grep+read |
Run code-graph-mcp benchmark on your own project to measure.
Efficiency: code-graph vs Traditional Tools
Real-world benchmarks comparing code-graph-mcp tools against traditional approaches (Grep + Read + Glob) on a 33-file Rust project (~537 AST nodes).
Tool Call Reduction
Scenario | Traditional | code-graph | Savings |
Project architecture overview | 5-8 calls | 1 call ( | ~85% |
Find function by concept | 3-5 calls | 1 call ( | ~75% |
Trace 2-level call chain | 8-15 calls | 1 call ( | ~90% |
Pre-change impact analysis | 10-20+ calls | 1 call ( | ~95% |
Module structure & exports | 5+ calls | 1 call ( | ~80% |
File dependency mapping | 3-5 calls | 1 call ( | ~75% |
Similar code detection | N/A | 1 call ( | unique |
Overall Session Efficiency
Metric | Without code-graph | With code-graph | Improvement |
Tool calls per navigation task | ~6 | ~1.2 | ~80% fewer |
Source lines read into context | ~8,000 lines | ~400 lines (structured) | ~95% less |
Navigation token cost | ~36K tokens | ~7K tokens | ~80% saved |
Full session token savings | — | — | 40-60% |
What code-graph Uniquely Enables
Impact analysis — "Changing
connaffects 33 functions across 4 files, 78 tests at HIGH risk" — impossible to derive manually with GrepTransitive call tracing — Follow
main→run_serve→handle_message→handle_tools_call→connin one querySemantic search — Find
authenticate_sessionwhen searching "handle user login"Dependency strength — Not just "file A imports file B", but "file A uses 38 symbols from file B"
When Traditional Tools Are Still Better
Use Case | Best Tool |
Exact string / constant search | Grep |
Reading a file to edit it | Read |
Finding files by name pattern | Glob |
Architecture
src/
├── domain.rs # Shared constants, relation types, env-var config
├── mcp/ # MCP protocol layer (JSON-RPC, tool registry, server)
│ └── server/ # McpServer with IndexingState + CacheState sub-structs
├── parser/ # Tree-sitter parsing, relation extraction, LanguageConfig dispatch
├── indexer/ # 3-phase pipeline, Merkle tree, file watcher
├── storage/ # SQLite schema (v6), CRUD, FTS5, migrations
├── graph/ # Recursive CTE call graph queries
├── search/ # RRF fusion search combining BM25 + vector
├── embedding/ # Candle embedding model (optional, masked mean pooling)
├── sandbox/ # Context compressor with token estimation
└── utils/ # Language detection, configInstallation
Option 1: Claude Code Plugin (Recommended)
Install as a Claude Code plugin for the best experience — includes slash commands, agents, skills, auto-indexing hooks, StatusLine health display, and automatic updates:
# Step 1: Add the marketplace
/plugin marketplace add sdsrss/code-graph-mcp
# Step 2: Install the plugin
/plugin install code-graph-mcpWhat you get:
MCP Server — All code-graph tools available to Claude
Slash Commands —
/understand <module>,/trace <route>,/impact <symbol>Code Explorer Agent — Deep code understanding expert via
code-explorerAuto-indexing Hook — Incremental index on every file edit (PostToolUse)
StatusLine — Real-time health display (nodes, files, watch status) — compatible with other plugins' StatusLine via composite multiplexer
Auto-update — Checks for new versions every 6h, updates silently
Manual Update
npm update -g @sdsrs/code-graphThen reconnect the MCP server in Claude Code with /mcp.
Note: Auto-update is disabled in the source repo directory (dev mode). Use manual update when developing the plugin itself.
Turning auto-update off
Environment variable | Effect |
| Skips the update check entirely — no version check, no download, and no updater process is started. A missing binary is still installed on first run, so the MCP server can't be left with no engine. Update manually with the command above. |
Set it in the env block of ~/.claude/settings.json (the environment of the
process hosting the MCP server), then reconnect with /mcp.
An update that keeps failing also stops hammering: after 5 failed attempts at
the same release the updater drops to one retry per day (and retries
immediately when a newer release is published), instead of re-downloading on
every session. While it is in that state the statusline shows ⚠ update stuck
and code-graph-mcp doctor prints the manual update command.
Invited-memory mode (quieter prompts)
By default, every user prompt the plugin deems code-related gets a small context injection from code-graph CLI output. If you'd rather rely on MEMORY.md + explicit tool calls, opt into invited-memory mode:
Adopt the plugin contract into your project (idempotent, self-heals):
code-graph-mcp adoptThis writes a sentinel-wrapped managed block into
<cwd>/CLAUDE.md(auto-loaded each session) plus<cwd>/.claude/plugin_code_graph_mcp.md(the full decision table, opened on demand). Runcode-graph-mcp unadoptto remove both; content outside the managed block is kept.Set the activation env var in
~/.claude/settings.json:{ "env": { "CODE_GRAPH_QUIET_HOOKS": "1" } }Restart Claude Code. Session startup skips the project-map injection, UserPromptSubmit stops auto-injecting context, and the MCP
instructionsbecome a short pointer to the MEMORY.md file.
Option 2: Claude Code MCP Server Only
Register as an MCP server without the plugin features:
claude mcp add code-graph-mcp -- npx -y @sdsrs/code-graphOption 3: Cursor / Windsurf / Other MCP Clients
Add to your MCP settings file (e.g. ~/.cursor/mcp.json):
{
"mcpServers": {
"code-graph": {
"command": "npx",
"args": ["-y", "@sdsrs/code-graph"]
}
}
}Option 4: npx (No Install)
Run directly without installing:
npx -y @sdsrs/code-graphOption 5: npm (Global Install)
Install globally, then run anywhere:
npm install -g @sdsrs/code-graph
code-graph-mcpUninstallation
Claude Code Plugin
# Uninstall the plugin
/plugin uninstall code-graph-mcp
# (Optional) Remove the marketplace
/plugin marketplace remove code-graph-mcp
# (Optional) Clean up all config and cache data
node ~/.claude/plugins/cache/code-graph-mcp/code-graph-mcp/*/scripts/lifecycle.js uninstallClaude Code MCP Server
claude mcp remove code-graph-mcpCursor / Windsurf / Other MCP Clients
Remove the code-graph entry from your MCP settings file (e.g. ~/.cursor/mcp.json).
npm (Global)
Run the teardown first, while the CLI still exists — npm 7 removed the
preuninstall/postuninstall lifecycle scripts, so nothing runs on your behalf
during npm uninstall. Doing it in the other order leaves the hook entries in
~/.claude/settings.json and the ~40 MB binary cache behind, with no command
left on disk to remove them.
code-graph-mcp uninstall # restore statusline, strip hooks, drop the cache
npm uninstall -g @sdsrs/code-graphMCP Tools
Tool | Description |
| Full project architecture: modules, dependencies, entry points, hot functions |
| Hybrid BM25 + vector + graph search for AST nodes |
| Trace upstream/downstream call chains for a function |
| Full request flow: route → handler → downstream call chain |
| Analyze the blast radius of changing a symbol |
| High-level overview of a module's structure and exports |
| Visualize dependency relationships between modules. Supports |
| Find semantically similar code via embeddings. Requires |
| Extract a specific code symbol with signature, body, and relations. Supports |
| Search AST nodes by text and/or structural filters (type, return type, params) |
| Find all references to a symbol (callers, importers, inheritors). Supports |
| Find unused code — orphan symbols and exported-but-unused public APIs |
CLI Commands
All tools are also available as CLI subcommands for shell scripts, hooks, and terminal workflows:
Command | MCP Equivalent | Description |
|
| FTS5 search by concept |
|
| Structural search with |
|
| Show call graph (callers/callees) |
|
| Impact analysis (callers, routes, risk level) |
|
| Show symbol details (code, type, signature) |
|
| Project architecture map |
|
| Module symbols grouped by file and type |
|
| File-level dependency graph |
|
| Trace HTTP route → handler → downstream calls |
|
| Find semantically similar code (requires embeddings) |
|
| Find all references to a symbol |
|
| Find unused code (orphans and exported-unused) |
| — | AST-context grep (ripgrep + containing function/class) |
| — | Run incremental index update (auto-creates DB if needed) |
|
| Query index status and freshness |
| — | Benchmark index speed, query latency, token savings |
Common options: --json (JSON output), --compact (compact output), --limit N, --depth N, --file <path>.
As of v0.37.0 the CLI is clap-based: every subcommand has --help for its full flag list (code-graph-mcp <command> --help), value flags accept both --flag value and --flag=value, and unknown flags or malformed arguments fail fast with a clear error and a non-zero exit code (2) instead of being silently ignored. For example, trace hides downstream middleware with --no-middleware (shown by default), and snapshot is a create/inspect subcommand pair.
Plugin Slash Commands
Available when installed as a Claude Code plugin:
Command | Description |
| Deep dive into a module or file's architecture and relationships |
| Trace a full HTTP request flow from route to data layer |
| Analyze the impact scope of changing a symbol before modifying it |
| Show code-graph index status and embedding progress |
| Force a full code-graph index rebuild |
Supported Languages (19)
Language | Extensions | Relations Extracted |
TypeScript | .ts, .tsx | calls, imports, exports, inherits, implements, routes_to |
JavaScript | .js, .jsx, .mjs, .cjs | calls, imports, exports, inherits, routes_to |
Go | .go | calls, imports, inherits, routes_to |
Python | .py, .pyi | calls, imports, inherits, routes_to |
Rust | .rs | calls, imports, inherits, implements |
Java | .java | calls, imports, inherits, implements |
C# | .cs | calls, imports, inherits, implements |
Kotlin | .kt, .kts | calls, imports, inherits |
Ruby | .rb | calls, imports, inherits |
PHP | .php | calls, imports, inherits, implements |
Swift | .swift | calls, imports, inherits |
Dart | .dart | calls, imports, inherits, implements |
C | .c, .h | calls, imports |
C++ | .cpp, .cc, .cxx, .hpp | calls, imports, inherits |
Bash | .sh, .bash | functions, commands, |
Markdown | .md, .mdx, .markdown | headings |
HTML | .html, .htm | file-FTS only (no AST symbols) |
CSS | .css | file-FTS only (no AST symbols) |
JSON | .json | file-FTS only (no AST symbols) |
Known limitations:
Kotlin/Swift interface conformance is recorded as
inherits(both use a single: Typegrammar for base classes and protocols/interfaces), soimplements-filtered queries return empty for these two languages.Cross-file dead-code detection may false-positive a type whose only cross-file reference sits beyond the 4096-byte stored-content cap per node (documented accepted limitation, v0.97.1).
Team-shared graph snapshot
Skip the full local index for team members and CI runners by publishing a ~3-5MB graph snapshot with each GitHub release.
Setup (one-time):
Copy
node_modules/code-graph-mcp/templates/code-graph-snapshot.ymlinto your repo's.github/workflows/.Push a release tag. The workflow uploads
code-graph-snapshot-<sha>.db.zstas a release asset.
Verify:
npx code-graph-mcp snapshot inspect ./code-graph-snapshot-<sha>.db.zstAfter setup, the auto-fetch is opt-in per consumer: an untrusted repo could
otherwise seed a misleading graph, so an unconfigured clone prints a hint and
skips the install. Enable it with one of the trust signals below. These live in
the environment (never in .code-graph.toml) so a committed/PR-injected config
file cannot set them.
Environment variable | Effect |
| Trust the auto-detected GitHub-release snapshot for this repo's |
| Pin the expected artifact digest (64-char blake3 hex). When set it is the sole integrity authority — the download must match it, no network sidecar is consulted — and it also implicitly trusts the origin path. |
| Honor a |
Integrity fail-closes: with no pin set and no fetchable <url>.blake3 sidecar,
install is refused rather than accepting unverified content. Set a pin, or have
the publisher serve the .blake3 sidecar alongside the snapshot. (file://
sources, used in tests, are exempt.)
Offline / air-gapped usage
The optional embedding model (needed for vector semantic search) is downloaded lazily on first use. To control that in a restricted environment:
Environment variable | Effect |
| Load |
| Disable the automatic background model download. An already-cached model is still loaded and used; the server otherwise stays in FTS5-only mode. |
Installing the model by hand
CODE_GRAPH_MODEL_DIR is the supported manual route. Hand-populating the
default cache dir (<platform cache>/code-graph/models) does not work:
that dir is only trusted once extract_and_promote has written a .model-id
marker, so a manually filled copy is treated as not-current and re-downloaded.
# Download + verify against the published checksum, then extract flat
# (the archive has no wrapping folder: model.safetensors, tokenizer.json, config.json).
curl -sL -o models.tar.gz \
https://github.com/sdsrss/code-graph-mcp/releases/download/v<version>/models.tar.gz
curl -sL https://github.com/sdsrss/code-graph-mcp/releases/download/v<version>/models.tar.gz.sha256
sha256sum -c models.tar.gz.sha256
mkdir -p ~/.cache/code-graph/models-manual
tar -xzf models.tar.gz -C ~/.cache/code-graph/models-manual
export CODE_GRAPH_MODEL_DIR=~/.cache/code-graph/models-manualOn Windows use %LOCALAPPDATA%\code-graph\models-manual, and give tar a POSIX
path for -C (/c/Users/<you>/...) — tar -C C:\... fails with
"Cannot connect to C: resolve failed". The model is pinned by content hash, so
a manual install must be redone on each version bump.
Diagnosing a model that never downloads
code-graph-mcp doctor reports the last download outcome, distinguishing
"no download has been attempted" from "download FAILED after N attempt(s): …"
with the underlying error. The raw record is
<platform cache>/code-graph/model-download.json. On a network that performs
TLS inspection, the download retries automatically against the OS certificate
store after the bundled roots are rejected.
Storage
Uses SQLite with:
FTS5 for full-text search
sqlite-vec extension for vector similarity search
Merkle tree hashes for incremental change detection
Data is stored in .code-graph/index.db under the project root (auto-created, gitignored).
Build from Source
Prerequisites
Rust 1.75+ (2021 edition)
A C compiler (for bundled SQLite / sqlite-vec)
Build
# Default build — FTS5-only (~10 MB binary, no embedding model)
cargo build --release
# With local embedding model (~150 MB binary; downloads ~120 MB model lazily on first semantic search)
cargo build --release --features embed-modelDirect
cargo installusers get the FTS5-only build by default. npm/npx/plugin users get the full hybrid (FTS5 + vector) build automatically — release CI compiles with--features embed-modelfor shipped binaries.
Configure (from source)
Add the compiled binary to your MCP settings:
{
"mcpServers": {
"code-graph": {
"command": "/path/to/target/release/code-graph-mcp"
}
}
}Development
# Run tests
cargo test
# Run tests without embedding model
cargo test --no-default-features
# Check compilation
cargo check
# Run performance benchmarks (indexing, search, call graph)
cargo bench --no-default-featuresLicense
See LICENSE for details.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityAmaintenanceCross-repository code knowledge graph MCP server for Java, Kotlin, JavaScript, and TypeScript. Indexes source code into embedded KuzuDB via tree-sitter and exposes 30+ tools for call-flow tracing, multi-hop taint analysis (OWASP/CWE/PCI/STIG), entry-point reachability filtering, performance hotspot detection, and license compliance — without reading source files. 95% fewer tokens vs source-readLast updated331MIT
- AlicenseAqualityAmaintenanceHigh-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 159 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.Last updated836,898MIT
- Alicense-qualityDmaintenanceMCP server for semantic code search and dependency graph analysis. Indexes codebases into a knowledge graph with vector embeddings for AI-powered code understanding.Last updated17MIT
- Alicense-qualityDmaintenanceInstant codebase knowledge graph MCP server. It auto-detects languages, indexes functions, classes, and call chains, enabling LLMs to navigate code in milliseconds.Last updatedMIT
Related MCP Connectors
Enterprise code intelligence for M&A, security audits, and tech debt. Hosted server with 200k free.
Local-first RAG engine with MCP server for AI agent integration.
An MCP server that gives your AI access to the source code and docs of all public github repos
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/sdsrss/code-graph-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server