MCP语言服务器
   ](https://github.com/isaacphi/mcp-language-server/blob/main/go.mod)
演示
mcp-language-server 通过为启用MCP的客户端提供获取定义、引用、重命名和诊断等语义工具,帮助他们更轻松地浏览代码库。
设置
- 安装Go:遵循以下说明
- 安装或更新此服务器:
go install github.com/isaacphi/mcp-language-server@latest - 安装语言服务器: _遵循以下指南之一_
- 配置您的MCP客户端: _遵循以下指南之一_
Go (gopls)
Install gopls: go install golang.org/x/tools/gopls@latest
Configure your MCP client: This will be different but similar for each client. For Claude Desktop, add the following to ~/Library/Application\ Support/Claude/claude_desktop_config.json
{ "mcpServers": { "language-server": { "command": "mcp-language-server", "args": ["--workspace", "/Users/you/dev/yourproject/", "--lsp", "gopls"], "env": { "PATH": "/opt/homebrew/bin:/Users/you/go/bin", "GOPATH": "/users/you/go", "GOCACHE": "/users/you/Library/Caches/go-build", "GOMODCACHE": "/Users/you/go/pkg/mod" } } } }
Note: Not all clients will need these environment variables. For Claude Desktop you will need to update the environment variables above based on your machine and username:
PATH needs to contain the path to go and to gopls. Get this with echo $(which go):$(which gopls)
GOPATH, GOCACHE, and GOMODCACHE may be different on your machine. These are the defaults.
Rust (rust-analyzer)
Install rust-analyzer: rustup component add rust-analyzer
Configure your MCP client: This will be different but similar for each client. For Claude Desktop, add the following to ~/Library/Application\ Support/Claude/claude_desktop_config.json
{ "mcpServers": { "language-server": { "command": "mcp-language-server", "args": [ "--workspace", "/Users/you/dev/yourproject/", "--lsp", "rust-analyzer" ] } } }
Python (pyright)
Install pyright: npm install -g pyright
Configure your MCP client: This will be different but similar for each client. For Claude Desktop, add the following to ~/Library/Application\ Support/Claude/claude_desktop_config.json
{ "mcpServers": { "language-server": { "command": "mcp-language-server", "args": [ "--workspace", "/Users/you/dev/yourproject/", "--lsp", "pyright-langserver", "--", "--stdio" ] } } }
Typescript (typescript-language-server)
Install typescript-language-server: npm install -g typescript typescript-language-server
Configure your MCP client: This will be different but similar for each client. For Claude Desktop, add the following to ~/Library/Application\ Support/Claude/claude_desktop_config.json
{ "mcpServers": { "language-server": { "command": "mcp-language-server", "args": [ "--workspace", "/Users/you/dev/yourproject/", "--lsp", "typescript-language-server", "--", "--stdio" ] } } }
C/C++ (clangd)
Install clangd: Download prebuilt binaries from the official LLVM releases page or install via your system's package manager (e.g., apt install clangd, brew install clangd).
Configure your MCP client: This will be different but similar for each client. For Claude Desktop, add the following to ~/Library/Application\\ Support/Claude/claude_desktop_config.json
{ "mcpServers": { "language-server": { "command": "mcp-language-server", "args": [ "--workspace", "/Users/you/dev/yourproject/", "--lsp", "/path/to/your/clangd_binary", "--", "--compile-commands-dir=/path/to/yourproject/build_or_compile_commands_dir" ] } } }
Note:
Replace /path/to/your/clangd_binary with the actual path to your clangd executable.
--compile-commands-dir should point to the directory containing your compile_commands.json file (e.g., ./build, ./cmake-build-debug).
Ensure compile_commands.json is generated for your project for clangd to work effectively.
Other
I have only tested this repo with the servers above but it should be compatible with many more. Note:
The language server must communicate over stdio.
Any aruments after -- are sent as arguments to the language server.
Any env variables are passed on to the language server.
工具
definition:从代码库中检索任何符号(函数、类型、常量等)的完整源代码定义。references:在整个代码库中查找符号的所有用法和引用。diagnostics:提供特定文件的诊断信息,包括警告和错误。hover:显示给定位置的文档、键入提示或其他悬停信息。rename_symbol:重命名项目中的符号。edit_file:允许根据行号对文件进行多次文本编辑。与基于搜索和替换的编辑工具相比,提供了一种更可靠、更经济的编辑文件的方法。
关于
此代码库使用来自的编辑代码 gopls 以处理LSP通信。详细信息请参见属性。这里的所有内容都包含在宽松的BSD风格许可证中。
mcp走 用于MCP通信。谢谢你的服务。
这是测试版软件。如果您遇到任何问题或有任何建议,请通过创建问题告诉我。
贡献
对于任何实质性的问题,请先保持PR的小规模和开放性。只要经过测试,通过检查,气味不太难闻,人工智能就可以。
设置
克隆仓库:
git clone https://github.com/isaacphi/mcp-language-server.git
cd mcp-language-serverA. justfile 为方便起见,包括:
just -l
Available recipes:
build # Build
check # Run code audit checks
fmt # Format code
generate # Generate LSP types and methods
help # Help
install # Install locally
snapshot # Update snapshot tests
test # Run tests配置您的Claude Desktop(或类似设备)以使用本地二进制文件:
{
"mcpServers": {
"language-server": {
"command": "/full/path/to/your/clone/mcp-language-server/mcp-language-server",
"args": [
"--workspace",
"/path/to/workspace",
"--lsp",
"language-server-executable"
],
"env": {
"LOG_LEVEL": "DEBUG"
}
}
}
}更改后重建。
日志记录
设置 LOG_LEVEL DEBUG的环境变量允许将所有组件的详细日志记录到stderr,包括往返于语言服务器的消息和语言服务器的日志。
LSP交互
internal/lsp/methods.go包含用于调用连接的语言服务器的生成代码。internal/protocol/tsprotocol.go包含LSP类型的生成代码。这是我借的gopls的源代码。谢谢你的服务。- LSP允许语言服务器为相同的方法返回不同的类型。Go不喜欢这样,所以有一些丑陋的解决方法
internal/protocol/interfaces.go.
本地开发和快照测试
有一个快照测试套件,可以更容易地尝试对工具进行更改。这些程序在模拟工作区上运行实际的语言服务器,并捕获输出和日志。
您需要在本地安装语言服务器才能运行它们。有go、rust、python和typescript的测试。
integrationtests/
├── tests/ # Tests are in this folder
├── snapshots/ # Snapshots of tool outputs
├── test-output/ # Gitignored folder showing the final state of each workspace and logs after each test run
└── workspaces/ # Mock workspaces that the tools run on要更新快照,请运行 UPDATE_SNAPSHOTS=true go test ./integrationtests/...
