# How to Configure the MCP Server for Claude Code Integration in Code-Graph-RAG

> Integrate Claude Code with your code repository by configuring the MCP server. Learn to set TARGET_REPO_PATH and register with claude mcp add for semantic codebase queries.

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

---

**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`](https://github.com/vitali87/code-graph-rag/blob/main/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:

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

```

Constant definitions reside in [`codebase_rag/constants/mcp.py`](https://github.com/vitali87/code-graph-rag/blob/main/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`](https://github.com/vitali87/code-graph-rag/blob/main/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`](https://github.com/vitali87/code-graph-rag/blob/main/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`](https://github.com/vitali87/code-graph-rag/blob/main/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`](https://github.com/vitali87/code-graph-rag/blob/main/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):

```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

```

### Running from Source

When executing from the repository directory, use `uv run` to manage dependencies:

```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 \
  -- 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:

```bash
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`](https://github.com/vitali87/code-graph-rag/blob/main/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 classes
- **`list_projects`** – Enumerate available projects in the graph database
- **`write_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:

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

```

## Summary

- **Set `TARGET_REPO_PATH`** to the absolute path of your target repository; the server reads this from [`codebase_rag/constants/mcp.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/constants/mcp.py) and falls back to [`codebase_rag/config.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/config.py) defaults 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 stdio` for proper CLI integration
- **Tool definitions** are automatically loaded from [`codebase_rag/tools/tool_descriptions.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/tools/tool_descriptions.py) into the `MCPToolsRegistry` when 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`](https://github.com/vitali87/code-graph-rag/blob/main/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`](https://github.com/vitali87/code-graph-rag/blob/main/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`](https://github.com/vitali87/code-graph-rag/blob/main/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`](https://github.com/vitali87/code-graph-rag/blob/main/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.