Skip to content

lsp-client/lsp-mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LSP-MCP Server

基于 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 .

使用方法

作为 MCP 服务器运行

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

可用工具

1. 获取定义

get_definition(
    file_path="src/models.py",
    symbol_name="User.validate",
    mode="definition",  # "definition", "declaration", "type_definition"
    include_code=True
)

3. 查找引用

find_references(
    file_path="src/models.py",
    symbol_name="User.validate",
    mode="references",  # "references" or "implementations"
    max_items=20,
    context_lines=3
)

4. 获取文件大纲

get_outline(
    file_path="src/models.py"
)

5. 获取悬停信息

get_hover_info(
    file_path="src/main.py",
    symbol_name="process_data"
)

6. 搜索工作区

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

相关项目

许可证

MIT License - 详见 LICENSE 文件

贡献

欢迎贡献!请查看 LSAP 贡献指南

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages