How to Configure MCP Server for Claude Code Integration: A Complete Guide

Configure the MCP server for Claude Code by setting the TARGET_REPO_PATH environment variable to point at your repository, then register the server with claude mcp add --transport stdio.

The MCP (Model Context Protocol) server in Code‑Graph‑RAG enables Claude Code to query, analyze, and edit codebases through natural language. This bridge transforms your repository into a searchable knowledge graph that Claude Code can interrogate in real time. Whether you install via pip or run from source, configuration requires only a handful of environment variables to connect your project and LLM backend.

Prerequisites and Core Concepts

Before launching the server, understand how Code‑Graph‑RAG structures its MCP implementation. The server is transport‑agnostic, supporting both stdio (for CLI integration) and HTTP (for custom clients). It maintains a live code graph in Memgraph, exposing tools like semantic_search, list_projects, and write_file to MCP clients.

The entry point resides in codebase_rag/mcp/server.py, which orchestrates:

Required Environment Variables

The server reads configuration at startup. These variables control repository access and LLM integration:

Variable Purpose Example Value
TARGET_REPO_PATH Absolute path to the project to analyze /home/user/my-project
CYPHER_PROVIDER LLM provider for graph operations openai, google
CYPHER_MODEL Specific model for embeddings/generation gpt-5.6-luna, gemini-3.5-flash-lite
CYPHER_API_KEY Authentication key for the LLM provider sk-... (never commit this)

If TARGET_REPO_PATH is omitted, the server falls back to the current working directory. This fallback is implemented in codebase_rag/mcp/server.py at line 44:

repo_path = os.environ.get(cs.MCPEnvVar.TARGET_REPO_PATH) or settings.TARGET_REPO_PATH

The constant TARGET_REPO_PATH is defined in codebase_rag/constants/mcp.py, with its default value "." established in codebase_rag/config.py.

Installation and Registration Commands

Method 1: Installed via pip

For pip-installed Code‑Graph‑RAG, register the MCP server with Claude Code using:

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 with uv

When developing or running the bleeding-edge version:

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 \
  -- uv run --directory /path/to/code-graph-rag code-graph-rag mcp-server

Method 3: Current directory as target

For iterative work on a single project, use shell expansion to dynamically set the path:

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

How the Server Processes Requests

Once registered, Claude Code sends MCP requests that the server routes through this pipeline:

  1. Environment resolution — TARGET_REPO_PATH and LLM credentials are loaded
  2. Graph initialization — The target repository is indexed into Memgraph (incrementally updated if previously processed)
  3. Tool execution — Requests like semantic_search execute against the graph
  4. Response serialization — Results return as MCPResultType for Claude Code to display

Example interaction from Claude Code:

{
  "tool": "semantic_search",
  "params": {
    "question": "Find all functions that send an email"
  }
}

The server responds with matching functions ranked by semantic similarity, enabling natural language code exploration.

Key Source Files Reference

Understanding these files aids debugging and customization:

Summary

  • Set TARGET_REPO_PATH to the absolute path of your target repository
  • Provide LLM credentials via CYPHER_PROVIDER, CYPHER_MODEL, and CYPHER_API_KEY
  • Use --transport stdio for Claude Code CLI integration
  • Register once with claude mcp add; the server runs continuously in the background
  • Source files in codebase_rag/mcp/server.py and codebase_rag/config.py control all configuration logic

Frequently Asked Questions

What happens if TARGET_REPO_PATH is not set?

The server defaults to the current working directory. This fallback is defined in codebase_rag/config.py with TARGET_REPO_PATH = "." and applied in codebase_rag/mcp/server.py line 44 when the environment variable is absent.

Can I use a different LLM provider than OpenAI?

Yes. Set CYPHER_PROVIDER to any supported backend (e.g., google for Gemini). The CYPHER_MODEL and CYPHER_API_KEY must correspond to your chosen provider. The server's LLM abstraction in codebase_rag/config.py handles provider-specific initialization.

How do I verify the server is properly registered?

Run claude mcp list to see registered servers. If code-graph-rag appears with your configured environment variables, registration succeeded. Launch Claude Code and attempt a natural language query like "find authentication functions" to test the connection.

Is HTTP transport required for any use cases?

No. The stdio transport suffices for Claude Code CLI integration. HTTP transport benefits custom MCP clients or remote deployments where the server must accept requests over a network. Specify --transport http and expose the appropriate port if needed.

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 →