# How to Start the MCP Server for Claude Code Integration with Code-Graph-RAG

> Start the MCP server for Claude Code integration with vitali87/code-graph-rag. Run cgr mcp-server after cgr daemon up and add the server with claude mcp add for AI code queries.

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

---

**Run `cgr mcp-server` after installing the package and starting the Docker services with `cgr daemon up`, then register the server with Claude Code using the `claude mcp add` command to enable AI-powered codebase queries.**

The **MCP (Model-Context Protocol) server** bridges Claude Code and the Code-Graph-RAG knowledge graph, allowing AI agents to query your codebase structure and semantics through deterministic tools. This integration transforms Claude Code into an intelligent coding assistant that understands cross-file relationships stored in Memgraph. According to the vitali87/code-graph-rag source code, the server runs as a stdio-based process that exposes graph query capabilities via the MCP protocol.

## Prerequisites: Installation and Docker Setup

Before starting the MCP server, you must install the Code-Graph-RAG package and spin up the required backend services. The system relies on **Memgraph** for the knowledge graph and **Qdrant** for vector storage, both containerized via Docker.

### Installing the Package

Install the tool using `uv` (recommended) or `pipx` to place the `cgr` executable on your PATH:

```bash

# Via uv (recommended)

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

# Or via pipx

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

```

The `[treesitter-full,semantic]` extras ensure full language parsing capabilities required for graph construction.

### Starting the Backend Services

Launch the Docker containers for Memgraph and Qdrant:

```bash
cgr daemon up

```

This command initializes the graph database where your codebase structure will be indexed.

## Starting the MCP Server

Once dependencies are running, you can start the server using either the installed binary or by running directly from source.

### From Binary Installation

If you installed via `uv` or `pipx`, simply execute:

```bash
cgr mcp-server

```

This starts a long-running stdio process that listens for MCP protocol messages and exposes tools defined in [`codebase_rag/mcp/tools.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/mcp/tools.py).

### From Source Checkout

When developing or running from a local clone of the vitali87/code-graph-rag repository:

```bash
git clone https://github.com/vitali87/code-graph-rag.git
cd code-graph-rag
uv sync

# Start the server via uv

uv run --directory . code-graph-rag mcp-server

```

The entry point for this command is defined in [`codebase_rag/cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/cli.py) around line 950, where the `mcp_server` Typer command initializes the stdio server using the `mcp` library.

## Registering the Server with Claude Code

After starting the server, register it as an MCP provider in Claude Code. This requires specifying environment variables for the target repository and LLM configuration.

```bash
claude mcp add --transport stdio code-graph-rag \
  --env TARGET_REPO_PATH=/absolute/path/to/your/project \
  --env CYPHER_PROVIDER=openai \
  --env CYPHER_MODEL=gpt-5.6-luna \
  --env CYPHER_API_KEY=your-api-key \
  -- code-graph-rag mcp-server

```

**Important limitation**: Only one repository can be indexed per MCP instance. When you change `TARGET_REPO_PATH` to a new directory, the previous index is cleared automatically.

Verify the registration:

```bash
claude mcp list

```

You should see `code-graph-rag` listed among available MCP servers.

## Architectural Overview and Key Files

Understanding the implementation helps troubleshoot integration issues and extend functionality.

### CLI Entry Point

The `mcp_server` command is implemented in [`codebase_rag/cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/cli.py). This function initializes the stdio transport and registers all available tools.

### MCP Client Helper

For programmatic access outside Claude Code, [`codebase_rag/mcp/client.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/mcp/client.py) contains the `query_mcp_server` function. This helper opens a temporary stdio client, sends JSON-RPC requests, and parses responses:

```python
from codebase_rag.mcp.client import query_mcp_server

response = query_mcp_server("What functions call UserService.create_user?")
print(response["output"])

```

### Tool Definitions

All deterministic tools exposed to Claude Code—such as `list_projects`, `query_code_graph`, and `ask_agent`—are defined in [`codebase_rag/mcp/tools.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/mcp/tools.py). These tools connect to Memgraph via `pymgclient` to execute Cypher queries against the knowledge graph.

## Summary

- **Install** the package using `uv tool install` or `pipx install` with the `[treesitter-full,semantic]` extras to get the `cgr` command
- **Start services** with `cgr daemon up` to launch Memgraph and Qdrant containers
- **Launch the server** using `cgr mcp-server`, which runs as a stdio process defined in [`codebase_rag/cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/cli.py)
- **Register with Claude Code** via `claude mcp add`, setting `TARGET_REPO_PATH` and `CYPHER_*` environment variables
- **Query programmatically** using the helper in [`codebase_rag/mcp/client.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/mcp/client.py) when building external integrations

## Frequently Asked Questions

### What environment variables are required to start the MCP server for Claude Code?

The essential variables are `TARGET_REPO_PATH` (absolute path to the repository to index), `CYPHER_PROVIDER` (e.g., "openai"), `CYPHER_MODEL` (the specific model name), and `CYPHER_API_KEY` (your LLM API key). These are passed via the `--env` flags when running `claude mcp add`.

### Can I index multiple repositories with one MCP server instance?

No, the architecture currently supports only one repository per MCP instance. When you point `TARGET_REPO_PATH` to a new directory, the previous graph data is cleared automatically. For multiple repositories, you must run separate MCP server instances with different configurations.

### How do I verify that the MCP server is running correctly?

First, ensure `cgr daemon up` has started the Memgraph and Qdrant containers without errors. Then run `claude mcp list` after registration—you should see `code-graph-rag` in the output. You can also test the Python helper `query_mcp_server` from [`codebase_rag/mcp/client.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/mcp/client.py) to verify stdio communication.

### Where is the MCP server entry point defined in the source code?

The command implementation is located in [`codebase_rag/cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/cli.py) around line 950, within the `mcp_server` function. This Typer command sets up the stdio transport and wires the tools defined in [`codebase_rag/mcp/tools.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/mcp/tools.py) to handle incoming MCP requests.