Codebase-Memory-MCP: 3-Minute Linux Kernel Indexing, 120x Token Savings
> Paper: Vogel M, et al. (2026). *Codebase-Memory: Tree-Sitter-Based Knowledge Graphs for LLM Code Exploration via MCP*. arXiv:2603.27277 > Project: https://github.com/DeusData/codebase-memory-mcp > Authors: Martin Vogel, Falk Meyer-Eschenbach, Severin Kohler, Elias Grünewald, Felix Balzer (Berlin team) > License: MIT > Languages: 158 via Tree-Sitter grammars; Hybrid LSP for Python, TS/JS/JSX/TSX, PHP, C#, Go, C, C++, Java, Kotlin, Rust
One-line positioning
This is not another code search tool. It turns a codebase's structure into a queryable knowledge graph, exposed through 14 MCP tools to any AI coding assistant. One graph, one indexing pass—then every subsequent query takes under 1ms and ~1,000 tokens, instead of tens of thousands from file-by-file grep.
Key points
- Performance story: Indexes the Linux kernel (28M LOC, 75K files → 2.1M nodes, 4.9M edges) in ~3 minutes on an Apple M3 Pro via a RAM-first pipeline (LZ4 HC, Aho-Corasick, pthread worker pools) with SQLite persistence.
- Token efficiency: 5 structured queries cost ~3,400 tokens vs ~412,000 tokens for file-by-file exploration (up to 120x reduction). BFS call-path tracing runs in ~0.3ms; dead-code detection ~150ms.
- vs. CodeGraph: Same pain point (AI assistants re-exploring codebases each session), different tradeoffs—Codebase-Memory-MCP is a zero-dependency single binary with 158 languages, incremental sync (XXH3 content hashes + background watcher), git-shareable compressed graph snapshots, and stronger security verification.
- 14 MCP tools in 4 groups: indexing (
index_repository,list_projects,delete_project,index_status), querying (search_graph,trace_call_path,query_graph,ingest_traces), analysis (detect_changes,get_graph_schema,get_architecture), and code (get_code_snippet,search_code,manage_adr). - Hybrid LSP: A lightweight C type-resolution engine (structurally compatible with tsserver, pyright, gopls, Roslyn, JDT, rust-analyzer) is compiled into the binary—no language-server processes, per-project config, or API keys. It refines CALLS edges over Tree-Sitter's syntax-level output.
- Security (8-layer CI audit): static libc-call whitelisting, post-build binary string audit, strace-based network egress monitoring, install-path sandboxing, hardened smoke tests, frontend audit, 23 adversarial JSON-RPC payloads (SQLi/shell injection/path traversal/ReDoS), and SHA-256 checks on 72 vendored files. Release gates: VirusTotal (70+ engines, zero detections), SLSA L3 (Sigstore cosign), CodeQL, OpenSSF Scorecard, CycloneDX SBOM, sanitizer soak tests.
- Team-shareable graphs:
.codebase-memory/graph.db.zstsnapshots (SQLite → VACUUM INTO → zstd, 8-13:1) can be committed to git withmerge=oursso teammates skip full re-indexing. - Graph wins (19/31 languages): hub detection, caller ranking, cross-file dependency chains.
- File wins (16/31 languages): full-source-context questions, exhaustive line-by-line grep.
- Worst case: macro-heavy C (0.58 vs 1.00) since macros aren't in Tree-Sitter ASTs.
- Conclusion: a hybrid architecture is optimal—graph for structural queries, files for source-level tasks.
Benchmark reality check
Head-to-head on 31 real repositories, 12 question types:
| Metric | MCP agent (graph) | Exploration agent (files) | Gap | |---|---|---|---| | Quality score | 0.83 | 0.92 | 90% | | Tool calls/question | 2.3 | 4.8 | 2.1x fewer | | Tokens/question | ~1,000 | ~10,000 | 10x fewer | | Query latency | <1ms | 10-30s | >100x faster |
Limitations
1. Macros, dynamic reflection, and runtime-generated code are absent from the graph. 2. The 83% vs 92% quality gap still requires fallback to file exploration. 3. Single-repository only; multi-repo dependency tracking is future work. 4. Static structure only—no runtime behavior or dynamic dispatch. 5. All benchmarks on Apple M3 Pro; other platforms may differ. 6. Built-in semantic search relies on a single embedded model (Nomic nomic-embed-code, 768d int8).
Core conclusions
1. This is code-structure infrastructure, not a code search tool—one indexing pass, constant-time queries thereafter. 2. The 3-minute kernel index is a real engineering result: RAM-first pipeline, LZ4, Aho-Corasick, parallel workers. 3. The 120x token reduction comes from precomputation—the graph pays the index cost once. 4. The single-binary, zero-dependency bet (parsing, type inference, graph storage, MCP protocol in one C binary) is a notable engineering achievement. 5. The 8-layer security audit responds to MCP's trust problem and should become an ecosystem standard. 6. vs. CodeGraph: pragmatic sufficiency vs. performance maximalism—choose based on team size and performance sensitivity.
> "In the AI coding era, developers need infrastructure that is not faster grep, but precomputed structure."
---
*Reference: Vogel M, et al. (2026). Codebase-Memory: Tree-Sitter-Based Knowledge Graphs for LLM Code Exploration via MCP. arXiv:2603.27277.*