Parses a multi-language codebase into a knowledge graph so an AI client can query, retrieve, and edit code in plain English.
Also known as vitali87/code-graph-rag
- Stars
- 5,354
- Tools
- —
- Downloads, 30 days
- 2,154
- Latest version
- 0.6.30
- Last commit
- Nov 14, 2026
- License
- MIT
What is Code-Graph-RAG MCP?
Code-Graph-RAG parses a multi-language codebase into a knowledge graph so an AI client can query, retrieve, and edit code in plain English.
Summary generated from the project's README
About Code-Graph-RAG MCP server
Developers can transform complex, multi-language repositories into searchable knowledge graphs to facilitate natural language interaction with their code. By using Tree-sitter and compiler-grade frontends like libclang or go/types, this tool extracts functions, classes, and modules into a unified graph schema. It works locally using an embedded SQLite database, though users can opt into Memgraph or Neo4j backends for more advanced needs.
Once indexed via the cgr command, an AI client can use the server to query the codebase, retrieve specific source code by intent, and perform surgical edits using AST-based patching. The system supports a wide range of languages including Python, TypeScript, Rust, Go, and C++. It also allows for dynamic tracing to merge runtime behavior into the static graph, providing a complete view of how code actually executes.
What you can do with it
- 1Querying codebase structureAsk an AI client to explain how different modules and functions relate to each other within a large repository.
- 2Performing surgical code editsInstruct an agent to modify specific functions or classes using precise AST-based changes and diff previews.
- 3Identifying dead codeFind unused functions or modules by analyzing the call and reference edges starting from known entry points.
- 4Merging runtime tracesOverlay actual execution data from tests or eBPF profiles onto the static knowledge graph.
Written from the project's README. Every use case is checked against a quote from it.
How to install Code-Graph-RAG MCP
Formats verified 10 Nov 2026Add to CursorAdd to GooseInstall Code-Graph-RAG MCP in Claude Code
$ claude mcp add --env 'CYPHER_API_KEY=<YOUR_CYPHER_API_KEY>' --env 'ORCHESTRATOR_API_KEY=<YOUR_ORCHESTRATOR_API_KEY>' code-graph-rag -- uvx code-graph-ragInstall Code-Graph-RAG MCP in Cursor
~/.cursor/mcp.json
{
"mcpServers": {
"code-graph-rag": {
"command": "uvx",
"args": [
"code-graph-rag"
],
"env": {
"CYPHER_API_KEY": "<YOUR_CYPHER_API_KEY>",
"ORCHESTRATOR_API_KEY": "<YOUR_ORCHESTRATOR_API_KEY>"
}
}
}
}Install Code-Graph-RAG MCP in VS Code
.vscode/mcp.json
{
"servers": {
"code-graph-rag": {
"type": "stdio",
"command": "uvx",
"args": [
"code-graph-rag"
],
"env": {
"CYPHER_API_KEY": "<YOUR_CYPHER_API_KEY>",
"ORCHESTRATOR_API_KEY": "<YOUR_ORCHESTRATOR_API_KEY>"
}
}
}
}Install Code-Graph-RAG MCP in VS Code CLI
$ code --add-mcp '{"name":"code-graph-rag","type":"stdio","command":"uvx","args":["code-graph-rag"],"env":{"CYPHER_API_KEY":"<YOUR_CYPHER_API_KEY>","ORCHESTRATOR_API_KEY":"<YOUR_ORCHESTRATOR_API_KEY>"}}'Install Code-Graph-RAG MCP in Claude Desktop
claude_desktop_config.json
{
"mcpServers": {
"code-graph-rag": {
"command": "uvx",
"args": [
"code-graph-rag"
],
"env": {
"CYPHER_API_KEY": "<YOUR_CYPHER_API_KEY>",
"ORCHESTRATOR_API_KEY": "<YOUR_ORCHESTRATOR_API_KEY>"
}
}
}
}Install Code-Graph-RAG MCP in Codex
$ codex mcp add code-graph-rag --env 'CYPHER_API_KEY=<YOUR_CYPHER_API_KEY>' --env 'ORCHESTRATOR_API_KEY=<YOUR_ORCHESTRATOR_API_KEY>' -- uvx code-graph-ragInstall Code-Graph-RAG MCP in Codex config.toml
~/.codex/config.toml
[mcp_servers.code-graph-rag] command = "uvx" args = ["code-graph-rag"] [mcp_servers.code-graph-rag.env] CYPHER_API_KEY = "<YOUR_CYPHER_API_KEY>" ORCHESTRATOR_API_KEY = "<YOUR_ORCHESTRATOR_API_KEY>"
Install Code-Graph-RAG MCP in Gemini CLI
$ gemini mcp add -s user -e 'CYPHER_API_KEY=<YOUR_CYPHER_API_KEY>' -e 'ORCHESTRATOR_API_KEY=<YOUR_ORCHESTRATOR_API_KEY>' code-graph-rag uvx -- code-graph-ragInstall Code-Graph-RAG MCP in Gemini settings.json
~/.gemini/settings.json
{
"mcpServers": {
"code-graph-rag": {
"command": "uvx",
"args": [
"code-graph-rag"
],
"env": {
"CYPHER_API_KEY": "<YOUR_CYPHER_API_KEY>",
"ORCHESTRATOR_API_KEY": "<YOUR_ORCHESTRATOR_API_KEY>"
}
}
}
}Configuration
CYPHER_API_KEYSecretAPI key for the Cypher LLM provider (not needed for the default local ollama provider)
ORCHESTRATOR_API_KEYSecretAPI key for the orchestrator LLM provider (not needed for the default local ollama provider)
CYPHER_MODELModel name for Cypher query generation
CYPHER_PROVIDERLLM provider for Cypher query generation (openai, anthropic, google, azure, cohere, ollama)
MEMGRAPH_HOSTHostname of the Memgraph database
MEMGRAPH_PORTPort of the Memgraph database
ORCHESTRATOR_MODELModel name for the orchestrator agent
ORCHESTRATOR_PROVIDERLLM provider for the orchestrator agent (openai, anthropic, google, azure, cohere, ollama)
TARGET_REPO_PATHPath to the repository to analyze (auto-detected from working directory if not set)
| Name | Description | |
|---|---|---|
| CYPHER_API_KEY | API key for the Cypher LLM provider (not needed for the default local ollama provider) | Secret |
| ORCHESTRATOR_API_KEY | API key for the orchestrator LLM provider (not needed for the default local ollama provider) | Secret |
| CYPHER_MODEL | Model name for Cypher query generation | |
| CYPHER_PROVIDER | LLM provider for Cypher query generation (openai, anthropic, google, azure, cohere, ollama) | |
| MEMGRAPH_HOST | Hostname of the Memgraph database | |
| MEMGRAPH_PORT | Port of the Memgraph database | |
| ORCHESTRATOR_MODEL | Model name for the orchestrator agent | |
| ORCHESTRATOR_PROVIDER | LLM provider for the orchestrator agent (openai, anthropic, google, azure, cohere, ollama) | |
| TARGET_REPO_PATH | Path to the repository to analyze (auto-detected from working directory if not set) |
Automated checks
Ran Nov 13, 2026Full report →Passed our automated checks. That is not a security audit: read the code and give the server the narrowest access it needs. How checks work
- Source repository linked and reachablePass
- Open source license (OSI)Pass
- Commit or release in the last yearPass
- Package name not close to a popular packagePass
- Remote endpoint uses HTTPSNot checked
- Destructive tools are labelledNot checked
- No hidden instructions to the modelPass
- No critical advisory in the package or its dependenciesPass
README
View on GitHubCode-Graph-RAG
Code-Graph-RAG parses a multi-language codebase with Tree-sitter, sharpened by compiler-grade frontends and runtime traces where available, builds a knowledge graph of its structure in an embedded graph database that needs no server, and lets you query, edit, and optimise that code in plain English. It works across a monorepo of mixed languages under one unified graph schema.
Latest News 🔥
- Type Handling: Improved handling of type context managers, walrus operators, and match binding targets in both Python and TypeScript.
- Rename Refinement: Prevented Go renames from unexporting names used by other packages.
- Profile Naming: Corrected the naming of pprof profiles to avoid "malformed" errors when no samples are present.
- Output Budget: Increased the Anthropic output budget to improve the default thinking experience.
- Module Resolution: Resolved issues with module resolution in various scenarios, including ES module default imports and bare name bindings.
- Dead Code Elimination: Removed dead code roots associated with IPython rich-display methods.
- Incremental Refresh: Improved incremental refresh to ensure callers are updated when dispatch targets change.
See NEWS.md for the full history.
What It Does
Point Code-Graph-RAG at a repository and it reads every source file, extracts functions, classes, methods, modules, and the relationships between them, and stores the result as an interconnected graph. Once the graph exists you can:
- Ask questions about the codebase in natural language and get answers grounded in the real structure.
- Retrieve the actual source of any function, class, or method by name or by intent.
- Edit code through the agent with AST-based surgical patching and a diff preview before anything changes.
- Optimise code against language best practices or your own coding standards.
- Find dead code by walking call and reference edges from entry points.
- Search and rewrite structurally by AST pattern with ast-grep.
- Overlay runtime behaviour: trace a test run (or pull production eBPF profiles) with
cgr traceand merge the calls that actually happened into the graph, exposing dispatch that static analysis cannot see.
How It Works
The system has two components:
- Multi-language parser. A Tree-sitter based parser reads the codebase and ingests functions, classes, methods, modules, and their relationships into the graph under a single language-agnostic schema. Where a toolchain is available, compiler-grade frontends layer exact facts on top (libclang for C/C++,
go/typesfor Go, and opt-in Roslyn,javacand Jedi for C#, Java and Python), and dynamic tracing merges calls observed at runtime. Tree-sitter stays the backbone: a trace only sees code that ran, and a compiler frontend only covers what its toolchain can build. - RAG system (
codebase_rag/). An interactive CLI that turns natural language into Cypher queries, retrieves matching code, and drives AI-powered editing and optimisation.
Source Code -> Tree-sitter Parser -> AST Analysis -> Knowledge Graph
|
User Query -> AI Model (Cypher Gen) -> Cypher Query -> Graph Results -> Response
The graph is stored in an embedded SQLite file by default. Memgraph and Neo4j are opt-in backends that run the same Cypher; Graph Backends compares them.
See the Architecture Overview and Graph Schema for the full picture.
Supported Languages
Python, TypeScript, TSX, JavaScript, Rust, Go, Java, C, C++, C#, PHP, Lua, Dart, and Julia are fully supported. Scala is in development, and Ruby, Kotlin, Swift, Elixir, Haskell, Solidity, Bash, and Nix have structural support (modules, functions, classes where the language has them, and imports) through the pluggable ast-grep tier. See the Language Support matrix for per-language capabilities.
Installation
cgr is published to PyPI. Install it system-wide with the treesitter-full (tree-sitter grammars), ast-grep (Ruby, Kotlin, Swift, Elixir, Haskell, Solidity, Bash, Nix) and semantic (vector search) extras:
# with uv (recommended)
uv tool install "code-graph-rag[treesitter-full,ast-grep,semantic]"
# or with pipx
pipx install "code-graph-rag[treesitter-full,ast-grep,semantic]"
Which version am I getting?
Three version lines exist and they intentionally differ:
| where | what it tracks |
|---|---|
| git tags | every version, one per merge |
| GitHub Releases (binaries, signatures) | every 50th version, plus any security fix, breaking change or merge labelled release now |
| PyPI | every 50th version, plus any security fix, breaking change or merge labelled release now |
So the newest tag on main usually runs ahead of the newest release, often by
tens of patch versions; they coincide only just after a release. Nothing is
stuck, the cadences differ by design. A security fix, a breaking change or a
merge a maintainer labels release now does NOT wait for the cadence: each ships
a release and a PyPI upload immediately.
uv tool install and pipx install give you the newest PyPI version, which is the
newest RELEASE, not the newest tag. Interim tags exist so every merge is
addressable; binaries and PyPI uploads follow the cadence above.
To run code newer than the latest release, install from git:
uv tool install "code-graph-rag[treesitter-full,ast-grep,semantic] @ git+https://github.com/vitali87/code-graph-rag@main"
To upgrade an existing install, run uv tool upgrade code-graph-rag (with pipx, pipx upgrade code-graph-rag, or pipx reinstall code-graph-rag for a git install). Upgrade covers the other install methods.
You also need Python 3.12+ and ripgrep. The graph lives in an embedded SQLite file by default, so there is no database server to run: no Docker and no cmake. Memgraph and Neo4j remain available as opt-in backends (Graph Backends). Full prerequisites, source installs, and environment setup are in the Installation guide.
[!NOTE] cgr requires its native extension,
cgr-graph-rs, which ships for CPython 3.12 or newer on Linux (x86_64, aarch64), macOS and Windows x64, so it installs on those platforms only. Older system interpreters (Debian Bookworm ships 3.11) need the interpreter pinned explicitly; see Installation for the commands.
Quick Start
# Parse a repository into the graph, then query it
cgr start --repo-path /path/to/repo --update-graph
cgr start --repo-path /path/to/repo
The graph is written to ~/.cgr/graph.sqlite (set SQLITE_GRAPH_PATH to move it).
To use Memgraph instead, install the driver with the memgraph extra, set
GRAPH_BACKEND=memgraph, and start the packaged Memgraph + Qdrant stack with
cgr daemon up.
Repeat the first command for each repository you want indexed; the graph is
shared, and syncing one project leaves the others alone. To start over from an
empty graph, add --clean — it deletes every project in the shared graph,
not just this one, and asks for confirmation first when other
projects would be destroyed.
A default index leaves out the opt-in capture groups; add them with --capture or CGR_CAPTURE.
The Quick Start guide walks through parsing, querying, and exporting in five minutes.
MCP Server
Code-Graph-RAG runs as an MCP server so Claude Code and other MCP clients can query and edit your codebase directly. See the MCP Server guide for setup.
Documentation
Getting Started
User Guide
- CLI Reference
- Interactive Querying
- Code Optimisation
- Dead Code Detection
- Dynamic Call Tracing
- Graph Export
- Real-Time Updates
- C/C++ Semantic Mode
- MCP Server
- Porting Between Languages
Architecture
Python SDK
Advanced
Enterprise Services
Code-Graph-RAG is open source and free to use. For organisations that need more, we offer fully managed cloud-hosted solutions and on-premise deployments:
- Cloud-Hosted Deployment: Managed cloud infrastructure for both the graph database and the AI agent connection. Zero infrastructure overhead, so we handle scaling, updates, and availability while your team focuses on building.
- On-Premise & Air-Gapped Deployment: Deploy Code-Graph-RAG entirely within your own environment, including air-gapped networks. Full data sovereignty for regulated industries and security-sensitive organisations.
We also offer custom development, integration consulting, technical support contracts, and team training.
View plans & pricing at code-graph-rag.com
Contributing
Please see CONTRIBUTING.md for contribution guidelines. Good first PRs come from the TODO issues.
Support
For issues or questions, check the Troubleshooting guide first, then open an issue.
If cgr is useful to you, please consider pledging support on GitHub Sponsors. cgr links the page under cgr --version and, in a terminal, after most commands finish; set CGR_SPONSOR_PLEDGE=false to hide that line.
Accessibility
ACCESSIBILITY.md describes what cgr and its documentation support for people using assistive technology or alternative settings, the known limitations and their workarounds, and how to report a barrier.
License
MIT. See LICENSE.
Third-party components and their licences are credited on the Credits page.
Code-Graph-RAG MCP questions
How do I add Code-Graph-RAG MCP to Claude Code?
Run claude mcp add --env 'CYPHER_API_KEY=<YOUR_CYPHER_API_KEY>' --env 'ORCHESTRATOR_API_KEY=<YOUR_ORCHESTRATOR_API_KEY>' code-graph-rag -- uvx code-graph-rag in your terminal. Add --scope user to make it available in every project.
How do I add Code-Graph-RAG MCP to Cursor?
Open ~/.cursor/mcp.json and add the server under mcpServers, using the Cursor config shown in the install section above.
What does code-graph-rag do with a repository?
It parses every source file, extracts functions, classes, methods, modules and their relationships, and stores them as an interconnected graph you can query.
Which programming languages are supported?
Python, TypeScript, TSX, JavaScript, Rust, Go, Java, C, C++, C#, PHP, Lua, Dart and Julia are fully supported, with structural support for several more languages.
Where is the code graph stored?
By default the graph is stored in an embedded SQLite file, with Memgraph and Neo4j available as opt-in backends.
Can it find dead code?
Yes, it finds dead code by walking call and reference edges from entry points.