How to Integrate Code‑Graph‑RAG with Existing Projects: A Complete Guide
Integrate Code‑Graph‑RAG via its CLI (cgr), Python SDK (cgr package), or MCP server to add graph‑backed code intelligence to any project without modifying your existing codebase.
Code‑Graph‑RAG is a two‑part system that brings RAG‑powered code understanding to multilingual repositories. The Tree‑sitter‑based parser extracts structure and writes it to Memgraph, while the RAG‑enabled CLI/SDK translates natural language into Cypher queries, retrieves code, and performs AI‑driven edits. This guide shows you exactly how to wire each integration point into your existing workflow.
Installation and Prerequisites
Start with a full installation that includes all language parsers and semantic search capabilities:
pip install "code-graph-rag[treesitter-full,semantic]"
Or use uv for faster tooling:
uv tool install "code-graph-rag[treesitter-full,semantic]"
This installs the cgr console script and all Python SDK modules. The package names follow the pattern documented in the installation instructions.
Core Integration Points
1. CLI Entry Point (cgr)
The cgr command is your fastest path to production. It requires zero code changes in your existing project.
Key commands:
cgr daemon up— launches Dockerized Memgraph + Qdrant stack (nodocker-compose.ymlneeded)cgr start --repo-path /path/to/project --update-graph— parses and ingests a repositorycgr query "natural language question"— queries the graph directly
The daemon start logic lives in [main.py](https://github.com/vitali87/code-graph-rag/blob/main/main.py). Full CLI reference: CLI reference docs.
2. Python SDK (cgr Package)
For programmatic integration, import from the cgr namespace. All public functionality is exposed here.
Ingest and Query Programmatically
from cgr import MemgraphIngestor, CypherGenerator
# Connect to the running graph
ingestor = MemgraphIngestor()
# Generate Cypher from natural language
cypher = CypherGenerator().from_natural("Find all functions that call `my_helper`")
results = ingestor.run_cypher(cypher)
print(results)
Source locations:
MemgraphIngestor— [codebase_rag/workspaces/storage.py](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/workspaces/storage.py)CypherGenerator— [codebase_rag/workspaces/models.py](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/workspaces/models.py)
Semantic Code Search
Add vector search to your existing retrieval pipeline:
from cgr import embed_code
vectors = embed_code(["def foo(): pass", "def bar(): pass"])
Semantic search utilities are documented in [docs/sdk/semantic-search.md](https://github.com/vitali87/code-graph-rag/blob/main/docs/sdk/semantic-search.md).
AI‑Driven Code Editing
Modify code structure through the graph:
from cgr import CypherGenerator, MemgraphIngestor
edit_cypher = CypherGenerator().edit_node("Function", "my_func", {"name": "new_name"})
MemgraphIngestor().run_cypher(edit_cypher)
The editing pipeline reuses the same CypherGenerator implementation from [codebase_rag/workspaces/models.py](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/workspaces/models.py).
Full SDK overview: SDK documentation.
3. MCP Server for External Tools
Code‑Graph‑RAG exposes a Model Context Protocol (MCP) server so tools like Claude Code can query or edit the graph without native Python integration.
Start the MCP server:
cgr daemon up
This launches both the Memgraph/Qdrant stack and the MCP server on http://localhost:8080.
Point your MCP client to that endpoint. The protocol handling uses pydantic-ai as documented in the architecture overview.
MCP server details: MCP server guide.
End‑to‑End Integration Workflow
| Step | Action | Implementation Source |
|---|---|---|
| 1. Install | pip install "code-graph-rag[treesitter-full,semantic]" |
README installation |
| 2. Start infrastructure | cgr daemon up |
[main.py](https://github.com/vitali87/code-graph-rag/blob/main/main.py) |
| 3. Ingest codebase | cgr start --repo-path /path/to/project --update-graph |
CLI + [codebase_rag/workspaces/models.py](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/workspaces/models.py) |
| 4. Programmatic queries | Use MemgraphIngestor + CypherGenerator |
[storage.py](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/workspaces/storage.py), [models.py](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/workspaces/models.py) |
| 5. Semantic search | Call embed_code() |
semantic‑search.md |
| 6. MCP integration | Connect client to http://localhost:8080 |
mcp‑server.md |
Because CLI, SDK, and MCP server share the same underlying graph, you can mix these approaches arbitrarily — launch the daemon in CI, ingest via CLI, then query from a downstream microservice using the Python SDK without restarting the database.
Key Source Files Reference
| File | Purpose |
|---|---|
[main.py](https://github.com/vitali87/code-graph-rag/blob/main/main.py) |
CLI entry point, daemon startup, MCP server |
[codebase_rag/workspaces/storage.py](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/workspaces/storage.py) |
MemgraphIngestor — Cypher execution wrapper around pymgclient |
[codebase_rag/workspaces/models.py](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/workspaces/models.py) |
Data models and CypherGenerator |
[docs/sdk/overview.md](https://github.com/vitali87/code-graph-rag/blob/main/docs/sdk/overview.md) |
Python SDK usage patterns |
[docs/guide/mcp-server.md](https://github.com/vitali87/code-graph-rag/blob/main/docs/guide/mcp-server.md) |
MCP server configuration |
[docs/guide/cli-reference.md](https://github.com/vitali87/code-graph-rag/blob/main/docs/guide/cli-reference.md) |
Complete CLI command reference |
Summary
- Install once with
pip install "code-graph-rag[treesitter-full,semantic]"to get CLI, SDK, and MCP server - No code changes required — use
cgrcommands to ingest and query any repository - Three integration depths: CLI for scripts/CI, Python SDK for embedded code intelligence, MCP server for external tool compatibility
- Shared graph backend — mix CLI ingestion with SDK queries and MCP edits without data migration
- Key classes:
MemgraphIngestorfor storage,CypherGeneratorfor natural‑language‑to‑Cypher translation
Frequently Asked Questions
Does Code‑Graph‑RAG require modifying my existing project files?
No. Code‑Graph‑RAG operates entirely through ingestion of your repository into Memgraph. The parser reads your code via Tree‑sitter without injecting changes, and all edits happen through the graph layer if you explicitly invoke them.
Can I use Code‑Graph‑RAG in a CI/CD pipeline?
Yes. Run cgr daemon up to start infrastructure, then cgr start --repo-path . --update-graph to ingest the current checkout. The CLI returns structured exit codes suitable for pipeline automation, and the running daemon stays available for downstream SDK queries.
What programming languages does the parser support?
The Tree‑sitter‑based parser handles multiple languages through optional dependency groups. Install [treesitter-full] for complete language coverage or select specific parsers to minimize dependency weight. The parsing pipeline in [codebase_rag/workspaces/models.py](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/workspaces/models.py) normalizes all languages into a unified graph schema.
How do I connect Claude Code or other AI assistants to my code graph?
Start the MCP server with cgr daemon up and configure your client to connect to http://localhost:8080. The server implements the Model Context Protocol so compatible assistants can query code structure, retrieve definitions, and request edits through natural language.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →