
Cgraphy
io.github.pmgargPublished by GitHub account pmgargv0.1.1Updated Oct 25, 2026
Code knowledge graph over MCP: token-budgeted context for AI coding agents.
Overview
A local code knowledge graph server that indexes a repository and gives AI coding agents token-budgeted context about symbols, dependencies and changes.
- What you can do
- Orient in a repository with an overview map of subsystems, key symbols and files, and search symbols by ranked lexical or optional semantic matches, returning file and line locations with summaries. Retrieve a token-budgeted subgraph around a symbol, including callers, callees, imports and co-changes, or read a single symbol's source with line numbers. Assess the blast radius of a change, including transitive dependents, affected tests and historically co-changed files, and map a working git diff to touched symbols and covering tests. Enrich the graph by fetching batches of symbols that need one-line summaries and storing the summaries the agent writes.
- When to use it
- Useful when an assistant works in a larger codebase and should orient itself, find symbols and judge the impact of edits without reading many files on every prompt. Best suited to agents that can be steered to consult the graph before bulk file reading.
- Requirements
- Runs as a local process installed from PyPI (pip or uv), with Python and a repository path passed to the serve command. Indexing is done locally into a SQLite file in a .cgraphy directory. Optional semantic search needs an extra package; optional CI summarization needs an Anthropic API key.
Installation
In SourceWeft
- Open Cgraphy in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
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_contextexpands the graph greedily around a symbol and stops exactly at your token budget — cost scales with the question, not the repo. - Git-aware.
--git-historymines 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
Quick start
cgraphy init does three things:
- Writes a project-scoped
.mcp.json— picked up automatically by Claude Code in all its forms: CLI, VSCode extension, and the desktop app. - Appends a steering block to
CLAUDE.mdandAGENTS.mdtelling 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.) - Builds the index with git co-change history.
Or register the MCP server manually with your assistant:
Claude Code
Codex CLI (~/.codex/config.toml)
Gemini CLI (~/.gemini/settings.json) / Cursor (.cursor/mcp.json)
The eight tools
Reading / orientation:
Editing / reviewing — the tools that make the graph part of the change loop:
Enrichment:
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)
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
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
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)
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
cgraphy indexwalks 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.- A resolver links cross-file references (calls, imports, inheritance) by qualified name, best-effort; unresolved names are kept, never dropped.
- PageRank runs over the edge graph; every query surfaces important symbols first. Search blends FTS5 relevance with rank.
cgraphy serveexposes the five MCP tools over stdio.- Optional:
--git-historyadds weighted co-change edges mined fromgit 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:
License
MIT
mcp-name: io.github.pmgarg/cgraphy
Source: README.md at commit 4541e4f
Tools
0Version history
1- v0.1.1LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts