How to Configure the MCP Server for Claude Code Integration in Code-Graph-RAG
Configure the MCP server by setting the TARGET_REPO_PATH environment variable to your repository's absolute path, then register it with Claude Code using claude mcp add --transport stdio to enable semantic codebase queries.
The Model Context Protocol (MCP) server in the vitali87/code-graph-rag repository acts as the bridge between Claude Code and your codebase. When properly configured, this integration allows Claude Code to perform semantic searches, navigate AST relationships, and modify files through natural language commands. The configuration process centers on environment variables that define your target repository and LLM backend credentials.
Core Architecture and Configuration Files
The MCP server implementation follows a strict initialization sequence defined across three critical files. In codebase_rag/mcp/server.py, the entry point handles environment resolution, graph initialization, and request routing. The system first resolves the target repository path using a fallback chain defined at line 44:
repo_path = os.environ.get(cs.MCPEnvVar.TARGET_REPO_PATH) or settings.TARGET_REPO_PATH
Constant definitions reside in codebase_rag/constants/mcp.py, which contains the MCPEnvVar enumeration including the TARGET_REPO_PATH key. Default values and the Pydantic settings model live in codebase_rag/config.py, where TARGET_REPO_PATH defaults to "." (the current working directory). Tool descriptions that populate the MCP interface are defined in codebase_rag/tools/tool_descriptions.py and registered through the MCPToolsRegistry.
Required Environment Variables
The server reads four critical variables at startup to configure the target repository and LLM backend:
| Variable | Source | Purpose | Example Value |
|---|---|---|---|
TARGET_REPO_PATH |
codebase_rag/constants/mcp.py |
Absolute path to the codebase for analysis | /home/user/myproject |
CYPHER_PROVIDER |
Environment | LLM provider for graph queries | openai or google |
CYPHER_MODEL |
Environment | Specific model for embeddings/generation | gpt-5.6-luna |
CYPHER_API_KEY |
Environment | API authentication key | sk-... |
If TARGET_REPO_PATH is omitted, the server falls back to the directory from which Claude Code was launched, as implemented in the fallback logic of codebase_rag/mcp/server.py.
Registering the Server with Claude Code
Installation via pip
For packaged installations, use the claude mcp add command with the stdio transport (required for Claude Code CLI integration):
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
Running from Source
When executing from the repository directory, use uv run to manage dependencies:
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
Dynamic Path Configuration
To analyze the current working directory dynamically, pass the environment variable at runtime:
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
Available MCP Tools
Once connected, the server exposes tools defined in codebase_rag/tools/tool_descriptions.py through the MCPHandlerType routing system. Key capabilities include:
semantic_search– Query the codebase using natural language to find relevant functions and classeslist_projects– Enumerate available projects in the graph databasewrite_file– Modify existing files or create new ones within the target repository
Requests are routed through the transport layer (stdio for Claude Code) and return serialized MCPResultType objects. For example, a semantic search request:
{
"tool": "semantic_search",
"params": {
"question": "Find all functions that send an email"
}
}
Summary
- Set
TARGET_REPO_PATHto the absolute path of your target repository; the server reads this fromcodebase_rag/constants/mcp.pyand falls back tocodebase_rag/config.pydefaults if unset - Configure LLM variables (
CYPHER_PROVIDER,CYPHER_MODEL,CYPHER_API_KEY) to enable graph queries and embeddings - Use stdio transport when registering with Claude Code via
claude mcp add --transport stdiofor proper CLI integration - Tool definitions are automatically loaded from
codebase_rag/tools/tool_descriptions.pyinto theMCPToolsRegistrywhen the server initializes
Frequently Asked Questions
What happens if I don't set TARGET_REPO_PATH?
If the environment variable is omitted, the server executes the fallback logic in codebase_rag/mcp/server.py (line 44), defaulting to the current working directory from which Claude Code was launched. This default is defined in codebase_rag/config.py as TARGET_REPO_PATH = ".".
Can I switch from stdio to HTTP transport for Claude Code?
While the server implementation in codebase_rag/mcp/server.py supports both transports via the --transport argument, Claude Code specifically requires stdio for MCP integration. The HTTP transport option exists for other MCP clients, but stdio is mandatory for Claude Code CLI connections.
Where are the tool descriptions stored?
Human-readable tool descriptions reside in codebase_rag/tools/tool_descriptions.py. This file populates the MCPToolsRegistry with definitions for tools like semantic_search and write_file, which Claude Code displays in its interface.
Does the server handle Memgraph initialization automatically?
Yes. After resolving TARGET_REPO_PATH, the server automatically builds or incrementally updates the code graph in Memgraph. You do not need to manually populate the graph database; the server indexes the repository upon startup using the configured LLM provider for embeddings.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →