使用说明
lsp-mcp
LSP-MCP是由Agentic Labs在lsproxy项目的基础上构建的。
目标是提供一个多语言MCP服务器,通过语言服务器和树保姆提供精确的代码导航和分析
主要设计用于通过MCP stdio为AI编码代理公开LSP功能。针对Golang、Rust和Typescript进行了测试。虽然基于原始的lsproxy实现也支持Python、Ruby等。
学分
这是在Agentic Labs的lsproxy项目的基础上构建的,而树保姆的实现灵感来自Roo Code项目。最初的实施归功于他们。
主要特点
- 🎯 精确代码导航:跳转到定义,查找所有引用,并在整个项目中导航实现。
- 🔍 符号搜索:在工作区中按名称搜索符号,或在文件中查找标识符。
- 📝 代码智能:在任何位置获取悬停信息、类型签名和上下文感知代码详细信息。
- 🌳 调用层次结构:查询传入和传出的函数调用,包括外部依赖关系。
- 🔗 参考分析:查找定义引用的符号并探索代码关系。
- 📊 代码诊断:获取文件或整个工作区的特定语言lint错误、警告和诊断。
- 🔄 语义搜索:(可选)使用语义相似性嵌入执行自然语言代码搜索。
- 🌐 多语言支持:通过单个MCP服务器访问多个语言服务器(Rust、TypeScript、Go、Python、Ruby、Java、PHP、C/C++)。
- 🛠️ 自动配置:引导式设置工具,用于根据您的项目文件检测和配置语言服务器。
- 📁 文件操作:列出工作区文件并读取支持行/字符范围的源代码。
每个项目根运行一个MCP服务器。除非被覆盖,否则服务器将使用当前工作目录作为工作区。
安装
cargo run --bin lsp-mcp -- --workspace-root /path/to/project
源代码构建需要在以下位置安装ast-grep规则 /usr/src/ast_grep:
bash scripts/install-ast-grep-rules.sh
配置您的MCP客户端,以项目根目录作为工作目录启动服务器。服务器通过stdio进行通信。
预先构建语义搜索索引
启用语义搜索后,初始索引可能会占用大量资源。为了避免MCP正常使用过程中的速度减慢,您可以从命令行预构建索引:
# Build index for current directory
lsp-mcp --index
# Build index for a specific workspace
lsp-mcp --index --workspace-root /path/to/project
# Force full rebuild from scratch
lsp-mcp --index --force
这 --index 标志:
- 构建语义搜索索引并退出(不启动MCP服务器)
- 自动启用语义搜索,即使未在中配置
.lsp-mcp.json - 显示进度:
Indexing: 150/500 files (30%) - 报告最终统计数据:索引的块和经过的时间
这 --force flag删除所有现有索引并从头开始重建。
GPU加速(快速嵌入)
FastEmbed使用ONNX运行时执行提供程序。GPU加速在构建时通过货物功能启用并使用 在运行时自动执行(选择最高优先级的可用提供程序,然后CPU回退)。
构建标志:
# macOS Apple Silicon (CoreML / ANE where available)
cargo build --features ort-coreml
# Windows NVIDIA (CUDA) + DirectML fallback
cargo build --features ort-cuda,ort-directml
# Windows DirectML only (AMD/Intel/NVIDIA DX12 GPUs)
cargo build --features ort-directml
# Linux AMD ROCm (optional)
cargo build --features ort-rocm
笔记:
- CUDA需要在目标计算机上启用CUDA的ONNX运行时构建和兼容的NVIDIA驱动程序/运行时。
- DirectML需要Windows 10+和支持DX12的GPU(AMD/Intel/NVIDIA)。
- CoreML在macOS上受支持,并将在可用时使用ANE。
关于CoreML的说明: 我已经在我的M1 Max Macbook Pro上测试过了,它可以工作,但比CPU回退慢。CPU回退将在初始索引时消耗大量资源几分钟,然后在重新索引文件时稳定到较小的峰值。
MCP客户端配置
使用stdio MCP客户端配置,每个工作区启动一台服务器。关键部分是 command 和 args;如果你的客户支持 cwd,将其设置为工作区根。
开发人员(从源代码运行):
{
"mcpServers": {
"lsp-mcp": {
"command": "cargo",
"args": [
"run",
"--bin",
"lsp-mcp",
"--",
"--workspace-root",
"/path/to/project"
],
"cwd": "/path/to/project"
}
}
}
软件包(已安装二进制文件):
{
"mcpServers": {
"lsp-mcp": {
"command": "lsp-mcp",
"args": [
"--workspace-root",
"/path/to/project"
],
"cwd": "/path/to/project"
}
}
}
克劳德代码(~/.claude.json):
开发人员(从源代码运行):
{
"mcpServers": {
"lsp-mcp": {
"type": "stdio",
"command": "cargo",
"args": [
"run",
"--bin",
"lsp-mcp",
"--",
"--workspace-root",
"/path/to/project"
],
"cwd": "/path/to/project"
}
}
}
软件包(已安装二进制文件):
{
"mcpServers": {
"lsp-mcp": {
"type": "stdio",
"command": "lsp-mcp",
}
}
}
Codex CLI(~/.codex/config.toml):
开发人员(从源代码运行):
[mcp_servers.lsp-mcp]
command = "cargo"
args = ["run", "--bin", "lsp-mcp", "--", "--workspace-root", "/path/to/project"]
软件包(已安装二进制文件):
[mcp_servers.lsp-mcp]
command = "lsp-mcp"
args = ["--workspace-root", "/path/to/project"]
配置
您可以自定义 lsp-mcp 行为与a .lsp-mcp.json 工作区根目录中的文件。
看 CONFIGURATION.md 查看完整的模式和示例。
首次设置
首次启动时(无项目配置) initialSetup 该工具在标准预设中启用,以帮助配置语言和二进制文件。
如果一个项目 .lsp-mcp.json 存在, initialSetup 除非您设置,否则将自动禁用 "tools": { "initial_setup": "enabled" }.
设置后,添加 initialSetup 到 "tools": { "disable": ["initialSetup"] } 并重新启动您的代理。
输出模式
控制工具输出的冗长程度:
{
"output": {
"mode": "verbose"
}
}
"default"(默认):紧凑型输出格式"verbose":具有完整信息的详细输出
支持的语言
| 语言 | 服务器 | URL |
|---|---|---|
| C/C++ | clangd |
https://clangd.llvm.org/ |
| Golang | gopls |
https://github.com/golang/tools/tree/master/gopls |
Javajdtls |
https://github.com/eclipse-jdtls/eclipse.jdt.ls | |
| Javascript | typescript-language-server |
https://github.com/typescript-language-server/typescript-language-server |
| PHP | phpactor |
https://github.com/phpactor/phpactor |
pythonjedi-language-server |
https://github.com/pappasam/jedi-language-server | |
| 生锈 | rust-analyzer |
https://github.com/rust-lang/rust-analyzer |
| 打字 | typescript-language-server |
https://github.com/typescript-language-server/typescript-language-server |
| csharp | omnisharp-roslyn |
https://github.com/OmniSharp/omnisharp-roslyn |
| 你最喜欢的语言 | 很棒的语言服务器 | https://github.com/agentic-labs/lsproxy/issues/new |