# repo2graph [Health: Active]

**Category:** 💻 Developer Tools  
**Repository:** https://github.com/Srinivasan-78/repo2graph  
**GitHub Stars:** 9  
**Views:** 1  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/repo2graph

## Description
Ask a codebase questions and get cited code back, from a tree-sitter graph of the repo.

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "repo2graph": {
    "command": "uvx",
    "args": ["repo2graph"]
  }
}
```

## Documentation

## What repo2graph does
repo2graph turns a codebase into a searchable structural map for coding agents and CI workflows. Its index records relationships such as callers, callees, imports, base classes, and files that change together in Git. Queries return source excerpts with citations in the form of a path and line range, making the retrieved evidence traceable.

The server is aimed especially at questions whose answers cross file or module boundaries. It can identify related symbols, follow dependency links, and produce a context pack constrained by a token budget. For purely lexical questions contained in one file, ordinary text search may be a better fit.

## How it works
A tree-sitter pass parses the repository and builds the graph. Retrieval begins with BM25 matches, then expands through recorded relationships to find supporting code. The returned pack is measured, capped, and measured again before delivery; the MCP limit is 12,000 tokens.

Relationships exposed by the index carry confidence information. When a name could refer to multiple definitions, the relationship is marked ambiguous and its contribution is reduced rather than selecting a definition without qualification. Reverse dependency traversal can calculate a symbol's blast radius within a hop and visit limit.

Building, querying, and serving the MCP interface are local operations. GitHub targets require cloning, and the optional vector path downloads an embedding model on first use. The standard parser package includes its grammars in the installed wheel.

## Setup and configuration
The package can be run through `uvx`. To try the bundled example, run:

```bash
uvx repo2graph demo
```

To index a local repository into `.r2g`, use:

```bash
uvx repo2graph build . -o .r2g
```

A cited, budget-limited context pack can be generated with:

```bash
uvx repo2graph rag "how does routing work" -o .r2g
```

Register the MCP interface with Claude Code using:

```bash
claude mcp add repo2graph -- uvx --from "repo2graph[mcp]" repo2graph-mcp .
```

Cursor, Claude Desktop, and other MCP clients use the same server through client-specific configuration. An optional dense-retrieval installation is available with `repo2graph[rag]`; a lighter static backend is available with `repo2graph[rag-static]`. The backend used for embedding and querying must match. After an embedding model is cached, `HF_HUB_OFFLINE=1` prevents later Hugging Face requests.

## Tools and capabilities
- Answer repository questions with cited source blocks.
- Build a repository index from a local codebase.
- Retrieve context with BM25 ranking and graph expansion.
- Inspect a symbol's callers, callees, base classes, and defining file through `repo_neighbours`.
- Traverse reverse dependencies with `repo_blast_radius`.
- Enforce a token ceiling on returned MCP context.
- Clone GitHub repositories when given a supported GitHub target.
- Use the MCP server from Claude Code, Cursor, Claude Desktop, and other compatible clients.
- Provide caller, callee, base-class, and co-change information to the preview VS Code extension.

## Limitations and notes
Graph retrieval is not a replacement for grep. Benchmarks in the project show stronger results on cross-file structural questions and weaker results on single-file lexical questions. Dense retrieval is optional and requires downloading a model; the default BM25 path avoids that dependency.

The `rag` embedding backend can install PyTorch and, on Linux, NVIDIA CUDA packages. The static backend uses a different model and produces different retrieval behavior. GitHub operations and embedding downloads are the main network-requiring paths; normal indexing, querying, and MCP serving do not make network calls.

There is no interactive desktop UI comparable to Sourcetrail. The project instead exposes repository structure through its CLI, MCP server, and the preview VS Code extension.

_Full upstream README: https://allmcps.com/mcp/repo2graph/readme_

