CodeCortX-MCP
A lightning-fast, language-agnostic code analysis MCP (Model Context Protocol) server built in Rust
README
CodeCortXMCP Server
A lightning-fast, language-agnostic code analysis MCP (Model Context Protocol) server built in Rust. Provides instant symbol lookups, reference tracking, and semantic code search for large codebases with performance as a first-class citizen.
🚀 Features
- ⚡ High Performance: <1ms symbol lookups, >100 files/sec indexing
- 🔒 Lock-free Concurrency: No blocking operations, handles concurrent requests efficiently
- 🧠 Smart Caching: Binary persistence with <1s startup for previously indexed repositories
- 📊 Memory Management: Automatic LRU eviction with configurable memory limits
- 🔄 Incremental Updates: File watching with SHA-256 change detection
- 🌍 Multi-language: 15+ languages supported with extensible architecture
- 🛡️ Error Resilient: Graceful handling of malformed code and I/O errors
- 🔍 Full-text Search: BM25 statistical search through all code content
🏗️ Architecture
- Language: Rust (performance + safety)
- Parser: Tree-sitter (consistent, incremental parsing)
- Storage: In-memory DashMap + binary persistence
- Concurrency: Lock-free data structures
- Protocol: MCP over JSON-RPC stdio
📋 MCP Tools
The server provides 7 MCP tools for comprehensive code analysis:
1. index_code
Index source code files to build symbol table for fast lookups.
{
"path": "/path/to/project"
}
2. get_symbol
Retrieve symbol information by name with optional source code inclusion.
{
"name": "function_name",
"include_source": true
}
3. get_symbol_references
Find all references to a symbol across the codebase.
{
"name": "symbol_name"
}
4. find_symbols
Search symbols by query using exact match or fuzzy search with optional type filtering.
{
"query": "test_",
"symbol_type": "function"
}
5. code_search 🎯
BM25 statistical search through all indexed code content.
{
"query": "fibonacci algorithm",
"max_results": 10
}
Perfect for finding:
- Algorithm implementations:
"binary search algorithm" - Error handling patterns:
"error handling try catch" - Database code:
"database connection pool" - Specific functionality:
"file upload validation"
6. get_file_outline 📄
Get structured outline of symbols in a specific file.
{
"file_path": "/path/to/file.rs"
}
Returns organized view of:
- Classes/Structs with signatures
- Functions/Methods with full signatures and parameters
- Constants, Enums, Interfaces, Modules, Imports, Variables
- Line numbers and visibility (pub/priv)
7. get_directory_outline 📁
Get high-level overview of symbols across a directory.
{
"directory_path": "/path/to/project",
"includes": ["functions", "methods", "constants"]
}
Perfect for:
- Project structure understanding
- API surface discovery
- Architecture overview
- Code navigation
🛠️ Installation & Setup
Prerequisites
- Rust 1.70+ with Cargo
- Git
Building from Source
git clone https://github.com/kensave/codecortx-mcp.git
cd codecortx-mcp
cargo build --release
The binary will be available at target/release/codecortx-mcp.
🔧 Usage
With Amazon Q CLI
-
Add to Amazon Q CLI Configuration
Add the following to your Amazon Q CLI MCP configuration:
{ "mcpServers": { "codecortx": { "command": "/path/to/codecortx-mcp/target/release/codecortx-mcp", "args": [] } } } -
Restart Amazon Q CLI
-
Start Using
In Amazon Q CLI, you can now ask questions like:
- "Index the code in my project directory"
- "Find all functions that contain 'parse' in their name"
- "Show me all references to the
SymbolStorestruct" - "Get the implementation of the
extract_symbolsfunction" - "Search for fibonacci algorithm implementations"
- "Find error handling patterns in the codebase"
- "Show me the outline of this file with all functions and their signatures"
- "Get an overview of all classes and methods in this directory"
Testing with MCP Inspector
MCP Inspector is a great tool for testing and debugging MCP servers.
-
Install MCP Inspector
npx @modelcontextprotocol/inspector -
Test the Server
# Run the server ./target/release/codecortx-mcp # In another terminal, run MCP Inspector npx @modelcontextprotocol/inspector ./target/release/codecortx-mcp -
Explore the Tools
- View available tools and their schemas
- Test tool calls with sample data
- Inspect request/response cycles
- Debug any integration issues
Manual Testing via Command Line
You can also test the server manually using stdio:
# Start the server
./target/release/codecortx-mcp
# Send MCP initialization (paste this JSON)
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"}}}
# Send initialized notification
{"jsonrpc": "2.0", "method": "notifications/initialized"}
# List available tools
{"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}
# Index a directory
{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "index_code", "arguments": {"path": "/path/to/your/project"}}}
# Search for symbols
{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "find_symbols", "arguments": {"query": "main", "symbol_type": "function"}}}
# Search code content with BM25
{"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "code_search", "arguments": {"query": "error handling", "max_results": 5}}}
# Get file outline with signatures
{"jsonrpc": "2.0", "id": 6, "method": "tools/call", "params": {"name": "get_file_outline", "arguments": {"file_path": "/path/to/file.rs"}}}
# Get directory overview
{"jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": {"name": "get_directory_outline", "arguments": {"directory_path": "/path/to/project", "includes": ["functions", "classes"]}}}
⚡ Performance Benchmarks
Run the included benchmarks to validate performance on your system:
# Run all benchmarks
cargo bench
# Run specific benchmark
cargo bench -- symbol_lookup
# Run performance validation tests
cargo test --test performance_validation -- --nocapture
Expected Performance Targets:
- Symbol lookups: <1ms average
- Indexing speed: >100 files/second
- Concurrent access: >50k lookups/second
- Memory usage: <1GB for large repositories
🧪 Testing
The project includes comprehensive test coverage:
# Run all tests
cargo test
# Run unit tests only
cargo test --lib
# Run integration tests
cargo test --test integration_test
# Run performance validation
cargo test --test performance_validation
# Run with output for debugging
cargo test -- --nocapture
Test Coverage:
- 54 unit tests covering all core modules
- 5 integration tests for end-to-end workflows
- 5 performance tests validating requirements
- 15 language-specific tests
- 4 outline tool tests
Total: 83 tests passing
🔍 Supported Languages
Currently supports 15+ languages:
- Rust (.rs): Functions, structs, enums, traits, implementations, constants, modules
- Python (.py): Functions, classes, methods, variables, imports
- JavaScript (.js): Functions, classes, methods, constants, variables
- TypeScript (.ts): Functions, classes, interfaces, types, enums
- Java (.java): Classes, methods, interfaces, enums, constants
- Go (.go): Functions, structs, interfaces, constants, variables
- C (.c): Functions, structs, enums, typedefs, variables
- C++ (.cpp, .hpp): Classes, functions, namespaces, templates
- Ruby (.rb): Classes, modules, methods, constants
- PHP (.php): Classes, functions, methods, constants
- C# (.cs): Classes, methods, interfaces, enums, properties
- Kotlin (.kt): Classes, functions, interfaces, objects
- Scala (.scala): Classes, objects, traits, functions
- Swift (.swift): Classes, structs, protocols, functions
- Objective-C (.m, .h): Classes, methods, protocols, categories
Adding New Languages: The architecture is designed for easy extension. To add a new language:
- Add Tree-sitter grammar dependency
- Create query files in
queries/directory - Update
Languageenum and language detection - Add to supported extensions
💾 Caching & Persistence
- Cache Location: Uses system cache directory (
~/.cache/codecortext-mcp/on Unix) - Cache Format: Custom binary format with bincode serialization
- Cache Key: Based on repository path and last modification times
- Cache Validation: Automatic validation on startup with incremental updates
- Memory Management: LRU eviction when memory pressure detected (configurable)
🛡️ Error Handling
The server is designed for robustness:
- Parse Errors: Continues indexing other files, logs issues
- File System Errors: Graceful degradation with partial results
- Memory Pressure: Automatic cleanup and eviction
- Malformed Requests: Proper MCP error responses
- Concurrent Access: Lock-free structures prevent deadlocks
📊 Monitoring & Logging
The server uses structured logging with different levels:
# Enable debug logging
RUST_LOG=debug ./target/release/codecortx-mcp
# Enable trace logging for specific modules
RUST_LOG=codecortx_mcp::indexer=trace ./target/release/codecortx-mcp
⚙️ Configuration
Environment Variables
# Memory management
export CODECORTEXT_MAX_MEMORY_MB=1024
export CODECORTEXT_EVICTION_THRESHOLD=0.8
# Cache location
export CODECORTX_CACHE_DIR=~/.cache/codecortx-mcp
# Logging
export RUST_LOG=codecortx_mcp=info
🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Run the test suite (
cargo test) - Run benchmarks to ensure no performance regression (
cargo bench) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📝 License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
🔧 Troubleshooting
Common Issues
-
"Symbol not found" errors during compilation
- Ensure you have the latest Rust toolchain:
rustup update - Clean and rebuild:
cargo clean && cargo build
- Ensure you have the latest Rust toolchain:
-
Server not responding in Amazon Q CLI
- Check the config file path and syntax
- Verify the binary path is correct and executable
- Check Amazon Q CLI logs for error messages
-
High memory usage
- Configure memory limits via environment variables
- The server will automatically evict least-recently-used files
- Consider indexing smaller subdirectories for very large repositories
-
Slow indexing performance
- Check disk I/O performance
- Ensure no antivirus is scanning files during indexing
- Use SSD storage for better performance
Debug Commands
# Check server version and capabilities
./target/release/codecortx-mcp --version
# Test basic functionality
cargo test --test integration_test -- test_end_to_end_rust_indexing
# Benchmark performance
cargo test --test performance_validation -- --nocapture
📚 Documentation
- Architecture Guide - Detailed system architecture
- Development Guide - Setup and development workflow
- API Reference - Complete MCP tool documentation
Built with ❤️ in Rust for lightning-fast code analysis
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。