
Turn any repository into a graph of its files, folders and functions and the links between them.
Turn any repository into a graph of its files, folders and functions and the links between them.
·
AST-driven code graphs & zero-dependency GraphRAG for AI coding agents and humans
English · 简体中文 · 日本語 · Français · Español · Deutsch
What is it · Quickstart · MCP setup · Compare · Benchmarks · Architecture · Docs · Contributing
When an AI coding agent searches a codebase with grep or plain keyword matching, it either dumps whole matching files into context — burning the token budget and losing structure — or misses the implementation entirely because it used different words than the search query.
repo2graph parses source with tree-sitter into a
graph of real code relationships — CALLS, IMPORTS, INHERITS, DEFINES, CO_CHANGE — and
serves that graph to agents over the Model Context Protocol, or packs it into a budget-bounded
markdown context for any LLM. Every returned block carries an exact [cite: path:start-end]
anchor, so answers are traceable back to source instead of paraphrased from a guess.
flowchart LR
A[your code] --> B[tree-sitter<br/>reads the code]
B --> C[graph<br/>dots + arrows]
C --> D[graph.html<br/>the picture]
C --> E[chunks.jsonl<br/>pieces for an AI]
C -->|MCP stdio| F[Claude / Cursor /<br/>any MCP client]No project setup, no language server, no build step — point it at a folder and it works.
| Interactive canvas, zoomed | Filter & inspector controls |
|---|---|
![]() | ![]() |
graph.html is one self-contained file — no server, no internet, drag to pan, scroll to zoom,
click a node to inspect its code and neighbours.
Same graph, same chunk format, same .r2g output — pick the interface for where you're
standing right now.
| 🐍 Python / CLI | ⚙️ GitHub Action | 🔌 MCP server | 🐳 Docker |
|---|---|---|---|
|
Local dev, scripting, ad-hoc questions from a terminal. |
A fresh graph committed next to your code on every push, zero Python setup. |
Give Claude, Cursor or any MCP client live, cited access to the codebase. |
Enterprise-ready, read-only, non-root container deployment. |
Requires Python 3.10+. Run via uv, no install step:
uvx repo2graph build . -o .r2g && open .r2g/human/graph.htmlOr install it properly:
pip install repo2graph
repo2graph build /path/to/project -o .r2g --git-history 200
repo2graph query "how does routing match a path" -o .r2g
One pass over this repository — 195 files, 2,552 nodes, 11,118 edges — takes about three seconds and needs no configuration file, no language server and no API key. Ask it something, and the answer comes back as source you can check, not a summary you have to trust:
Full flag tables, budget accounting and the Python API: docs/cli.md · docs/python-api.md.
Published on the GitHub Marketplace — one step, no Python setup on the runner:
- uses: actions/checkout@v4
with: { fetch-depth: 0 } # full history, so CO_CHANGE edges are meaningful
- uses: Srinivasan-78/repo2graph@v1
with:
path: . # or: repo: some-org/other-repo
git-history: "500" # commits scanned for CO_CHANGE edges (0 = skip)
artifact-name: repo-graph@v1 follows every 1.x release; pin an exact tag (@v1.6.0) to upgrade by hand instead. It never
calls an LLM — --answer is deliberately not exposed — and it writes a job-summary table (hub
files, CO_CHANGE hotspots, the graph delta since the last build) straight from the artifacts, so
the shape of the map shows up in the run without downloading anything.
Also pack a cited context for a fixed question, and push the map to a browsable branch:
- uses: Srinivasan-78/repo2graph@v1
with:
query: "how does auth middleware validate a token"
commit-branch: graph # force-pushed; this repo's own /graph branch is built this wayAll inputs/outputs, private-repo tokens and the vector-embedding step: docs/github-action.md.
repo2graph-mcp is a stdio MCP server. It builds its own index on the first call if one doesn't
exist yet — nothing to run ahead of time.
Claude Code
claude mcp add repo2graph -- uvx --from "repo2graph[mcp]" repo2graph-mcp /path/to/projectClaude Desktop (claude_desktop_config.json) and Cursor (.cursor/mcp.json) — same block:
{
"mcpServers": {
"repo2graph": {
"command": "uvx",
"args": ["--from", "repo2graph[mcp]", "repo2graph-mcp", "/path/to/project"]
}
}
}Any other stdio-based MCP client (Windsurf, Zed, generic clients) takes the same command/args
pair — see docs/mcp.md for config file locations per platform and client.
That is the hop grep cannot do: one symbol in, and its definer, its callers and its callees come back with file and line — the relationship, not a text match that happens to contain the name.
For enterprise and shared deployments, an official Dockerfile is provided. It's a multi-stage build running as a non-root user (10000:10000), fully compatible with a read-only root filesystem and dropped capabilities.
docker build -t repo2graph .
docker run --rm \
--read-only \
--cap-drop=ALL \
--security-opt=no-new-privileges \
--network=none \
-v /path/to/repo:/repo:ro \
-v repo2graph-index:/repo/.r2g \
repo2graph build /repo -o /repo/.r2gSee docs/ENTERPRISE_DEPLOYMENT.md for full container hardening and HTTP server instructions.
Several tools build a graph out of a codebase. The thing that separates them is what comes back when you ask a question — a picture, a subgraph, or the code itself.
| repo2graph | Graphify | Code Graph (Obsidian) | grep / embedding RAG | |
|---|---|---|---|---|
| What a query returns | the source, packed — every block headed [cite: path:start-end] | a scoped subgraph, a path, or a concept explanation to traverse | a force-directed picture to read | matching lines, or nearest-neighbour chunks |
| How hits are ranked | BM25 seeds, then k-hop graph expansion; optional dense fusion | graph traversal (explicitly not a vector index) | n/a — it is a view | lexical only, or vectors only |
| Token budget | hard cap on the whole pack, re-measured before returning (12k ceiling over MCP) | not a packing layer | n/a | usually unbounded |
| Edges from git history | CO_CHANGE, from --git-history | — | — | — |
| Runs with no assistant, no model, no account | yes — CLI, MCP, or the GitHub Action | code pass is local; the docs/media pass uses a model | needs Obsidian desktop 1.7.2+ | varies |
| Corpus | code in 16 parsed grammars, every other file as text | code in ~40 languages, plus docs, PDFs, images, video | TS/TSX/JS/Python parsed, imports-only for 8 more | anything |
Reach for Graphify when the graph itself is the product: community detection, shortest path between two concepts, and your PDFs and design docs in the same graph as the code. Reach for the Obsidian plugin when a human wants to read the graph beside their notes. Reach for repo2graph when an agent needs cited source inside a fixed token budget, when it has to run in CI with no model and no account, or when "which files keep changing together" is part of the answer.
Longer version, with the trade-offs each choice implies: docs/comparison.md.
Five tools. Three answer questions about the code; two report on the server itself.
| Tool | Arguments | What comes back |
|---|---|---|
repo_map | none | Languages, hub files, and top entry points. Stable across calls — read this first. |
repo_search | query, optional k (default 8, max 50), hops (default 1, max 4), budget_tokens (default 6000, max 12000) | Seed chunks plus graph neighbours, each block headed [cite: path:start-end]. |
repo_neighbours | node_id, optional hops (default 1, max 4), limit (default 20, max 50) | One graph hop from a symbol/file/dir id: callers, callees, base classes, defining file. |
repo_cache_stats | none | Result-cache counters: hits, misses, size, max_size, ttl_s, evictions, hit_rate. Never itself cached. |
repo_build_status | task_id | Progress of a background --async-build: building, ready, failed or unknown, with progress_pct and eta_s. |
The three content tools exclude secrets unconditionally — no flag turns that off — and every numeric argument is clamped in the handler, so a caller cannot widen a bound by asking. Full contract, argument ceilings and client configs: docs/mcp.md. Running it shared, over HTTP, with bearer or OIDC auth and an audit log: docs/ENTERPRISE_DEPLOYMENT.md.
repo, dir, file, symbol (function/method/class/struct/trait/interface/type),
module (external dependency), external (an unresolved call target).CONTAINS, DEFINES, IMPORTS, CALLS (carries count + confidence),
CALLS_EXTERNAL, INHERITS, CO_CHANGE (from --git-history, requires 3+ co-edits).confidence = 1/n; filter to confidence == 1.0 when you need certainty over recall.Index.retrieve()'s budget_chars bounds only the chunks'
own text (a back-compat surface); Index.pack_context()'s budget_chars bounds the entire
rendered markdown — citation headers, separators, everything. New retrieval code should be built
on pack_context().Full breakdown of every node/edge kind and the chunk schema: docs/reference.md. The pipeline, the Python API, and where the graph guesses (and why): TECHNICAL.md.
Not a toy demo — five real, large, public repositories, each indexed at a pinned commit, with the
generated graph committed and the exact reproduction command recorded. Every number is measured,
from benchmarks/results.json, not estimated.
| Repository | Language(s) | Scope | Nodes | Edges |
|---|---|---|---|---|
| Kubernetes | Go | scoped (controllers, scheduler, API server) | 14,451 | 110,246 |
| TensorFlow | C++ / Python | scoped (Python/C++ boundary) | 21,380 | 115,984 |
| Django | Python | full repository | 55,810 | 303,339 |
| VS Code | TypeScript | scoped (src/vs/) | 113,080 | 656,158 |
| Linux kernel | C | scoped (extreme-scale) | 136,219 | 256,413 |
See examples/README.md for the full index and reproduction commands, docs/benchmarks.md for methodology, and docs/limitations.md for what running against five real repositories actually surfaced (parse-error rates on macro-heavy C/C++, call-name ambiguity, cross-language resolution limits).
| Command | Does |
|---|---|
repo2graph build <path> -o .r2g [--git-history N] | Parse a local repo into a graph + chunks. |
repo2graph github <owner/repo> -o <dir> | Fetch, build, and clean up — no local clone needed. |
repo2graph query "<question>" -o .r2g | Lexical search + one-hop graph expansion. |
repo2graph rag "<question>" -o .r2g [--vectors] [--answer] | Budget-bounded GraphRAG pack; --answer sends it to an LLM (opt-in, network). |
repo2graph embed -o .r2g [--verify-rag] | Compute/verify dense vectors for hybrid search. |
repo2graph map -o .r2g [--viz-nodes N] | Regenerate graph.html with a different node cap. |
repo2graph stats -o .r2g [--format text] | Node/edge/function counts for an existing index; --format text for a quality summary. |
repo2graph doctor [path] | Diagnose environment, dependencies, permissions, and index integrity. |
repo2graph explain-path <path> [-r <repo>] | Say whether a path would be indexed, and which precedence rule decided. |
| `repo2graph explain <edge | node |
repo2graph completion [shell] | Print shell tab completion setup script (bash, zsh, fish). |
repo2graph-mcp <path> [--no-auto-build] [--async-build] | stdio MCP server over .r2g. |
Environment variables (only read by rag --answer, in this precedence order):
GEMINI_API_KEY → OPENAI_API_KEY → ANTHROPIC_API_KEY → OLLAMA_HOST. --model overrides the
provider's best-effort default. No other command makes a network call or reads these. Full flag
tables and budget accounting: docs/cli.md.
build, github, auto-building query/rag, GitHub Action, and MCP exclude credential files (.env*, private keys, certificates, tokens, .ssh, .aws, .gnupg) automatically. Use --include-secrets only if you explicitly choose to index them.--secret-policy redact-match|exclude-file|warn-only|off).build, query, rag, and the MCP server make no network calls. rag --answer is the one opt-in exception — it sends the assembled pack to an LLM provider and prints the provider + hostname before doing so. Details: .github/SECURITY.md.git clone https://github.com/Srinivasan-78/repo2graph
cd repo2graph
python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
make lint test # or: ruff check . && pytestrepo2graph/.MIT. See LICENSE.
Found repo2graph useful? Star the repo — it's the easiest way to help other people find it.
Pick your client and paste the snippet. Each one is the same server, written the way that client expects it.
claude mcp add repo2graph -- uvx --from repo2graph[mcp] repo2graph-mcp /path/to/project{
"mcpServers": {
"repo2graph": {
"args": [
"--from",
"repo2graph[mcp]",
"repo2graph-mcp",
"/path/to/project"
],
"command": "uvx"
}
}
}code --add-mcp '{"name":"repo2graph","args":["--from","repo2graph[mcp]","repo2graph-mcp","/path/to/project"],"command":"uvx"}'[mcp_servers.repo2graph]
command = "uvx"
args = ["--from", "repo2graph[mcp]", "repo2graph-mcp", "/path/to/project"]Runs locally on your device. Your client starts the server itself, so nothing has to be hosted.
Paste this prompt into your agent. It reads this page and does the setup for you.
Read https://aiagentslisting.com/mcp/repo2graph to learn what the "repo2graph" MCP server does and how to install it. Add it to my coding agent's MCP configuration as documented on that page, then confirm the server connects and list the tools it exposes.Agents can also browse this directory over MCP at https://aiagentslisting.com/api/mcp
uvx repo2graph build . -o .r2g && open .r2g/human/graph.htmlclaude mcp add repo2graph -- uvx --from "repo2graph[mcp]" repo2graph-mcp /path/to/projectdocker run --rmThis server runs locally, so we can't read its tool list over the web yet.
We could not run this server: it ships no npx package for our sandbox and no public endpoint. The four checks that need a live server are left out, and the grade tops out at B until one exists.
Paste this line near the top of your repository's README. The badge always renders the current score.
[](https://aiagentslisting.com/mcp/repo2graph)Nothing comparable is listed yet.
v2.0.0Release notesv1.6.0Release notesv1.5.4Release notesv1.5.3Release notesv1.5.2Release notesv1.5.1Release notesv1.5.0Release notesv1.4.0Release notesv1.2.0Release notesConnect to the AI Agents Listing MCP server at https://aiagentslisting.com/api/mcp using the HTTP transport and complete the sign-in when it asks. Then call the submit_review tool for the listing "repo2graph" with a rating from 1 to 5 and a short note on what worked and what did not.One email a week. New agents, MCP servers and skills, and what is actually getting traction.