一个用 Rust 编写的高性能、语言无关的代码分析 MCP(模型上下文协议)服务器。它提供即时符号查找、引用跟踪以及针对大型代码库的语义代码搜索,性能是其首要考虑因素。
该服务器提供了 7 个 MCP 工具,用于全面的代码分析:
index_code索引源代码文件以构建符号表,实现快速查找。
{
"path": "/path/to/project"
}
get_symbol通过名称检索符号信息,可选包含源代码。
{
"name": "function_name",
"include_source": true
}
get_symbol_references在整个代码库中查找符号的所有引用。
{
"name": "symbol_name"
}
find_symbols通过精确匹配或模糊搜索查询符号,可选类型过滤。
{
"query": "test_",
"symbol_type": "function"
}
code_search 🎯通过所有已索引代码内容进行 BM25 统计搜索。
{
"query": "fibonacci algorithm",
"max_results": 10
}
适用于查找:
get_file_outline 📄获取特定文件中符号的结构化大纲。
{
"file_path": "/path/to/file.rs"
}
返回组织视图:
get_directory_outline 📁获取目录中符号的高层次概述。
{
"directory_path": "/path/to/project",
"includes": ["functions", "methods", "constants"]
}
适用于:
git clone https://github.com/kensave/roberto-mcp.git
cd roberto-mcp
cargo build --release
构建后的二进制文件位于 target/release/roberto-mcp。
添加到 Amazon Q CLI 配置
在您的 Amazon Q CLI MCP 配置中添加以下内容:
{
"mcpServers": {
"roberto": {
"command": "/path/to/roberto-mcp/target/release/roberto-mcp",
"args": []
}
}
}
重启 Amazon Q CLI
开始使用
在 Amazon Q CLI 中,您可以提问如下问题:
SymbolStore 结构的所有引用"extract_symbols 函数的实现"MCP Inspector 是一个测试和调试 MCP 服务器的好工具。
安装 MCP Inspector
npx @modelcontextprotocol/inspector
测试服务器
# 运行服务器
./target/release/roberto-mcp
# 在另一个终端运行 MCP Inspector
npx @modelcontextprotocol/inspector ./target/release/roberto-mcp
探索工具
您也可以通过标准输入输出手动测试服务器:
# 启动服务器
./target/release/roberto-mcp
# 发送 MCP 初始化(粘贴此 JSON)
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"}}}
# 发送初始化通知
{"jsonrpc": "2.0", "method": "notifications/initialized"}
# 列出可用工具
{"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}
# 索引一个目录
{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "index_code", "arguments": {"path": "/path/to/your/project"}}}
# 搜索符号
{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "find_symbols", "arguments": {"query": "main", "symbol_type": "function"}}}
# 使用 BM25 搜索代码内容
{"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "code_search", "arguments": {"query": "error handling", "max_results": 5}}}
# 获取带有签名的文件大纲
{"jsonrpc": "2.0", "id": 6, "method": "tools/call", "params": {"name": "get_file_outline", "arguments": {"file_path": "/path/to/file.rs"}}}
# 获取目录概述
{"jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": {"name": "get_directory_outline", "arguments": {"directory_path": "/path/to/project", "includes": ["functions", "classes"]}}}
运行包含的基准测试以验证系统上的性能:
# 运行所有基准测试
cargo bench
# 运行特定基准测试
cargo bench -- symbol_lookup
# 运行性能验证测试
cargo test --test performance_validation -- --nocapture
预期性能目标:
该项目包括全面的测试覆盖率:
# 运行所有测试
cargo test
# 仅运行单元测试
cargo test --lib
# 运行集成测试
cargo test --test integration_test
# 运行性能验证
cargo test --test performance_validation
# 为调试运行输出
cargo test -- --nocapture
测试覆盖率:
总计:83 个测试通过
目前支持 15+ 种语言:
添加新语言: 架构设计易于扩展。要添加新语言:
queries/ 目录创建查询文件Language 枚举和语言检测~/.cache/roberto-mcp/)服务器设计具有鲁棒性:
服务器使用结构化日志,不同级别:
# 启用调试日志
RUST_LOG=debug ./target/release/roberto-mcp
# 启用特定模块的跟踪日志
RUST_LOG=roberto_mcp::indexer=trace ./target/release/roberto-mcp
# 内存管理
export ROBERTO_MAX_MEMORY_MB=1024
export ROBERTO_EVICTION_THRESHOLD=0.8
# 缓存位置
export ROBERTO_CACHE_DIR=~/.cache/roberto-mcp
# 日志
export RUST_LOG=roberto_mcp=info
git checkout -b feature/amazing-feature)cargo test)cargo bench)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)本项目根据 Apache 许可证 2.0 许可 - 详情见 LICENSE 文件。
编译期间出现“未找到符号”错误
rustup updatecargo clean && cargo buildAmazon Q CLI 中服务器无响应
高内存使用
索引性能慢
# 检查服务器版本和功能
./target/release/roberto-mcp --version
# 测试基本功能
cargo test --test integration_test -- test_end_to_end_rust_indexing
# 基准测试性能
cargo test --test performance_validation -- --nocapture
用 Rust 构建,用于闪电般快速的代码分析