The LSP MCP Server is a powerful tool that enables interaction between Language Server Protocol (LSP) servers and Large Language Models (LLMs). By acting as a bridge, it allows LLMs to query LSP hover and completion providers, enhancing code suggestions and analysis capabilities.
The LSP MCP Server works by:
This integration empowers LLMs to leverage LSPs for more accurate and context-aware code suggestions.
To configure the LSP MCP Server, use the following JSON structure:
{
"mcpServers": {
"lsp-mcp": {
"type": "stdio",
"command": "npx",
"args": [
"tritlo/lsp-mcp",
"<language-id>",
"<path-to-lsp>",
"<lsp-args>"
]
}
}
}
get_info_on_location
: Retrieves hover information at a specific file location.get_completions
: Fetches completion suggestions at a specific file location.get_code_actions
: Retrieves code actions for a specific range in a file.open_document
: Opens a file in the LSP server for analysis.close_document
: Closes a file in the LSP server.get_diagnostics
: Retrieves diagnostic messages (errors, warnings) for open files.start_lsp
: Starts the LSP server with a specified root directory.restart_lsp_server
: Restarts the LSP server without restarting the MCP server.set_log_level
: Changes the server's logging verbosity level at runtime.lsp-diagnostics://
: Access diagnostic messages with real-time updates via subscriptions.lsp-hover://
: Retrieve hover information at specific file locations.lsp-completions://
: Get code completion suggestions at specific positions.For the demo server:
Clone the repository:
bash
git clone https://github.com/your-username/lsp-mcp.git
cd lsp-mcp
Install dependencies:
bash
npm install
Build the MCP server:
bash
npm run build
The project includes integration tests for TypeScript LSP support. These tests verify LSP operations like hover information, completions, diagnostics, and code actions.
To run the TypeScript LSP tests:
npm test
or specifically:
npm run test:typescript
Tests verify the following functionality:
Run the MCP server by providing the path to the LSP executable and any arguments to pass to the LSP server:
npx tritlo/lsp-mcp <language> /path/to/lsp [lsp-args...]
For example:
npx tritlo/lsp-mcp haskell /usr/bin/haskell-language-server-wrapper lsp
With version 0.2.0 and later, you must explicitly start the LSP server by calling the start_lsp
tool before using any LSP functionality:
{
"tool": "start_lsp",
"arguments": {
"root_dir": "/path/to/your/project"
}
}
The server includes a comprehensive logging system with 8 severity levels:
debug
info
notice
warning
error
critical
alert
emergency
By default, logs are sent to:
notifications/message
method).For detailed debugging, you can:
Use the claude --mcp-debug
flag when running Claude:
bash
claude --mcp-debug
Change the log level at runtime using the set_log_level
tool:
json
{
"tool": "set_log_level",
"arguments": {
"level": "debug"
}
}
The server provides the following MCP tools:
get_info_on_location
Retrieves hover information at a specific location in a file.
{
"tool": "get_info_on_location",
"arguments": {
"file_path": "/path/to/your/file",
"language_id": "haskell",
"line": 3,
"column": 5
}
}
get_completions
Retrieves completion suggestions at a specific location in a file.
{
"tool": "get_completions",
"arguments": {
"file_path": "/path/to/your/file",
"language_id": "haskell",
"line": 3,
"column": 10
}
}
get_code_actions
Retrieves code actions for a specific range in a file.
{
"tool": "get_code_actions",
"arguments": {
"file_path": "/path/to/your/file",
"language_id": "haskell",
"start_line": 3,
"start_column": 5,
"end_line": 3,
"end_column": 10
}
}
start_lsp
Starts the LSP server with a specified root directory.
{
"tool": "start_lsp",
"arguments": {
"root_dir": "/path/to/your/project"
}
}
restart_lsp_server
Restarts the LSP server process without restarting the MCP server.
{
"tool": "restart_lsp_server",
"arguments": {
"root_dir": "/path/to/your/project"
}
}
open_document
Opens a file in the LSP server for analysis.
{
"tool": "open_document",
"arguments": {
"file_path": "/path/to/your/file",
"language_id": "haskell"
}
}
close_document
Closes a file in the LSP server.
{
"tool": "close_document",
"arguments": {
"file_path": "/path/to/your/file"
}
}
get_diagnostics
Retrieves diagnostic messages for one or all open files.
{
"tool": "get_diagnostics",
"arguments": {
"file_path": "/path/to/your/file"
}
}
set_log_level
Sets the server's logging level.
{
"tool": "set_log_level",
"arguments": {
"level": "debug"
}
}
Access diagnostic information via the lsp-diagnostics://
resource scheme.
Access hover information via the lsp-hover://
resource scheme.
Access code completion suggestions via the lsp-completions://
resource scheme.
Use the MCP resources/list
endpoint to discover available resources.
Diagnostic resources support subscriptions for real-time updates.
MIT License
The LSP-MCP server supports language-specific extensions that enhance its capabilities for different programming languages.
Extensions are loaded automatically when you specify a language ID when starting the server.
To create a new extension:
src/extensions/
.An MCP server that lets you interact with LSP servers.