lsp-mcp

lsp-mcp

An MCP server that exposes LSP-backed code navigation and editing tools to LLM agents using a single global config file to route file extensions to language servers.

Category
访问服务器

README

lsp-mcp

An MCP server that exposes LSP-backed code navigation and editing tools to LLM agents. Uses a single global config file to route any file extension to any language server(s) — no per-project configuration required.

Why

Serena is excellent but requires per-project .serena/ files to control which language server each project uses. lsp-mcp lets you define the policy once at ~/.config/lsp-mcp/config.yml and apply it to any project — including ones you don't own.

Installation

With uvx (recommended — no install needed)

uvx lsp-mcp --help

With uv run

git clone https://github.com/AFriemann/lsp-mcp
uv run --project /path/to/lsp-mcp lsp-mcp

Configuration

Create ~/.config/lsp-mcp/config.yml (or $XDG_CONFIG_HOME/lsp-mcp/config.yml):

servers:
  # Declare every language server you want to use.
  # command: list of tokens (no shell quoting needed).
  ty:
    command: [uvx, ty, server]

  ruff:
    command: [ruff, server]

  typescript-language-server:
    command: [npx, typescript-language-server, --stdio]

  gopls:
    command: [gopls]

file_handlers:
  # Map glob patterns to ordered lists of servers.
  # Navigation tools: first server returning a non-empty result wins.
  # Diagnostics: results from all servers are merged.
  "*.py":
    - server: ty          # type checker — first priority
    - server: ruff        # linter — second priority (also provides diagnostics)

  "*.ts":
    - server: typescript-language-server

  "*.js":
    - server: typescript-language-server

  "*.go":
    - server: gopls

Pattern matching

  • *.ext — matched against the basename only (e.g. *.py matches any .py file in any directory).
  • src/*.py — matched against the full path (use for path-style filtering).
  • Multiple handlers for the same pattern are concatenated in order; duplicates are removed by first occurrence.

Server binaries

Binaries are resolved lazily at server start time. A missing binary degrades just that one server — the others still work.

Adding to opencode

In your ~/.config/opencode/opencode.jsonc:

{
  "mcp": {
    "lsp-mcp": {
      "type": "local",
      "command": "uvx",
      "args": ["lsp-mcp"]
    }
  }
}

Or with a local clone:

{
  "mcp": {
    "lsp-mcp": {
      "type": "local",
      "command": "uv",
      "args": ["run", "--project", "/home/you/git/lsp-mcp", "lsp-mcp"]
    }
  }
}

Tools

All eight tools accept absolute file paths. Symbol names may be bare (my_func) or name-paths (MyClass/my_method) for nested symbols.

Tool Description LSP method
get_symbols_overview List all symbols in a file textDocument/documentSymbol
find_symbol Search for a symbol by name across the workspace workspace/symbol
find_declaration Find where a symbol is defined textDocument/definition
find_implementations Find implementations of an interface/abstract method textDocument/implementation
find_referencing_symbols Find all references to a symbol textDocument/references
replace_symbol_body Replace a symbol's source text in-place textDocument/documentSymbol + on-disk edit
rename_symbol Rename a symbol across the workspace textDocument/rename
get_diagnostics_for_file Get merged diagnostics from all configured servers textDocument/diagnostic (pull) or publishDiagnostics (push)

Tool parameters

get_symbols_overview(file_path)

  • file_path: absolute path to the source file

find_symbol(query, file_path="")

  • query: symbol name substring to search for
  • file_path: optional context file (selects which servers to query)

find_declaration(symbol, file_path)

  • symbol: bare name or name-path (MyClass/my_method)
  • file_path: absolute path to the file containing the symbol

find_implementations(symbol, file_path) — same parameters as find_declaration

find_referencing_symbols(symbol, file_path) — same parameters as find_declaration

replace_symbol_body(symbol, new_body, file_path)

  • symbol: bare name or name-path
  • new_body: full replacement source text (including the signature line)
  • file_path: absolute path to the file

rename_symbol(symbol, new_name, file_path)

  • symbol: bare name or name-path
  • new_name: new identifier
  • file_path: absolute path to the file

get_diagnostics_for_file(file_path)

  • file_path: absolute path to the source file

Response shape

Every tool returns a JSON object with:

  • The result data (symbols, locations, diagnostics, changed_files, success)
  • note: explanatory string when no result was found or no capable server is configured
  • warnings: list of non-fatal per-server error messages

Architecture

Five layers:

lsp_mcp/
  __main__.py        # CLI entry point
  server.py          # FastMCP app + 8 tool adapters
  types.py           # Shared response models
  dispatch/          # Routing (first-wins / merge), symbol resolution, edits
  lsp/               # GenericLanguageServer, ServerManager pool, capabilities
  config/            # Config loading, validation, glob resolver
  • Config defines the routing policy. One global file, no per-project files.
  • ServerManager maintains a persistent pool of running server processes keyed by (server_name, project_root). Servers start on demand, are reused across calls, and are idle-evicted after 15 minutes.
  • GenericLanguageServer subclasses multilspy's LanguageServer to launch any arbitrary command.
  • Dispatcher routes each tool call: resolves the file's matching servers, filters by capability, applies first-wins or merge semantics.
  • Edits apply on-disk changes with UTF-16-correct offset handling and notify open servers via didChange.

Development

git clone https://github.com/AFriemann/lsp-mcp
cd lsp-mcp
uv sync
uv run pytest

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选