# repo2graph

Maps codebase relationships with Tree-sitter and returns cited code excerpts within a strict token limit. Useful for coding agents tracing cross-file calls without external API keys.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 9
- Author: Srinivasan-78
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/Srinivasan-78/repo2graph
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/mcp/repo2graph

## What it does

repo2graph indexes source code with a single Tree-sitter pass to record import links, function invocations, and files committed together in Git history. It kicks off retrieval with BM25 keyword matching, traverses the discovered dependency edges, and returns excerpts capped by a preset token budget. Every code snippet includes precise location metadata in a `[cite: path:start-end]` header.

The server runs entirely offline by default, requiring no database, language server, or external API access. Precompiled grammar files are shipped directly inside the `tree-sitter-language-pack` distribution. Outbound network traffic happens only if you explicitly clone a GitHub repository, pass `--answer` to contact an LLM, or opt into embedding models through `repo2graph[rag]` or `repo2graph[rag-static]`.

The tool beats basic grep on multi-file structural investigations, but ripgrep performs better on simple lexical lookups inside a single file.

## Requirements
- Needs: Python and uv (commands run via uvx)

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add repo2graph -- uvx repo2graph
```
uvx runs the command named after the package; if the README names another one, use uvx --from repo2graph <command>

### Codex

**Platform CLI**
```bash
codex mcp add repo2graph -- uvx repo2graph
```
uvx runs the command named after the package; if the README names another one, use uvx --from repo2graph <command>

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "repo2graph": {
            "command": "uvx",
            "args": [
                "repo2graph"
            ]
        }
    }
}
```
uvx runs the command named after the package; if the README names another one, use uvx --from repo2graph <command>

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "repo2graph": {
            "type": "stdio",
            "command": "uvx",
            "args": [
                "repo2graph"
            ]
        }
    }
}
```
uvx runs the command named after the package; if the README names another one, use uvx --from repo2graph <command>

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add repo2graph uvx repo2graph
```
uvx runs the command named after the package; if the README names another one, use uvx --from repo2graph <command>

## When to use it
- trace cross-file function calls and inheritance hierarchies
- retrieve code snippets bounded by a strict token limit
- get cited code references with exact line numbers
- inspect repository architecture without sending source code to third-party services

## Example prompts
- Trace how HTTP requests are routed and list the functions handling them.
- Locate the base database model and show all modules importing it.
- Explain the error handling flow based on the call graph.

## Similar
- [skeletongraph](https://affpapa.org/en/nevibecode/mcp/skeletongraph.md) — MCP server · ★ 7
- [jCodemunch MCP](https://affpapa.org/en/nevibecode/mcp/jcodemunch-mcp.md) — MCP server · ★ 2809
- [Octocode](https://affpapa.org/en/nevibecode/mcp/octocode.md) — MCP server · ★ 518
- [smart-explore](https://affpapa.org/en/nevibecode/skills/smart-explore.md) — skill · 7300 installs
- [grepai-languages](https://affpapa.org/en/nevibecode/skills/grepai-languages.md) — skill · 704 installs
- [codeseeker](https://affpapa.org/en/nevibecode/mcp/codeseeker.md) — MCP server · ★ 20

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
