基于 LSAP (Language Server Agent Protocol) 的 MCP (Model Context Protocol) 服务器实现。
LSP-MCP 将底层的 Language Server Protocol (LSP) 能力转换为高级的、对 AI 代理友好的认知工具。它通过 LSAP 协议层,将原子化的 LSP 操作组合成语义化的接口。
- 定义导航: 查找符号的定义、声明或类型定义
- 引用查找: 查找符号的所有引用或实现
- 文件大纲: 获取文件的结构化大纲,显示所有符号
- 悬停信息: 获取符号的悬停信息和文档
- 工作区搜索: 在整个工作区中搜索符号
# 克隆仓库
git clone https://github.com/lsp-client/lsp-mcp.git
cd lsp-mcp
# 安装依赖(使用 uv)
uv sync
# 或使用 pip
pip install -e .LSP-MCP 服务器会自动检测当前工作目录中的项目类型并初始化相应的 LSP 客户端。只需在项目根目录下启动服务器:
cd /path/to/your/project
python main.py服务器会自动识别以下项目类型:
- Python: 查找
pyproject.toml,setup.py等 - TypeScript/JavaScript: 查找
package.json,tsconfig.json等 - Rust: 查找
Cargo.toml - Go: 查找
go.mod
get_definition(
file_path="src/models.py",
symbol_name="User.validate",
mode="definition", # "definition", "declaration", "type_definition"
include_code=True
)find_references(
file_path="src/models.py",
symbol_name="User.validate",
mode="references", # "references" or "implementations"
max_items=20,
context_lines=3
)get_outline(
file_path="src/models.py"
)get_hover_info(
file_path="src/main.py",
symbol_name="process_data"
)search_workspace(
query="User",
file_pattern="*.py",
max_items=20
)# LSP 客户端在服务器启动时自动初始化
# 确保在项目根目录下启动服务器
# 1. 获取文件大纲
outline = get_outline(file_path="src/models.py")
# 2. 查找符号定义
definition = get_definition(
file_path="src/main.py",
symbol_name="User",
mode="definition"
)
# 3. 查找所有引用
references = find_references(
file_path="src/models.py",
symbol_name="User.validate",
mode="references",
max_items=50
)
# 4. 搜索工作区
results = search_workspace(query="User", max_items=20)运行测试:
# 运行所有测试
pytest
# 运行特定测试文件
pytest tests/test_basic.py -v┌─────────────────┐
│ AI Agent │
│ (MCP Client) │
└────────┬────────┘
│ MCP Protocol
│
┌────────▼────────┐
│ LSP-MCP Server │
│ (FastMCP) │
└────────┬────────┘
│
┌────────▼────────┐
│ LSAP Layer │
│ (lsap-sdk) │
└────────┬────────┘
│ LSP Protocol
│
┌────────▼────────┐
│ Language Server │
│ (pyright, etc) │
└─────────────────┘
- MCP: Model Context Protocol - AI 代理通信协议
- LSAP: Language Server Agent Protocol - LSP 的高级抽象层
- LSP: Language Server Protocol - 代码分析和导航协议
- Python 3.13+: 主要编程语言
- FastMCP: 快速 MCP 服务器框架
- lsap-sdk: LSAP 协议 Python SDK
- LSAP - Language Server Agent Protocol
- lsp-client - Python LSP 客户端库
- Model Context Protocol - MCP 协议规范
MIT License - 详见 LICENSE 文件
欢迎贡献!请查看 LSAP 贡献指南。