# How to Set Up Claude Code with Code-Graph-RAG: Complete MCP Integration Guide

> Integrate Claude Code with Code-Graph-RAG using the Model Context Protocol for natural language queries and AST-based code edits. Get the complete MCP integration guide.

- Repository: [Vitali Avagyan/code-graph-rag](https://github.com/vitali87/code-graph-rag)
- Tags: how-to-guide
- Published: 2026-09-08

---

**Code-Graph-RAG integrates with Claude Code through the Model Context Protocol (MCP), exposing a JSON-RPC endpoint that enables natural-language queries and AST-based code edits against a Memgraph-backed knowledge graph.**

The **vitali87/code-graph-rag** repository provides a bridge between AI assistants and codebase intelligence through a graph-based retrieval system. Setting up Claude Code with Code-Graph-RAG allows you to query complex code relationships and execute refactoring operations using plain English instructions rather than manual navigation.

## Understanding the MCP Architecture

The integration follows a three-tier architecture that decouples the AI client from the storage engine:

```

Claude Code (MCP client) ⇄ Code-Graph-RAG MCP server ⇄ Memgraph graph DB

```

When Claude Code sends a request, the **Model Context Protocol (MCP)** server in Code-Graph-RAG translates natural language into Cypher queries and executes them against the Memgraph database. This design is language-agnostic, meaning the same setup works for Python, TypeScript, Rust, Go, and other supported languages. The MCP layer is intentionally thin—it merely forwards JSON-RPC method calls to the underlying `cgr` commands that power the interactive REPL.

## Installing Code-Graph-RAG and Dependencies

First, install the CLI tool with full Tree-sitter support to enable parsing across multiple languages. According to the repository documentation, the recommended method uses `uv`:

```bash
uv tool install "code-graph-rag[treesitter-full,semantic]"

```

Alternatively, you can use `pipx` if you prefer:

```bash
pipx install "code-graph-rag[treesitter-full,semantic]"

```

This command installs the `cgr` executable along with semantic analysis capabilities and language parsers required for building the knowledge graph.

## Initializing the Knowledge Graph

Before connecting Claude Code, you must index your target repository into Memgraph. Start the database daemon using Docker:

```bash
cgr daemon up

```

Then parse your codebase and populate the graph:

```bash
cgr start --repo-path /path/to/my/project --update-graph

```

This step analyzes the repository structure, builds an abstract syntax tree (AST) representation, and stores the relationships in Memgraph. The `cgr start` command uses the same underlying logic that the MCP server will later access when answering queries.

## Launching the MCP Server

The MCP server implementation resides in [`cgr/__main__.py`](https://github.com/vitali87/code-graph-rag/blob/main/cgr/__main__.py) (or the entry point [`cgr/cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/cgr/cli.py)), which implements the `mcp-server` sub-command. You can start the server in two modes:

**HTTP mode** (default on port 8000):

```bash
cgr mcp-server

```

**Stdio mode** (for Claude Code's built-in client):

```bash
cgr mcp-server --stdio

```

The HTTP server exposes endpoints on `localhost:8000` by default, while stdio mode communicates directly through standard input/output streams. Both modes provide the same JSON-RPC interface for querying the knowledge graph and submitting code edits.

## Configuring Claude Code

With the server running, configure Claude Code to connect to the MCP endpoint. Detailed instructions are available in [`docs/claude-code-setup.md`](https://github.com/vitali87/code-graph-rag/blob/main/docs/claude-code-setup.md), but the process involves:

1. Opening **Settings → MCP Server** in Claude Code
2. Setting the **Endpoint** to `http://localhost:8000` (or leaving blank for stdio)
3. Optionally specifying `TARGET_REPO_PATH` to default to a particular repository

Once connected, Claude Code can send natural-language prompts to the server, which generates Cypher queries, runs them against Memgraph via [`codebase_rag/workspaces/storage.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/workspaces/storage.py), and returns structured results.

## Querying and Editing Code

After configuration, test the integration with graph-aware queries. For example:

```

"Show me all functions that call fetch_data"

```

The MCP server processes this by traversing the graph for call relationships and returns the matching function definitions. For code editing, you can request patches—the server builds an AST-based diff, applies it (optionally after confirmation), and updates the graph to reflect the changes.

## Summary

- **Code-Graph-RAG** exposes functionality via the MCP protocol using a JSON-RPC/stdio interface that Claude Code consumes as a client.
- The **installation** requires `uv tool install "code-graph-rag[treesitter-full,semantic]"` to obtain the `cgr` CLI and language parsers.
- **Infrastructure** depends on Memgraph started via `cgr daemon up`, with repositories indexed using `cgr start --repo-path --update-graph`.
- The **MCP server** supports both HTTP (`cgr mcp-server`) and stdio (`cgr mcp-server --stdio`) transport modes, implemented in the CLI entry point.
- **Configuration** in Claude Code requires pointing to `http://localhost:8000` or enabling stdio mode, as documented in [`docs/guide/mcp-server.md`](https://github.com/vitali87/code-graph-rag/blob/main/docs/guide/mcp-server.md) and [`docs/claude-code-setup.md`](https://github.com/vitali87/code-graph-rag/blob/main/docs/claude-code-setup.md).

## Frequently Asked Questions

### What is the Model Context Protocol (MCP) in Code-Graph-RAG?

The Model Context Protocol is a JSON-RPC interface that allows Claude Code to communicate with Code-Graph-RAG as an external tool. It standardizes how the AI client requests graph queries and code edits, enabling the server to handle Cypher generation and AST manipulation independently of the client implementation.

### Can I use Code-Graph-RAG with editors other than Claude Code?

Yes, any MCP-compatible client can connect to the Code-Graph-RAG server. Because the protocol is standardized and language-agnostic, the same `cgr mcp-server` instance works with other AI assistants or IDE integrations that support MCP, provided they can send JSON-RPC requests over HTTP or stdio.

### How does the MCP server handle code edits?

When you request a code change through Claude Code, the server constructs an AST-based diff of the proposed modification. It applies the patch to the filesystem (optionally requiring user confirmation) and then updates the Memgraph database to reflect the new code structure, ensuring the knowledge graph remains synchronized with the actual source files.

### Where is the MCP server configuration documented?

The repository contains specific documentation in [`docs/guide/mcp-server.md`](https://github.com/vitali87/code-graph-rag/blob/main/docs/guide/mcp-server.md) for server command flags and transport options, and [`docs/claude-code-setup.md`](https://github.com/vitali87/code-graph-rag/blob/main/docs/claude-code-setup.md) for client-side configuration. The high-level architecture overview appears in the README.md under the MCP Server section, explaining how the components interact to provide natural-language codebase interaction.