多语言LSP协议服务

LSP MCP Server是一个提供统一访问多种编程语言的Language Server Protocol功能的服务器,支持Rust、TypeScript/JavaScript、Python、Go、C/C++等语言。

  • by johnhnguyen97
  • Rust
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 johnhnguyen97/lsp-mcp

使用说明

LSP MCP服务器

一种MCP(模型上下文协议)服务器,为多种编程语言提供对语言服务器协议功能的统一访问。

特性

  • 多语言支持:Rust、Types/JavaScript、Python、Go、C/C++
  • 完整的IDE功能 作为MCP工具公开:
    • lsp_hover -类型信息和文件
    • lsp_goto_definition -导航到符号定义
    • lsp_find_references -查找符号的所有用法
    • lsp_completion -代码完成建议
    • lsp_document_symbols -列出文件中的符号
    • lsp_workspace_symbols -跨工作区搜索符号
    • lsp_rename_symbol -跨文件重命名符号
    • lsp_diagnostics -获取错误和警告

先决条件

必须安装语言服务器并在PATH中可用:

语言 服务器 安装
锈蚀 锈蚀分析仪 rustup component add rust-analyzer
TypeScript/JS TypeScript语言服务器 npm i -g typescript-language-server typescript
Python 版权 npm i -g pyright 或 pip install pyright
Go gopls go install golang.org/x/tools/gopls@latest
C/C++ cland 通过系统包管理器安装

安装

cargo install --path .

用法

作为MCP服务器

添加到MCP客户端配置中:

{
  "mcpServers": {
    "lsp": {
      "command": "lsp-mcp"
    }
  }
}

工具示例

1.首先激活工作区:

{
  "tool": "lsp_activate_workspace",
  "arguments": {
    "workspace_path": "C:/path/to/project"
  }
}

2.获取悬停信息:

{
  "tool": "lsp_hover",
  "arguments": {
    "file_path": "C:/path/to/project/src/main.rs",
    "line": 10,
    "character": 5
  }
}

3.查找定义:

{
  "tool": "lsp_goto_definition",
  "arguments": {
    "file_path": "C:/path/to/project/src/main.rs",
    "line": 15,
    "character": 12
  }
}

4.查找参考文献:

{
  "tool": "lsp_find_references",
  "arguments": {
    "file_path": "C:/path/to/project/src/main.rs",
    "line": 5,
    "character": 7,
    "include_declaration": true
  }
}

发展

# Build
cargo build

# Run in development
cargo run

# Run tests
cargo test

# Build release
cargo build --release

建筑

lsp-mcp/
├── src/
│   ├── main.rs           # Entry point
│   ├── lib.rs            # Public API
│   ├── error.rs          # Error types
│   ├── server/           # MCP server
│   │   └── mcp_server.rs # Tool registration
│   ├── lsp/              # LSP client layer
│   │   ├── client.rs     # LSP client wrapper
│   │   ├── manager.rs    # Multi-server manager
│   │   ├── config.rs     # Server configurations
│   │   └── transport.rs  # Stdio transport
│   └── tools/            # MCP tools
│       ├── workspace.rs  # Workspace management
│       ├── hover.rs      # Hover info
│       ├── definition.rs # Go to definition
│       └── ...           # Other tools

许可证

麻省理工学院