MC

MCP Server: LSP Hover, Code Actions, Completions

**Calculating character counts**

Quick Install
npx -y @Tritlo/lsp-mcp

Overview

The MCP (Model Context Protocol) server lsp-mcp is a bridge between large language models (LLMs) and Language Server Protocol (LSP) servers. It exposes LSP functionality—hover information, completions, diagnostics and code actions—through MCP tools and resources so an LLM or other MCP-capable client can query code-aware language features programmatically.

lsp-mcp runs an LSP client process, forwards structured requests to the connected LSP server, and translates responses into MCP-friendly JSON results and resources. This lets LLM agents query precise, editor-grade information (type info, signatures, diagnostics, completion lists) without implementing LSP themselves. It is useful for assistants that need accurate context about source files to produce or validate code suggestions.

Features

  • Start and manage an LSP server from MCP (start / restart)
  • Open/close documents in the LSP and keep them synchronized
  • Hover lookups: rich hover contents and Markdown rendering
  • Completions: completion lists, insertText, and documentation
  • Code actions: quick fixes and refactors for a given range
  • Diagnostics: live error/warning reports for open files
  • Runtime-controllable log level and colorized console output
  • LSP-backed MCP resources:
    • lsp-diagnostics://
    • lsp-hover://
    • lsp-completions://

Installation / Configuration

Prerequisites:

  • Node.js v16+ and npm

Get the source:

git clone https://github.com/Tritlo/lsp-mcp.git
cd lsp-mcp
npm install
npm run build

Run via npx (example):

npx tritlo/lsp-mcp <language-id> /path/to/lsp-server [lsp-args...]
# example: npx tritlo/lsp-mcp haskell /usr/bin/haskell-language-server-wrapper lsp

Configure an MCP server entry (example for an MCP-capable client):

{
  "mcpServers": {
    "lsp-mcp": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "tritlo/lsp-mcp",
        "typescript",
        "/usr/bin/typescript-language-server",
        "--stdio"
      ]
    }
  }
}

Important: call the start_lsp tool before other LSP operations to set the root directory and initialize the LSP server:

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

Available Tools

Below is a quick reference for the main MCP tools exposed by the server.

Tool namePurposeKey arguments
start_lspStart the LSP server with a project rootroot_dir
restart_lsp_serverRestart the LSP without stopping the MCP process(none) or optional restart args
open_documentNotify LSP of an opened filefile_path, language_id, text
close_documentClose a file in the LSPfile_path
get_info_on_locationHover/tooltip at a positionfile_path, language_id, line, column
get_completionsCompletion suggestions at a positionfile_path, language_id, line, column
get_code_actionsCode actions for a rangefile_path, language_id, start/end line/column
get_diagnosticsGet diagnostics for open filesoptional file_path filter
set_log_levelChange runtime logging levellevel (debug/info/warning/…)

Examples (MCP request bodies):

Get hover information:

{
  "tool": "get_info_on_location",
  "arguments": {
    "file_path": "/project/src/example.ts",
    "language_id": "typescript",
    "line": 12,
    "column": 8
  }
}

Get completions:

{
  "tool": "get_completions",
  "arguments": {
    "file_path": "/project/src/example.ts",
    "language_id": "typescript",
    "line": 20,
    "column": 5
  }
}

Resources

The server exposes MCP resource URIs that update with server state and can be subscribed to:

  • lsp-diagnostics://{root}/{file} — subscribe to diagnostic updates for a file
  • lsp-hover://{root}/{file}:{line}:{col} — fetch hover content at a location
  • lsp-completions://{root}/{file}:{line}:{col} — fetch completion lists

These resources follow MCP resource conventions and are suitable for persistent subscriptions from an LLM client.

Use Cases

  1. Automated code suggestion assistant

    • Start the LSP for a project, open the target file, and request hover/completions before generating code. Use diagnostics to avoid suggesting fixes that conflict with existing errors.
  2. Context-aware commit message or PR assistant

    • Query hover and types around changed lines to produce accurate explanations of code changes. Use code actions to suggest automated refactors and present them as patch suggestions.
  3. Batch code review tooling

    • Use diagnostics and code actions across multiple files to surface recurring issues and mass-apply fixes programmatically via the LSP.

Logging & Debugging

  • Default log level: info
  • Change at runtime with set_log_level tool
  • For verbose trace of MCP traffic, enable client-side MCP debugging (e.g., the claude –mcp-debug flag if your client supports it).

Repository and source: https://github.com/Tritlo/lsp-mcp

For tests and examples, see the repository’s test folder (TypeScript project examples and integration tests).