How to Set Up the MCP Server for Claude Code Integration in Code-Graph-RAG

Configure four environment variables and run claude mcp add --transport stdio to expose Code-Graph-RAG's graph intelligence directly inside Claude Code.

Code-Graph-RAG provides an MCP (Model Context Protocol) server that bridges its semantic code graph with AI assistants. Setting up this integration allows Claude Code to query your repository using natural language, perform structural edits, and run advanced analysis tools. This guide covers the complete setup process using the official source files and CLI commands.

Prerequisites for MCP Server Setup

Before registering the server with Claude Code, ensure your environment meets the following requirements:

  • Install Code-Graph-RAG using uv (recommended) or pip with all extras enabled.
  • Start the graph database by running cgr daemon up, which launches the Memgraph and Qdrant containers required for indexing.
git clone https://github.com/vitali87/code-graph-rag.git
cd code-graph-rag
uv sync --extra treesitter-full --extra semantic
cgr daemon up

Required Environment Variables

The MCP server reads configuration from four mandatory environment variables. These must be exported in your shell or passed directly in the claude mcp add command:

  • TARGET_REPO_PATH: Absolute filesystem path to the repository you want to query (e.g., /home/user/my-project).
  • CYPHER_PROVIDER: The LLM provider for generating graph queries. Valid options include openai, google, or ollama.
  • CYPHER_MODEL: The specific model identifier (e.g., gpt-5.6-luna, gemini-3.5-flash-lite, or codellama).
  • CYPHER_API_KEY: Your API key for the selected provider. This is kept secret and never exposed in logs.

Registering the MCP Server with Claude Code

You can register the server using the Claude CLI. Choose the method that matches your installation type.

Method 1: Global Installation

If code-graph-rag is installed globally and available on your $PATH:

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

Method 2: Running from Source

For development or when using uv without global installation:

claude mcp add --transport stdio code-graph-rag \
  --env TARGET_REPO_PATH=/absolute/path/to/your/project \
  --env CYPHER_PROVIDER=google \
  --env CYPHER_MODEL=gemini-3.5-flash-lite \
  --env CYPHER_API_KEY=your-google-api-key \
  -- uv run --directory /path/to/code-graph-rag code-graph-rag mcp-server

Internally, the Claude CLI invokes the mcp-server subcommand defined in codebase_rag/cli_help.py. The wrapper at codebase_rag/mcp/client.py launches this with arguments args=["-m", "codebase_rag.cli", "mcp-server"] to start the JSON-over-stdio API.

Verifying the Integration

Once registered, open Claude Code and test the connection with these natural language commands:

> list_projects
> query_code_graph What functions call UserService.create_user?
> structural_search pattern="func $NAME($ARGS) { $BODY }"
> write_file path=src/utils.py content="def helper(): pass"

The server processes these requests against the Memgraph instance, returning natural language responses or diff previews for file operations.

Core Implementation Files

Understanding the architecture helps with troubleshooting:

  • codebase_rag/mcp/client.py: Contains the client wrapper that spawns the server process and manages the stdio transport.
  • codebase_rag/constants/mcp.py: Defines the tool schemas, method names (e.g., list_projects, query_code_graph), and default arguments available to Claude Code.
  • codebase_rag/cli_help.py: Registers the mcp-server subcommand entry point and handles argument parsing.
  • docs/guide/mcp-server.md: Comprehensive documentation covering advanced configuration, available tools, and troubleshooting steps.

Summary

  • Export four required environment variables (TARGET_REPO_PATH, CYPHER_PROVIDER, CYPHER_MODEL, CYPHER_API_KEY) before starting the server.
  • Use claude mcp add --transport stdio to register the server with Claude Code, specifying the environment variables and launch command.
  • The server wraps the cgr mcp-server command, implemented in codebase_rag/cli_help.py and executed via codebase_rag/mcp/client.py.
  • Ensure cgr daemon up is running to provide the Memgraph backend required for graph queries.

Frequently Asked Questions

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

The MCP is a standardized JSON-over-stdio protocol that allows AI assistants like Claude Code to invoke tools exposed by Code-Graph-RAG. It enables natural language querying of your codebase's graph structure without leaving your editor.

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

The server relies on the Memgraph database (started via cgr daemon up) to execute Cypher queries against the indexed knowledge graph. Without the daemon, the server cannot retrieve semantic relationships, call graphs, or file dependencies.

Can I use local LLMs like Ollama instead of OpenAI?

Yes. Set CYPHER_PROVIDER=ollama and CYPHER_MODEL to your local model name (e.g., codellama). Ensure your Ollama server is accessible at the default endpoint, and the MCP server will route all graph queries to your local instance.

How do I remove or update the MCP server registration?

Run claude mcp remove code-graph-rag to unregister the server. To update settings (such as changing the target repository or model), remove the existing registration and re-run the claude mcp add command with the new environment variables.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →