Cgraphy

io.github.pmgarg由 GitHub 帳號 pmgarg 發布v0.1.1更新於 Oct 25, 2026

Code knowledge graph over MCP: token-budgeted context for AI coding agents.

已驗證STDIO僅桌面知識與記憶開發者工具

概覽

AI 產生的概覽

一個本機程式碼知識圖譜伺服器,為 AI 程式設計助理索引程式碼庫,並依 token 預算提供符號、相依性與變更脈絡。

可以做什麼
透過儲存庫總覽圖了解子系統、關鍵符號與檔案,並依排序的词法或選用語意比對搜尋符號,回傳檔案與行號位置及摘要。依 token 預算取得某個符號周圍的子圖,包括呼叫端、被呼叫端、匯入與共同變更,或讀取單一符號含行號的原始碼。評估變更的影響範圍,包括傳遞相依、受影響的測試與歷史上共同變更的檔案,並把工作區 git diff 對應到涉及的符號與涵蓋測試。透過取得需要一句話摘要的符號批次並儲存助理撰寫的摘要來充實圖譜。
適用情境
適合助理在較大程式碼庫中工作、需要快速定位、尋找符號並判斷修改影響,而不必每次提示都讀取大量檔案的情境。最適合能被引導在大量讀檔前先查詢圖譜的助理。
執行需求
以本機程序從 PyPI 安裝(pip 或 uv)執行,需要 Python,並在 serve 指令中傳入儲存庫路徑。索引在本機寫入 .cgraphy 目錄下的 SQLite 檔案。選用語意搜尋需要額外安裝套件;選用的 CI 摘要產生需要 Anthropic API 金鑰。
安裝前請注意
init 指令會寫入專案層級的 MCP 設定,並向 CLAUDE.md 與 AGENTS.md 附加引導內容,因而修改儲存庫中的檔案。圖譜保存在本機,檢索遙測資料留在本機 SQLite 檔案中。選用的 CI 摘要產生會使用 ANTHROPIC_API_KEY 將程式碼傳送給 Anthropic。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Cgraphy,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

cgraphy – Code Knowledge Graph MCP Server

[PyPI version] [Python versions] [License] [DOI]

Paper (DOI): https://doi.org/10.5281/zenodo.21422935
PyPI: https://pypi.org/project/cgraphy/
GitHub: https://github.com/pmgarg/cgraphy

cgraphy is a Python code knowledge graph and Model Context Protocol (MCP) server for AI coding agents such as Claude Code, Codex CLI, Cursor, and Gemini CLI.

cgraphy indexes any codebase into a knowledge graph — functions, classes and files as nodes; calls, imports, inheritance and git co-change history as edges — and serves compact, token-budgeted slices of it to AI assistants through the Model Context Protocol. Instead of re-reading dozens of files to orient itself on every prompt, an agent asks the graph and gets the relevant subgraph in a couple of thousand tokens.

  • Any language. Full-fidelity extraction (calls, imports, inheritance) for Python, TypeScript/JavaScript, Java, Go, C, C++ and Rust; generic definition-level extraction for 20+ more via tree-sitter; config and docs files participate through summaries.
  • Importance-ranked. PageRank over the code graph puts load-bearing symbols first in every answer.
  • Token-budgeted. cgraphy_context expands the graph greedily around a symbol and stops exactly at your token budget — cost scales with the question, not the repo.
  • Git-aware. --git-history mines commit history for files that change together (logical coupling), an edge type static analysis can't see.
  • No API key. Semantic summaries are written by the host agent itself through the enrich loop; summaries survive re-indexing via content hashing.
  • Zero infrastructure. One SQLite file in .cgraphy/. No services, no daemons, no vector database.
  • Proven end-to-end. In 400+ controlled agent runs on SWE-bench Lite, the deployed configuration resolved 14 vs 8 of 57 real GitHub issues (official Docker harness). Indexes kubernetes (26K files, 219K nodes) in 49s, keeps it fresh in 1.6s cycles, answers queries in 1–152ms. All benchmarks and predictions are in this repo (Research paper and benchmarks).

Install

bash
pip install cgraphy        # or: uv tool install cgraphy

Quick start

bash
cd your-repocgraphy init          # one command: MCP config + agent steering + index

cgraphy init does three things:

  1. Writes a project-scoped .mcp.json — picked up automatically by Claude Code in all its forms: CLI, VSCode extension, and the desktop app.
  2. Appends a steering block to CLAUDE.md and AGENTS.md telling agents to consult the graph (cgraphy_overview → cgraphy_search → cgraphy_context) before reading files — this is what makes the graph actually replace bulk file reading. (Agents can't be forced, only steered: instruction files + persuasive tool descriptions + the tools being genuinely faster is the mechanism, and it works.)
  3. Builds the index with git co-change history.

Or register the MCP server manually with your assistant:

Claude Code

bash
claude mcp add cgraphy -- uvx cgraphy serve /path/to/repo

Codex CLI (~/.codex/config.toml)

toml
[mcp_servers.cgraphy]command = "uvx"args = ["cgraphy", "serve", "/path/to/repo"]

Gemini CLI (~/.gemini/settings.json) / Cursor (.cursor/mcp.json)

json
{"mcpServers": {"cgraphy": {"command": "uvx",                            "args": ["cgraphy", "serve", "/path/to/repo"]}}}

The eight tools

Reading / orientation:

ToolReturnsThe agent uses it…
cgraphy_overviewRepo map: subsystems, key symbols by importance, all filesfirst, instead of reading files to orient
cgraphy_searchRanked matches with file:line and summaries (hybrid lexical+semantic when the [semantic] extra is installed)before grep / directory listing
cgraphy_contextSubgraph around a symbol (callers, callees, imports, co-changes) within a token budgetinstead of reading whole files
cgraphy_readJust one symbol's source, line-numbered, budgetedinstead of reading the whole file

Editing / reviewing — the tools that make the graph part of the change loop:

ToolReturnsThe agent uses it…
cgraphy_impactBlast radius: direct + transitive dependents, affected tests, historically co-changed filesbefore modifying shared code
cgraphy_diff_contextThe working git diff mapped to touched symbols, their users, and covering testsbefore committing / when resuming work

Enrichment:

ToolReturnsThe agent uses it…
cgraphy_enrichBatch of symbols that still need one-line summarieswhen asked to "enrich the graph"
cgraphy_store_summariesConfirmation + remaining countto save the summaries it wrote

Retrieval is usage-aware: symbols an agent repeatedly asks about get a small, capped boost in future context expansion (telemetry stays in the local SQLite file; nothing leaves your machine).

Semantic search (optional)

bash
pip install "cgraphy[semantic]"

Adds tiny static embeddings (model2vec, CPU-only, no torch) fused with FTS5 by reciprocal-rank fusion — closes the vocabulary gap between issue-style prose ("login broken") and code identifiers (validate_jwt).

The graph self-heals: tools detect stale files and re-index incrementally (changed files only) before answering.

Enriching the graph

Structure is extracted automatically; meaning comes from summaries. Tell your agent once:

enrich the cgraphy graph

It will loop cgraphy_enrich → cgraphy_store_summaries until every symbol has a one-line semantic summary. Summaries are keyed to a hash of each symbol's source, so editing one function invalidates only that summary.

For CI, cgraphy index --summarize pre-bakes summaries with your own Anthropic API key (pip install cgraphy[summarize], ANTHROPIC_API_KEY set).

Viewer

bash
cgraphy view .        # http://localhost:8787

A dependency-free local page (bundled Cytoscape.js): search, color by kind, click for details, double-click to expand neighbors; co-change edges shown dashed.

Measuring the savings

bash
python scripts/benchmark.py /path/to/repo "your question"

Prints the tokens an agent spends orienting via cgraphy (overview + search + context) versus reading every code file, and the reduction factor.

Localization benchmark (research harness)

bash
python scripts/eval_localization.py /path/to/repo 50

Mines fix-like commits from the repo's history (subject = query, touched files = ground truth, co-change mining excludes evaluated commits), then scores an ablation ladder — FTS-only, +PageRank, +graph expansion, ±co-change edges — on hit@5/hit@10/MRR and token cost. No LLM calls, no human grading, fully reproducible. Results and a paper draft live in paper/.

How it works

  1. cgraphy index walks the repo (respecting .gitignore + .cgraphyignore), parses each file with tree-sitter, and stores nodes and edges in .cgraphy/graph.db (SQLite + FTS5). Re-indexing is incremental by content hash.
  2. A resolver links cross-file references (calls, imports, inheritance) by qualified name, best-effort; unresolved names are kept, never dropped.
  3. PageRank runs over the edge graph; every query surfaces important symbols first. Search blends FTS5 relevance with rank.
  4. cgraphy serve exposes the five MCP tools over stdio.
  5. Optional: --git-history adds weighted co-change edges mined from git log.

Design details: docs/superpowers/specs/2026-07-08-cgraphy-design.md

Citing cgraphy

If you use cgraphy in research or tooling, please cite the paper:

bibtex
@misc{garg2026cgraphy,  author = {Garg, Prateek Mohan},  title  = {Which Graph Signals Pay for Their Tokens? cgraphy: A Token-Budgeted            Code Knowledge Graph as a Portable Context Layer for AI Coding Agents},  year   = {2026},  doi    = {10.5281/zenodo.21422935},  url    = {https://doi.org/10.5281/zenodo.21422935},  note   = {Preprint}}

License

MIT

mcp-name: io.github.pmgarg/cgraphy

來源:README.md,提交 4541e4f

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.1最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分