AST knowledge graph MCP server for Claude Code — semantic search, call graph traversal, HTTP route tracing, impact analysis. Auto-indexes 10 languages via Tree-sitter.
$git clone https://github.com/sdsrss/code-graph-mcpInstalls into the current project.
Install code-graph-mcp by running `git clone https://github.com/sdsrss/code-graph-mcp`, then use it for the current task and follow its documentation at https://github.com/sdsrss/code-graph-mcp.
| 1 | # code-graph-mcp |
| 2 | |
| 3 | A high-performance code knowledge graph server implementing the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/). 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. |
| 4 | |
| 5 | ## Features |
| 6 | |
| 7 | - **Multi-language parsing** — Tree-sitter AST extraction across tiers of depth: |
| 8 | - **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-extracted |
| 9 | - **Smoke-tested** (calls + imports + inheritance): C#, Kotlin, Ruby, PHP, Swift, Dart |
| 10 | - **Limited** (functions + calls + `#include` imports + gtest test markers + C++ base-class inheritance; `Class::method` scope qualification deferred): C, C++ |
| 11 | - **Scripting**: Bash (functions + commands + `source`/`.` imports), Markdown (headings) |
| 12 | - **File-FTS only** (no AST symbol extraction): HTML, CSS, JSON |
| 13 | - **Semantic code search** — Hybrid BM25 full-text + vector semantic search with Reciprocal Rank Fusion (RRF), powered by sqlite-vec |
| 14 | - **Call graph traversal** — Recursive CTE queries to trace callers/callees with cycle detection |
| 15 | - **HTTP route tracing** — Map route paths to backend handler functions (Express, Flask/FastAPI, Go `net/http`) |
| 16 | - **Dead code detection** — Find unreferenced symbols with smart Orphan/Exported-Unused classification |
| 17 | - **Impact analysis** — Determine the blast radius of code changes by tracing all dependents |
| 18 | - **Incremental indexing** — Merkle tree change detection with file system watcher for real-time updates. Smart event filtering skips metadata-only changes (chmod, xattr) |
| 19 | - **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 |
| 20 | - **Embedding model** — Optional local embedding via Candle (feature-gated `embed-model`). Context reordered to prioritize structural relations over code for better embedding quality |
| 21 | - **Self-healing** — Automatic SQLite corruption recovery with rebuild. Startup repair for incomplete indexing (Phase 3 failures) |
| 22 | - **MCP protocol** — JSON-RPC 2.0 over stdio, plug-and-play with Claude Code, Cursor, Windsurf, and other MCP clients |
| 23 | - **Claude Code Plugin** — First-class plugin with slash commands (`/understand`, `/trace`, `/impact`), agents, skills, auto-indexing hooks, StatusLine integration, and self-updating |
| 24 | |
| 25 | ## Why code-graph-mcp? |
| 26 | |
| 27 | 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. |
| 28 | |
| 29 | ### Incremental by Design |
| 30 | |
| 31 | 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. |
| 32 | |
| 33 | ### Hybrid Search, Not Just Grep |
| 34 | |
| 35 | 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. |
| 36 | |
| 37 | ### Scope-Aware Relation Extraction |
| 38 | |
| 39 | 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. |
| 40 | |
| 41 | ### HTTP Request Flow Tracing |
| 42 | |
| 43 | 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. |
| 44 | |
| 45 | ### Zero External Dependencies at Runtime |
| 46 | |
| 47 | 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. |
| 48 | |
| 49 | ### Built for AI Assistants |
| 50 | |
| 51 | 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. |
| 52 | |
| 53 | ## Performance |
| 54 | |
| 55 | | Metric | Value | |
| 56 | |--------|-------| |
| 57 | | Indexing speed | **300+ files/second** (single-threaded, release build) | |
| 58 | | Incremental re-index | **<250ms** no-change detection via BLAKE3 Merkle tree | |
| 59 | | FTS search P50 / P99 | **<300us / <1ms** | |
| 60 | | Database overhead | **~3.5MB** per 800 nodes | |
| 61 | | Token savings | **5-20x fewer tokens** per code understanding task vs grep+read | |
| 62 | |
| 63 | Run `code-graph-mcp benchmark` on |