AI Coding / MCP
codebase-memory-mcp:用 Tree-sitter 與 Property Graph 給 AI Agent 高速讀懂大型程式庫
codebase-memory-mcp 是一個高效能 code intelligence MCP server,以 C / Tree-sitter 建構本地 knowledge graph,搭配記憶體 SQLite、hash 檔案變更偵測與多語言 AST/LSP 語意解析,主打大型 codebase 毫秒級結構查詢。
2026年6月29日2 分鐘閱讀👁 10
codebase-memory-mcp 是一個面向 AI coding agent 的本地 code intelligence MCP server。它把 codebase 索引成 persistent knowledge graph,讓 agent 不必每次用 grep / read file 大量掃描,而能用結構化查詢取得函式、類別、呼叫鏈、HTTP routes 與跨服務關係。
原串重點
原作者閱讀了 codebase-memory-mcp 的源碼與論文後,指出它的性能設計主要來自幾個選擇:
- 基於 Tree-sitter 做多語言 AST 解析,核心主要以 C 實作。
- 自建記憶體中的 SQLite pipeline,把索引性能推到極限。
- Knowledge Graph 採 Property Graph 思路,Call Graph 等不同 semantics 存在同一張 graph 裡,用不同 edge 類型區分。
- 使用高效 hash 偵測檔案變更,避免重建整個索引。
- 原串提到 fresh index Linux kernel 約 2.1M nodes / 4.9M edges,三分多鐘完成。
官方 repo 驗證
| GitHub | DeusData/codebase-memory-mcp |
|---|---|
| 描述 | High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 158 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies. |
| 主要語言 | C |
| License | MIT |
| Stars / Forks | 約 19,957 stars / 1,440 forks(整理時 GitHub API) |
| 論文 | README 連到 arXiv:2603.27277〈Codebase-Memory: Tree-Sitter-Based Knowledge Graphs for LLM Code Exploration via MCP〉 |
架構理解:為什麼它適合 agent?
| 問題 | 傳統 agent 做法 | codebase-memory-mcp 做法 |
|---|---|---|
| 理解大型 codebase | 反覆 grep、讀檔、猜路徑,token 消耗高。 | 先建 graph,再用 MCP tool 問結構化問題。 |
| 跨檔案關係 | 靠文字搜尋與上下文拼湊。 | 把函式、類別、call graph、routes、service links 以節點與 edge 表示。 |
| 更新索引 | 可能整包重掃。 | 用 hash 偵測檔案變更,支援 incremental 更新。 |
| 查詢速度 | 取決於檔案數與工具往返。 | README 主張 structural queries 可 sub-ms。 |