Claude Desktop MCP Setup¶
Complete guide to integrating Code Graph Knowledge System with Claude Desktop using the Model Context Protocol.
Overview¶
Claude Desktop is Anthropic's official desktop application that supports MCP (Model Context Protocol) integration. This allows Claude to directly call tools in your Code Graph Knowledge System, providing:
- Direct tool access: Claude can query your knowledge base, search code, manage memories
- Natural language interface: Ask questions in plain English
- Context awareness: Claude remembers your project knowledge
- Real-time responses: Immediate tool execution and results
Prerequisites¶
1. Claude Desktop¶
Download and install Claude Desktop:
Download Links: - macOS: https://claude.ai/download - Windows: https://claude.ai/download - Linux: Not officially supported yet (use VS Code extension)
Minimum Version: 0.7.0+ (MCP support added in v0.7.0)
2. Code Graph Knowledge System¶
You need a running instance:
# Option 1: Docker deployment
docker-compose -f docker/docker-compose.full.yml up -d
# Option 2: Local development
python -m codebase_rag --mcp
# Verify it's running
ps aux | grep start_mcp.py
3. Python Environment¶
Claude Desktop needs to invoke your MCP server:
# Check Python version (3.10+ required)
python --version
# Verify dependencies are installed
cd /path/to/codebase-rag
pip install -e .
# Or with uv
uv pip install -e .
Configuration¶
Step 1: Locate Configuration File¶
Claude Desktop stores MCP configuration in a JSON file:
macOS:
Windows:
Step 2: Create Configuration¶
If the file doesn't exist, create it:
# macOS
mkdir -p ~/Library/Application\ Support/Claude
touch ~/Library/Application\ Support/Claude/claude_desktop_config.json
# Windows (PowerShell)
New-Item -Path "$env:APPDATA\Claude\claude_desktop_config.json" -Force
Step 3: Add MCP Server Configuration¶
Edit claude_desktop_config.json:
Basic Configuration¶
{
"mcpServers": {
"code-graph": {
"command": "python",
"args": ["/absolute/path/to/codebase-rag/start_mcp.py"]
}
}
}
With Environment Variables¶
{
"mcpServers": {
"code-graph": {
"command": "python",
"args": ["/absolute/path/to/codebase-rag/start_mcp.py"],
"env": {
"PYTHONPATH": "/absolute/path/to/codebase-rag",
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USER": "neo4j",
"NEO4J_PASSWORD": "your_password",
"LLM_PROVIDER": "ollama",
"OLLAMA_HOST": "http://localhost:11434"
}
}
}
}
Using uv (Recommended)¶
{
"mcpServers": {
"code-graph": {
"command": "uv",
"args": ["run", "mcp_server"],
"cwd": "/absolute/path/to/codebase-rag"
}
}
}
Docker-based Setup¶
{
"mcpServers": {
"code-graph": {
"command": "docker",
"args": [
"exec",
"-i",
"codebase-rag-mcp",
"python",
"/app/start_mcp.py"
]
}
}
}
Step 4: Restart Claude Desktop¶
After configuration changes:
- Quit Claude Desktop completely (not just close window)
- macOS: Cmd+Q
-
Windows: File → Exit
-
Restart Claude Desktop
-
Verify MCP connection (see Verification section)
Configuration Examples¶
Example 1: Full Mode with Ollama¶
{
"mcpServers": {
"code-graph-full": {
"command": "python",
"args": ["/Users/john/projects/codebase-rag/start_mcp.py"],
"env": {
"PYTHONPATH": "/Users/john/projects/codebase-rag",
"DEPLOYMENT_MODE": "full",
"ENABLE_KNOWLEDGE_RAG": "true",
"ENABLE_AUTO_EXTRACTION": "true",
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USER": "neo4j",
"NEO4J_PASSWORD": "mypassword",
"LLM_PROVIDER": "ollama",
"OLLAMA_HOST": "http://localhost:11434",
"OLLAMA_MODEL": "llama3.2",
"EMBEDDING_PROVIDER": "ollama",
"OLLAMA_EMBEDDING_MODEL": "nomic-embed-text"
}
}
}
}
Example 2: Standard Mode (No RAG)¶
{
"mcpServers": {
"code-graph-standard": {
"command": "python",
"args": ["/home/user/codebase-rag/start_mcp.py"],
"env": {
"PYTHONPATH": "/home/user/codebase-rag",
"DEPLOYMENT_MODE": "standard",
"ENABLE_KNOWLEDGE_RAG": "false",
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USER": "neo4j",
"NEO4J_PASSWORD": "password"
}
}
}
}
Example 3: Multiple MCP Servers¶
{
"mcpServers": {
"code-graph-project-a": {
"command": "python",
"args": ["/path/to/project-a/codebase-rag/start_mcp.py"],
"env": {
"NEO4J_DATABASE": "project_a"
}
},
"code-graph-project-b": {
"command": "python",
"args": ["/path/to/project-b/codebase-rag/start_mcp.py"],
"env": {
"NEO4J_DATABASE": "project_b"
}
}
}
}
Verification¶
Check MCP Connection¶
After restarting Claude Desktop:
-
Start a new conversation
-
Look for tool indicator:
- You should see a tools icon or "Tools available" indicator
-
Click to view available tools
-
Verify tools are listed:
- You should see 20-30 tools (depending on deployment mode)
- Tool names:
query_knowledge,add_memory,code_graph_ingest_repo, etc.
Test Basic Functionality¶
Try these test prompts:
Expected: Claude lists all available tools
Expected: Claude calls get_statistics and shows results
Expected: Claude calls query_knowledge with your question
Check Logs¶
If tools don't appear:
MCP Server Logs:
# View server logs
tail -f /path/to/codebase-rag/mcp_server.log
# Enable debug mode
MCP_LOG_LEVEL=DEBUG python -m codebase_rag --mcp
Claude Desktop Logs:
macOS:
Windows:
Usage Patterns¶
1. Query Knowledge Base¶
Prompt:
What Claude Does: 1. Calls query_knowledge tool 2. Passes your question 3. Receives answer with sources 4. Formats and presents results
Response Example:
Based on the knowledge base, here's how to configure Docker deployment:
[Claude presents the answer with source citations]
Sources:
- Docker Guide (score: 0.92)
- Deployment Documentation (score: 0.87)
2. Search Code¶
Prompt:
What Claude Does: 1. Calls code_graph_fulltext_search 2. Finds matching code files 3. Presents results with context
3. Manage Memories¶
Prompt:
"Add a memory: We decided to use PostgreSQL for the main database
because it has better JSON support. This is an important architectural decision."
What Claude Does: 1. Extracts memory details 2. Calls add_memory tool 3. Saves to memory store 4. Confirms success
4. Analyze Code Repository¶
Prompt:
What Claude Does: 1. Calls code_graph_ingest_repo 2. Processes repository 3. Reports statistics
5. Monitor Tasks¶
Prompt:
What Claude Does: 1. Calls get_task_status 2. Returns current status 3. Shows progress if available
Advanced Usage¶
Chained Tool Calls¶
Claude can chain multiple tool calls:
Prompt:
What Claude Does: 1. Calls add_directory to index docs 2. Waits for completion (or gets task_id) 3. Calls query_knowledge with your question 4. Presents combined results
Context Building¶
Prompt:
"Search my memories for database decisions,
then query the knowledge base for PostgreSQL configuration examples"
What Claude Does: 1. Calls search_memories with "database" 2. Calls query_knowledge with "PostgreSQL configuration" 3. Synthesizes information from both sources
Memory Extraction¶
Prompt:
What Claude Does: 1. Calls batch_extract_from_repository 2. Analyzes commits 3. Extracts decisions and learnings 4. Saves as memories
Impact Analysis¶
Prompt:
What Claude Does: 1. Calls code_graph_impact_analysis 2. Finds dependent files 3. Assesses risk level 4. Presents findings
Best Practices¶
1. Be Specific with Tool Names¶
Good:
Less effective:
2. Provide Complete Paths¶
Good:
Bad:
3. Check Tool Availability¶
Before using a tool:
4. Handle Async Operations¶
For long-running tasks:
5. Verify Results¶
After tool calls:
"Show me the sources used for that answer"
"Confirm the memory was saved"
"Verify the repository was ingested successfully"
Troubleshooting¶
Issue: Tools Not Appearing¶
Symptoms: - No tools icon in Claude Desktop - Claude says "I don't have access to tools"
Solutions:
-
Verify configuration file location:
-
Check JSON syntax:
-
Verify absolute paths:
- All paths must be absolute, not relative
-
Expand ~ to full home path
-
Restart completely:
- Force quit Claude Desktop
- Kill any remaining processes
- Start fresh
Issue: Connection Errors¶
Symptoms: - "Failed to connect to MCP server" - Tools listed but calls fail
Solutions:
-
Check server is running:
-
Verify Neo4j connection:
-
Check environment variables:
-
Review MCP server logs:
Issue: Tool Calls Timeout¶
Symptoms: - "Tool call timeout" - Long delays before failure
Solutions:
-
Increase timeout in
.env: -
Check system resources:
-
Use async mode for large operations:
- Directory ingestion
- Large document processing
- Batch memory extraction
Issue: Permission Errors¶
Symptoms: - "Permission denied" when starting MCP server - Cannot read configuration files
Solutions:
-
Fix file permissions:
-
Check directory permissions:
-
Run with correct user:
Issue: Tools Return Errors¶
Symptoms: - "Tool execution failed" - Error messages in responses
Solutions:
-
Check backend services:
-
Review tool-specific logs:
-
Test tools directly via HTTP API:
Performance Optimization¶
Reduce Latency¶
- Use local LLM (Ollama) to avoid API delays
- Enable caching in configuration
- Use incremental mode for code ingestion
- Reduce top_k for faster queries
Improve Response Quality¶
- Add more documents to knowledge base
- Use better embeddings (larger models)
- Add rich metadata to documents
- Curate project memories regularly
Handle Large Operations¶
- Use async mode for:
- Directory ingestion
- Batch memory extraction
-
Large document processing
-
Monitor with watch_task:
Security Considerations¶
Configuration Security¶
-
Protect config file:
-
Don't commit credentials:
- Use environment variables
- Keep passwords in
.envfile -
Add
.envto.gitignore -
Use authentication:
Network Security¶
-
Bind to localhost:
-
Use firewall rules:
Tool Restrictions¶
- Disable destructive tools if needed:
- Modify
start_mcp.pyto exclude certain tools -
Implement tool-level access control
-
Read-only mode:
Next Steps¶
- MCP Overview: Learn about MCP protocol
- VS Code Setup: Configure VS Code extension
- Knowledge RAG Guide: Use query tools
- Memory Store Guide: Manage project memories
Additional Resources¶
- Claude Desktop: https://claude.ai/download
- MCP Documentation: https://modelcontextprotocol.io/
- Configuration Examples:
/examples/mcp_configs/ - Troubleshooting: https://docs.anthropic.com/claude/docs/mcp