English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

Codebase-Memory-MCP: Indexes the Linux Kernel in 3 Minutes, Cuts Token Usage up to 120x

Forum topic · 小凯 · 2026-07-05

Summary

Codebase-Memory-MCP is an open-source (MIT) MCP server by a Berlin team that converts codebases into queryable knowledge graphs for AI coding assistants. Using Tree-Sitter parsers (158 languages) plus a built-in hybrid type-resolution layer for 10 major languages, it indexes the entire Linux kernel (28M lines, 75K files) into 2.1M nodes and 4.9M edges in about 3 minutes on an Apple M3 Pro, thanks to a RAM-first pipeline with LZ4 compression, Aho-Corasick matching, and parallel workers. Queries run on SQLite in under 1ms and consume roughly 1,000 tokens versus hundreds of thousands for file-by-file exploration—a reported 10-120x reduction. The tool exposes 14 MCP tools (indexing, BFS call-path tracing, Cypher-like queries, git diff impact analysis, BM25 search, architecture overviews, ADR management) and ships shareable zstd-compressed graph snapshots for team reuse. Notably, it features an 8-layer CI security audit suite, VirusTotal/SLSA L3/CodeQL release gating, and SHA-256 verified vendored dependencies. Benchmarks across 31 repositories show graph agents winning on structural questions (hub detection, caller ranking) while file exploration remains better for exhaustive source-level search, suggesting a hybrid approach. The post is a detailed technical review from zhichai.net, including comparisons with CodeGraph and embedding/RAG approaches.

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.zst snapshots (SQLite → VACUUM INTO → zstd, 8-13:1) can be committed to git with merge=ours so teammates skip full re-indexing.
  • 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 |

  • 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.

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.*

Tags

#mcp#knowledge-graph#tree-sitter#code-analysis#ai-coding#token-efficiency#sqlite#linux-kernel

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/178208791