A lightweight, high-performance source code analysis MCP server with zero configuration
CodeGraphMCPServer is an MCP server that understands codebase structure and provides GraphRAG (Graph Retrieval-Augmented Generation) capabilities. With a self-contained architecture requiring no external database, it enables structural understanding and efficient code completion from MCP-compatible AI tools (GitHub Copilot, Claude Desktop, Cursor, etc.).
- Community Detection: Automatic code module clustering using Louvain algorithm
- LLM Integration: Multi-provider design supporting OpenAI/Anthropic/Local LLMs
- Global Search: Codebase-wide understanding using community summaries
- Local Search: Context retrieval from entity neighborhoods
| Feature | Description |
|---|---|
| π Zero Configuration | No external DB required, pip install && serve to start immediately |
| π³ AST Analysis | Fast and accurate code analysis with Tree-sitter |
| π Graph Construction | Builds graphs of relationships between code entities |
| π 14 MCP Tools | Dependency analysis, call tracing, code search |
| π 4 MCP Resources | Entities, files, communities, statistics |
| π¬ 6 MCP Prompts | Code review, feature implementation, debug assistance |
| β‘ Fast Indexing | 100K lines in under 30 seconds, incremental updates in under 2 seconds |
| π Multi-language Support | Python, TypeScript, JavaScript, Rust, Go, Java, PHP, C#, C, C++, HCL, Ruby, Kotlin, Swift, Scala, Lua (16 languages) |
- Python 3.11+
- MCP-compatible client (GitHub Copilot, Claude Desktop, Cursor, Windsurf)
pip install codegraph-mcp-servergit clone https://github.com/nahisaho/CodeGraphMCPServer.git
cd CodeGraphMCPServer
python -m venv .venv
source .venv/bin/activate # Linux/macOS
pip install -e ".[dev]"# Full index
codegraph-mcp index /path/to/repository --full
# Incremental index (default)
codegraph-mcp index /path/to/repository
# Auto re-index with file watching (v0.7.0 NEW)
codegraph-mcp watch /path/to/repository
codegraph-mcp watch /path/to/repository --debounce 2.0 # 2 second debounce
codegraph-mcp watch /path/to/repository --community # Community detection after re-indexOutput example:
Indexed 16 entities, 37 relations in 0.81s
codegraph-mcp stats /path/to/repositoryOutput example:
Repository Statistics
=====================
Repository: /path/to/repository
Entities: 16
Relations: 37
Communities: 0
Files: 1
Entities by type:
- class: 2
- function: 2
- method: 11
- module: 1
codegraph-mcp query "Calculator" --repo /path/to/repository# stdio transport (default)
codegraph-mcp serve --repo /path/to/repository
# SSE transport
codegraph-mcp start --repo /path/to/repository --port 8080~/.config/claude/claude_desktop_config.json:
{
"mcpServers": {
"codegraph": {
"command": "codegraph-mcp",
"args": ["serve", "--repo", "/path/to/your/project"]
}
}
}# stdio transport
claude mcp add codegraph -- codegraph-mcp serve --repo /path/to/project
# HTTP transport (SSE server)
codegraph-mcp start --port 8080 # In another terminal
claude mcp add --transport http codegraph http://0.0.0.0:8080.vscode/settings.json:
{
"mcp.servers": {
"codegraph": {
"command": "codegraph-mcp",
"args": ["serve", "--repo", "${workspaceFolder}"]
}
}
}~/.cursor/mcp.json:
{
"mcpServers": {
"codegraph": {
"command": "codegraph-mcp",
"args": ["serve", "--repo", "/path/to/your/project"]
}
}
}| Tool | Description | Main Arguments |
|---|---|---|
query_codebase |
Search code graph with natural language | query, max_results |
find_dependencies |
Find entity dependencies | entity_id, depth |
find_callers |
Find callers of function/method | entity_id |
find_callees |
Find callees of function/method | entity_id |
find_implementations |
Find interface implementations | entity_id |
analyze_module_structure |
Analyze module structure | file_path |
| Tool | Description | Main Arguments |
|---|---|---|
get_code_snippet |
Get entity source code | entity_id, include_context |
read_file_content |
Get file content | file_path, start_line, end_line |
get_file_structure |
Get file structure overview | file_path |
| Tool | Description | Main Arguments |
|---|---|---|
global_search |
Cross-community global search | query |
local_search |
Local search in entity neighborhood | query, entity_id |
| Tool | Description | Main Arguments |
|---|---|---|
suggest_refactoring |
Suggest refactoring | entity_id, type |
reindex_repository |
Re-index repository | incremental |
execute_shell_command |
Execute shell command | command, timeout |
| URI Pattern | Description |
|---|---|
codegraph://entities/{id} |
Entity details |
codegraph://files/{path} |
Entities in file |
codegraph://communities/{id} |
Community information |
codegraph://stats |
Graph statistics |
| Prompt | Description | Arguments |
|---|---|---|
code_review |
Perform code review | entity_id, focus_areas |
explain_codebase |
Explain codebase | scope, detail_level |
implement_feature |
Feature implementation guide | feature_description, constraints |
debug_issue |
Debug assistance | issue_description, context |
refactor_guidance |
Refactoring guide | entity_id, goal |
test_generation |
Test generation | entity_id, test_type |
You: What are the dependencies of the UserService class?
AI: [Using find_dependencies tool]
UserService depends on:
- DatabaseConnection (database.py)
- Logger (utils/logging.py)
- UserRepository (repositories/user.py)
You: What would be affected if I modify the authenticate method?
AI: [Using find_callers tool]
Callers of authenticate:
- LoginController.login() (controllers/auth.py:45)
- APIMiddleware.verify_token() (middleware/api.py:23)
- TestUserService.test_auth() (tests/test_user.py:78)
You: Explain the main components of this project
AI: [Using global_search tool]
[Using explain_codebase prompt]
This project uses a 3-tier architecture:
1. Controllers layer: HTTP request handling
2. Services layer: Business logic
3. Repositories layer: Data access
# Run all tests
pytest
# With coverage
pytest --cov=src/codegraph_mcp --cov-report=html
# Specific tests
pytest tests/unit/test_parser.py -v# Lint with Ruff
ruff check src tests
# Format with Ruff
ruff format src tests
# Type check with MyPy
mypy srcsrc/codegraph_mcp/
βββ __init__.py # Package initialization
βββ __main__.py # CLI entry point
βββ server.py # MCP server
βββ config.py # Configuration management
βββ core/ # Core logic
β βββ parser.py # Tree-sitter AST parser
β βββ graph.py # NetworkX graph engine
β βββ indexer.py # Repository indexer
β βββ community.py # Community detection (Louvain)
β βββ semantic.py # Semantic analysis
β βββ llm.py # LLM integration (OpenAI/Anthropic/Local)
β βββ graphrag.py # GraphRAG search engine
βββ storage/ # Storage layer
β βββ sqlite.py # SQLite persistence
β βββ cache.py # File cache
β βββ vectors.py # Vector store
βββ mcp/ # MCP interface
β βββ tools.py # 14 MCP Tools
β βββ resources.py # 4 MCP Resources
β βββ prompts.py # 6 MCP Prompts
βββ languages/ # Language support (12 languages)
βββ python.py # Python extractor
βββ typescript.py # TypeScript extractor
βββ javascript.py # JavaScript extractor
βββ rust.py # Rust extractor
βββ go.py # Go extractor
βββ java.py # Java extractor
βββ php.py # PHP extractor
βββ csharp.py # C# extractor
βββ c.py # C extractor
βββ cpp.py # C++ extractor
βββ hcl.py # HCL (Terraform) extractor
βββ ruby.py # Ruby extractor
| Metric | Measured | Notes |
|---|---|---|
| Indexing speed | 32 entities/sec | 67 files, 941 entities |
| File processing speed | 0.44 sec/file | Python/TS/Rust mixed |
| Incremental index | < 2 sec | Changed files only |
| Query response | < 2ms | Graph search |
| Metric | Target |
|---|---|
| Initial index (100K lines) | < 30 sec |
| Incremental index | < 2 sec |
| Query response | < 500ms |
| Startup time | < 2 sec |
| Memory usage | < 500MB |
MIT License - See LICENSE
- Model Context Protocol - MCP specification
- Tree-sitter - AST analysis
- NetworkX - Graph algorithms
- Microsoft GraphRAG - GraphRAG concept