# How to Start the Code‑Graph‑RAG MCP Server: A Complete Setup Guide

> Start the code-graph-rag MCP server effortlessly. Follow our guide to launch the server using the cgr CLI command after setting up your Memgraph instance.

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

---

**Launch the Code‑Graph‑RAG MCP server using the `cgr mcp-server` CLI command, which dispatches to either STDIO or HTTP transport handlers defined in [`codebase_rag/mcp.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/mcp.py), after starting a Memgraph instance with `cgr daemon up`.**

The **Model Context Protocol (MCP)** enables AI assistants like Claude Code to query and modify codebases through natural language. The **Code‑Graph‑RAG** project (vitali87/code-graph-rag) exposes its graph‑powered RAG capabilities as an MCP server, allowing clients to index repositories and execute Cypher queries against a Memgraph database. To start the code-graph-rag MCP server, you must configure environment variables, launch the graph database, and invoke the correct transport mode.

## Prerequisites and Environment Setup

Before starting the MCP server, ensure **Memgraph** is running and your environment is configured.

**Memgraph Database**: The MCP server requires an active Memgraph instance to store and query code graphs. Start the container using:

```bash
cgr daemon up

```

**Required Environment Variables**: The server expects several environment variables to be set, particularly `TARGET_REPO_PATH` pointing to the repository you want to analyze. When connecting via Claude Code, you must also provide LLM configuration for Cypher generation:

```

TARGET_REPO_PATH=/absolute/path/to/project
CYPHER_PROVIDER=openai
CYPHER_MODEL=gpt-4o  # or your preferred model

CYPHER_API_KEY=YOUR_API_KEY

```

## Installation Options

Install the package using a Python package manager. The `[treesitter-full,semantic]` extras are required for full language parsing capabilities.

```bash

# Using uv (recommended)

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

# Using pipx

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

```

## Starting the MCP Server

The entry point for the server is implemented in [`codebase_rag/cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/cli.py) in the `mcp_server` function (around line 950). This function parses CLI arguments and dispatches to the appropriate transport handler in [`codebase_rag/mcp.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/mcp.py).

### STDIO Transport (Default)

The **STDIO transport** is the default and simplest method, suitable for local MCP clients like Claude Code. It calls `serve_stdio()` from [`codebase_rag/mcp.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/mcp.py):

```bash
cgr mcp-server

```

### HTTP Transport

For remote clients or web-based integrations, use the **HTTP transport** by calling `serve_http(host, port)`:

```bash
cgr mcp-server --transport http --host 0.0.0.0 --port 8000

```

The dispatch logic in [`cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/cli.py) (lines 558‑566) routes to `serve_stdio()` when no transport flag is provided, otherwise invoking `serve_http()` with your specified host and port parameters.

## Connecting Claude Code to the Server

Register the server with Claude Code using the `claude mcp add` command. This configuration uses STDIO transport and passes the required environment variables:

```bash
claude mcp add --transport stdio code-graph-rag \
  --env TARGET_REPO_PATH=/absolute/path/to/project \
  --env CYPHER_PROVIDER=openai \
  --env CYPHER_MODEL=gpt-4o \
  --env CYPHER_API_KEY=YOUR_API_KEY \
  -- cgr mcp-server

```

For the current working directory, substitute `$(pwd)` for the `TARGET_REPO_PATH` value.

## Verifying the Server Connection

After registration, confirm the server is active by listing available tools:

```bash
claude mcp list

```

You should see tools including `list_projects`, `index_repository`, and `query_code_graph`, as defined in the MCP server implementation. These tools allow natural language queries against your codebase graph stored in Memgraph.

## Summary

- **Install** Code‑Graph‑RAG with tree‑sitter and semantic extras via `uv` or `pipx`.
- **Start Memgraph** using `cgr daemon up` before launching the MCP server.
- **Launch the server** with `cgr mcp-server` for STDIO transport or add `--transport http` for remote access.
- **Configure** the `TARGET_REPO_PATH` environment variable to point to your target repository.
- **Connect** Claude Code using `claude mcp add` with the appropriate environment variables for Cypher generation.
- **Verify** functionality by running `claude mcp list` to see available graph querying tools.

## Frequently Asked Questions

### What transport protocols does the Code‑Graph‑RAG MCP server support?

The server supports **STDIO** (standard input/output) and **HTTP** transports. STDIO is the default and is used for local CLI clients like Claude Code, while HTTP is available for remote connections via the `--transport http` flag.

### Why does the MCP server require Memgraph to be running?

The server queries and updates a **graph database** to provide code navigation and semantic search. Memgraph stores the abstract syntax tree (AST) and code relationships. Start it with `cgr daemon up` before launching the MCP server, or the initialization will fail.

### Where is the MCP server logic implemented in the codebase?

The command‑line interface is defined in [`codebase_rag/cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/cli.py) in the `mcp_server` function, which dispatches to transport‑specific handlers. The actual server implementations—`serve_stdio()` and `serve_http()`—reside in [`codebase_rag/mcp.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/mcp.py).

### Can I use a different LLM provider for Cypher query generation?

Yes. While the examples use OpenAI, you can configure any compatible provider by setting the `CYPHER_PROVIDER`, `CYPHER_MODEL`, and `CYPHER_API_KEY` environment variables when registering the server with your MCP client.