Home / MCP / LSP MCP Server

LSP MCP Server

Provides an MCP bridge to LSP hover and completion, enabling LLMs to query and utilize LSP features.

typescript
Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
    "mcpServers": {
        "lsp_mcp": {
            "command": "npx",
            "args": [
                "tritlo/lsp-mcp",
                "<language-id>",
                "<path-to-lsp>",
                "<lsp-args>"
            ]
        }
    }
}

You can run an MCP bridge that talks to an LSP server, exposing tools that let large language models query hover, completions, and related LSP features. This makes code suggestions more accurate by leveraging the LSP capabilities from within an MCP-enabled workflow.

How to use

Start the MCP server with the LSP bridge and then use the MCP tools or resources to fetch hover information, completions, or diagnostics from your LSP server. You can open documents, start and restart the LSP, and adjust logging at runtime. Use the provided MCP tools for direct queries, or access the corresponding lsp- resources for a REST-like approach.

How to install

# Prerequisites
- Node.js (v16 or later)
- npm

# Step 1: Install dependencies for the MCP server project
npm install

# Step 2: Build the MCP server (if a build step is required by the project)
npm run build

# Step 3: Run the MCP server by providing the language ID, LSP path, and any LSP arguments
# Example is for the lsp-mcp bridge; customize <language-id>, <path-to-lsp>, and <lsp-args> as needed
npx tritlo/lsp-mcp <language-id> <path-to-lsp> <lsp-args>

Additional sections

Configuration details are provided below so you can tailor the MCP server to your environment. The server exposes a stdio endpoint that starts an MCP bridge to an LSP server. Use the example command to wire up your language and LSP executable.

Testing and logging are supported. You can start the LSP server, query hover and completion data, and inspect diagnostics to verify that your LSP integration behaves as expected. The server includes a logging system with adjustable verbosity and comprehensive error reporting.

Usage examples show how to trigger hover information and completion suggestions at specific file locations, and how to open or close documents within the LSP server context. You can also restart the LSP server without restarting the MCP bridge.

Available tools

get_info_on_location

Retrieve hover or contextual information for a specific location in a file based on the LSP server.

get_completions

Obtain code completion suggestions at a given line and column in a file via the LSP server.

get_code_actions

Fetch code actions for a selected range in a file to assist with fixes or improvements.

open_document

Open a file in the LSP server to enable analysis and diagnostics.

close_document

Close an opened file in the LSP server to free resources.

get_diagnostics

Query diagnostic messages (errors, warnings) for open files or a specific file.

start_lsp

Start the LSP server with a provided root directory to initialize context.

restart_lsp_server

Restart the LSP server without restarting the MCP bridge.

set_log_level

Change the runtime logging verbosity of the MCP server.