C++ Graph-RAG MCP Server
A Model Context Protocol server for analyzing large C++ codebases with semantic search, crash dump analysis, and a web UI for configuration.
README
C++ Graph-RAG MCP Server
A powerful Model Context Protocol (MCP) server for analyzing large C++ codebases using Graph-RAG architecture. Features semantic search, crash dump analysis, and a web UI for configuration.
Features
- Graph-RAG Architecture: Combines semantic search (RAG) with relationship graphs
- Crash Dump Analysis: Parse stack traces and find problematic code instantly
- Tree-sitter Parsing: Accurate C++ parsing that understands syntax
- Incremental Indexing: Smart change detection and efficient updates
- pgvector Storage: Fast vector similarity search
- Web UI Dashboard: Configure directories and monitor indexing status
- Docker + Podman: Works with both container runtimes
Quick Start
Prerequisites
- Docker (20.x+) or Podman (4.x+)
- 4GB+ RAM (8GB recommended for large codebases)
- 5GB free disk space
1. Configure Environment
# Copy example config
cp env.example .env
# Edit .env to set your source code path
# Windows example: HOST_PATH=C:/Projects
# Linux example: HOST_PATH=/home/user/projects
2. Build and Start
Using Docker:
# Build images
docker-compose build
# Start services
docker-compose up -d
# View logs
docker-compose logs -f mcp-server
Using Podman:
# Build images
podman-compose build
# Start services
podman-compose up -d
# View logs
podman-compose logs -f mcp-server
3. Configure Directories
Open the web UI at http://localhost:8000 to:
- Browse your mounted directories
- Select folders to index
- Monitor indexing progress
- Test searches
4. Connect to Claude Desktop / VS Code
Add to your MCP client configuration:
Claude Desktop (%APPDATA%\Claude\claude_desktop_config.json on Windows):
{
"mcpServers": {
"cpp-codebase": {
"url": "http://localhost:8000/mcp/v1"
}
}
}
VS Code (MCP extension settings):
{
"mcp.servers": {
"cpp-codebase": "http://localhost:8000/mcp/v1"
}
}
Web UI
The dashboard at http://localhost:8000 provides:
| Feature | Description |
|---|---|
| Indexing Status | View files indexed, entities found, progress |
| Directory Browser | Navigate and select directories to index |
| Quick Search | Test semantic search queries |
| Re-index Button | Manually trigger re-indexing |
Available MCP Tools
search_code
Semantic search across your codebase.
"Find database connection patterns"
"Show mutex locking implementations"
find_symbol
Precise symbol lookup with usages.
"Find ConnectionPool::acquire"
"Where is DatabaseManager defined?"
trace_dependencies
Graph traversal for dependencies.
"What does AuthManager depend on?"
"Show me everything that calls validateUser"
get_context
Comprehensive context for AI agents.
"Get context about the payment processing module"
analyze_debugging_context
Analyze crash dumps from Visual Studio.
Provide: file path, line number, exception info, call stack
find_code_location
Navigate to specific file and line.
"Show me database_connection.cpp line 95"
Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
HOST_PATH |
./example_code |
Path to mount as /host |
MONITORED_PATHS |
(empty) | Comma-separated paths to index |
MCP_PORT |
8000 |
Port for API and web UI |
DB_NAME |
cpp_codebase |
PostgreSQL database name |
DB_USER |
postgres |
Database user |
DB_PASSWORD |
postgres |
Database password |
EMBEDDING_MODEL |
all-MiniLM-L6-v2 |
Sentence transformer model |
Volume Mounting
Mount your source code as read-only:
volumes:
# Mount entire drive (Windows)
- C:/:/host:ro
# Mount specific directory (Linux)
- /home/user/projects:/host:ro
Then use the web UI to select specific subdirectories.
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Container Network │
│ ┌─────────────────────┐ ┌─────────────────────────────┐ │
│ │ PostgreSQL 18 │ │ MCP Server │ │
│ │ + pgvector │◄───│ + FastAPI │ │
│ │ (pg18-trixie) │ │ + Web UI │ │
│ │ Port: 5432 │ │ Port: 8000 │ │
│ └─────────────────────┘ └─────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Commands Reference
Docker
# Start
docker-compose up -d
# Stop
docker-compose down
# View logs
docker-compose logs -f mcp-server
# Rebuild after code changes
docker-compose build --no-cache
# Reset database (deletes all indexed data)
docker-compose down -v
docker-compose up -d
# Check status
docker-compose ps
# Enter container shell
docker-compose exec mcp-server bash
Podman
# Start
podman-compose up -d
# Stop
podman-compose down
# View logs
podman-compose logs -f mcp-server
# Rebuild
podman-compose build --no-cache
# Reset database
podman-compose down -v
podman-compose up -d
API Endpoints
# Check health
curl http://localhost:8000/api/status
# List MCP tools
curl http://localhost:8000/mcp/v1/tools
# Search code
curl -X POST http://localhost:8000/api/search \
-H "Content-Type: application/json" \
-d '{"query": "database connection"}'
# Get directories
curl http://localhost:8000/api/directories
# Browse directory
curl "http://localhost:8000/api/browse?path=/host"
Troubleshooting
Server won't start
# Check logs
docker-compose logs mcp-server
# Common issues:
# - PostgreSQL not ready: Wait 30 seconds
# - Port in use: Change MCP_PORT in .env
# - Out of memory: Increase Docker memory limit
No files indexed
# Verify mount
docker-compose exec mcp-server ls -la /host
# Check configured paths
curl http://localhost:8000/api/directories
Slow indexing
# Use faster embedding model
EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
# Check database size
docker-compose exec postgres psql -U postgres -d cpp_codebase \
-c "SELECT pg_size_pretty(pg_database_size('cpp_codebase'));"
Permission denied on Linux
# Add user to docker group
sudo usermod -aG docker $USER
# Or use podman (rootless by default)
podman-compose up -d
Performance Tips
| Codebase Size | RAM | First Index Time |
|---|---|---|
| 10K LOC | 4GB | ~30 seconds |
| 100K LOC | 4GB | ~5 minutes |
| 1M LOC | 8GB | ~45 minutes |
| 3M+ LOC | 16GB | ~2 hours |
For Large Codebases
- Start with a single module to test
- Use the fast embedding model (default)
- Index only needed directories via web UI
- Consider SSD for database volume
Project Structure
cpp-graph-rag-mcp/
├── server.py # Main MCP server (FastAPI)
├── parser.py # Tree-sitter C++ parser
├── indexer.py # Code indexer
├── crash_analyzer.py # Crash dump analysis
├── vs_context_analyzer.py # VS debugging integration
├── config_manager.py # Configuration persistence
├── requirements.txt # Python dependencies
├── Dockerfile # Container build
├── docker-compose.yml # Multi-container setup
├── env.example # Configuration template
├── static/ # Web UI files
│ ├── index.html
│ ├── styles.css
│ └── app.js
├── example_code/ # Sample C++ for testing
└── docs/ # Documentation
Security Notes
- Server runs on localhost only by default
- Code is mounted read-only
- Database password should be changed for production
- No data leaves your machine (local embeddings)
License
MIT License - Free to use and modify.
Contributing
Key areas for improvement:
- Template specialization handling
- Macro expansion tracking
- Multi-language support
- Visual dependency graph viewer
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。