LSP MCP server

Bridges Language Server Protocol (LSP) servers with code intelligence features like hover information, completions, and diagnostics for accurate code suggestions across multiple programming languages.
Back to servers
Provider
Matthias Pall Gissurarson
Release date
Mar 22, 2025
Language
TypeScript
Stats
42 stars

The LSP MCP Server acts as a bridge between Language Server Protocol (LSP) servers and Large Language Models. It allows LLMs to access LSP features like hover information, code completions, and diagnostics for more accurate code suggestions and insights.

Installation

Prerequisites

  • Node.js (v16 or later)
  • npm
  • For specific language support, appropriate LSP servers must be installed

Setup Instructions

  1. Install the package using npx:
npx tritlo/lsp-mcp <language-id> <path-to-lsp> <lsp-args>

For example, to use with Haskell:

npx tritlo/lsp-mcp haskell /usr/bin/haskell-language-server-wrapper lsp

Configuration

If you're integrating with an MCP-compatible application, configure it to use the LSP-MCP server:

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

Usage

Getting Started

After starting the server, you must explicitly initialize the LSP connection with the start_lsp tool:

{
  "tool": "start_lsp",
  "arguments": {
    "root_dir": "/path/to/your/project"
  }
}

Opening Files

Before performing any operations on a file, you need to open it in the LSP server:

{
  "tool": "open_document",
  "arguments": {
    "file_path": "/path/to/your/file",
    "language_id": "haskell"
  }
}

Available Tools

Getting Hover Information

Retrieve details about code at a specific location:

{
  "tool": "get_info_on_location",
  "arguments": {
    "file_path": "/path/to/your/file",
    "language_id": "haskell",
    "line": 3,
    "column": 5
  }
}

Getting Code Completions

Get suggestions while typing:

{
  "tool": "get_completions",
  "arguments": {
    "file_path": "/path/to/your/file",
    "language_id": "haskell",
    "line": 3,
    "column": 10
  }
}

Getting Code Actions

Retrieve possible actions for fixing issues or refactoring:

{
  "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
  }
}

Getting Diagnostics

Retrieve errors and warnings for files:

{
  "tool": "get_diagnostics",
  "arguments": {
    "file_path": "/path/to/your/file"
  }
}

For all open files:

{
  "tool": "get_diagnostics",
  "arguments": {}
}

Closing Documents

Close files when you're done working with them:

{
  "tool": "close_document",
  "arguments": {
    "file_path": "/path/to/your/file"
  }
}

Managing the LSP Server

Restart the LSP server when needed:

{
  "tool": "restart_lsp_server",
  "arguments": {
    "root_dir": "/path/to/your/project"
  }
}

Setting Log Level

Control the verbosity of logs:

{
  "tool": "set_log_level",
  "arguments": {
    "level": "debug"
  }
}

Available levels: debug, info, notice, warning, error, critical, alert, emergency.

Resource-based Access

As an alternative to tools, you can also access LSP features through MCP resources:

Diagnostics Resources

Access diagnostics information:

  • For all files: lsp-diagnostics://
  • For a specific file: lsp-diagnostics:///path/to/file

Hover Information Resources

Get information about code elements:

lsp-hover:///path/to/file?line=42&column=10&language_id=haskell

Code Completion Resources

Get completion suggestions:

lsp-completions:///path/to/file?line=42&column=10&language_id=haskell

Troubleshooting

  • Ensure the path to the LSP executable is correct
  • Verify that you've started the LSP server with start_lsp before using other tools
  • Files must be opened with open_document before accessing their diagnostics or other information
  • Check the logs by setting the log level to debug for more detailed information
  • Use restart_lsp_server if the LSP connection becomes unresponsive

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later