LSP MCP Server
About
Integrates with Language Server Protocol (LSP) to provide features like code completion, diagnostics, and hover information.
Details
- Author
- tritlo
- Categories
- Developer Tools
Jump to
Setup
Install LSP MCP Server in your MCP client (Claude Desktop, Cursor, Windsurf, and others).
Repository: https://github.com/tritlo/lsp-mcp
Follow the installation instructions in the repository README, then restart your MCP client.
An MCP (Model Context Protocol) server for interacting with LSP (Language Server Protocol) interface. This server acts as a bridge that allows LLMs to query LSP Hover and Completion providers.
- Starting an LSP client that connects to a LSP server
- Exposing MCP tools that send requests to the LSP server
- Returning the results in a format that LLMs can understand and use
This enables LLMs to utilize LSPs for more accurate code suggestions.
{ "mcpServers": { "lsp-mcp": { "type": "stdio", "command": "npx", "args": [ "tritlo/lsp-mcp", "<language-id>", "<path-to-lsp>", "<lsp-args>" ] } } }
- get_info_on_location: Get hover information at a specific location in a file
- get_completions: Get completion suggestions at a specific location in a file
- get_code_actions: Get code actions for a specific range in a file
- open_document: Open a file in the LSP server for analysis
- close_document: Close a file in the LSP server
- get_diagnostics: Get diagnostic messages (errors, warnings) for open files
- start_lsp: Start the LSP server with a specified root directory
- restart_lsp_server: Restart the LSP server without restarting the MCP server
- set_log_level: Change the server's logging verbosity level at runtime
- lsp-diagnostics://resources for accessing diagnostic messages with real-time updates via subscriptions
- lsp-hover://resources for retrieving hover information at specific file locations
- lsp-completions://resources for getting code completion suggestions at specific positions
- Comprehensive logging system with multiple severity levels
- Colorized console output for better readability
- Runtime-configurable log level
- Detailed error handling and reporting
- Simple command-line interface
- GHC (8.10 or later)
- Cabal (3.0 or later)
git clone https://github.com/your-username/lsp-mcp.git cd lsp-mcp
The project includes integration tests for the TypeScript LSP support. These tests verify that the LSP-MCP server correctly handles LSP operations like hover information, completions, diagnostics, and code actions.
The tests verify the following functionality:
- Initializing the TypeScript LSP with a mock project
- Opening TypeScript files for analysis
- Getting hover information for functions and types
- Getting code completion suggestions
- Getting diagnostic error messages
- Getting code actions for errors
The test project is located intest/ts-project/and contains TypeScript files with intentional errors to test diagnostic feedback.
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...]
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 thestart_lsptool before using any LSP functionality. This ensures proper initialization with the correct root directory, which is especially important when using tools like npx:
{ "tool": "start_lsp", "arguments": { "root_dir": "/path/to/your/project" } }
The server includes a comprehensive logging system with 8 severity levels:
- debug: Detailed information for debugging purposes
- info: General informational messages about system operation
- notice: Significant operational events
- warning: Potential issues that might need attention
- error: Error conditions that affect operation but don't halt the system
- critical: Critical conditions requiring immediate attention
- alert: System is in an unstable state
- emergency: System is unusable
- Console output with color-coding for better readability
- MCP notifications to the client (via thenotifications/messagemethod)
-
Use theclaude --mcp-debugflag when running Claude to see all MCP traffic between Claude and the server:
Change the log level at runtime using theset_log_leveltool:
{ "tool": "set_log_level", "arguments": { "level": "debug" } }
The default log level isinfo, which shows moderate operational detail while filtering out verbose debug messages.
The server provides the following MCP tools:
Gets hover information at a specific location in a file.
- file_path: Path to the file
- language_id: The programming language the file is written in (e.g., "haskell")
- line: Line number
- column: Column position
{ "tool": "get_info_on_location", "arguments": { "file_path": "/path/to/your/file", "language_id": "haskell", "line": 3, "column": 5 } }
Gets completion suggestions at a specific location in a file.
- file_path: Path to the file
- language_id: The programming language the file is written in (e.g., "haskell")
- line: Line number
- column: Column position
{ "tool": "get_completions", "arguments": { "file_path": "/path/to/your/file", "language_id": "haskell", "line": 3, "column": 10 } }
Gets code actions for a specific range in a file.
- file_path: Path to the file
- language_id: The programming language the file is written in (e.g., "haskell")
- start_line: Start line number
- start_column: Start column position
- end_line: End line number
- end_column: End column position
{ "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 } }
Starts the LSP server with a specified root directory. This must be called before using any other LSP-related tools.
- root_dir: The root directory for the LSP server (absolute path recommended)
{ "tool": "start_lsp", "arguments": { "root_dir": "/path/to/your/project" } }
Restarts the LSP server process without restarting the MCP server. This is useful for recovering from LSP server issues or for applying changes to the LSP server configuration.
- root_dir: (Optional) The root directory for the LSP server. If provided, the server will be initialized with this directory after restart.
Example without root_dir (uses previously set root directory):
{ "tool": "restart_lsp_server", "arguments": {} }
{ "tool": "restart_lsp_server", "arguments": { "root_dir": "/path/to/your/project" } }
Opens a file in the LSP server for analysis. This must be called before accessing diagnostics or performing other operations on the file.
- file_path: Path to the file to open
- language_id: The programming language the file is written in (e.g., "haskell")
{ "tool": "open_document", "arguments": { "file_path": "/path/to/your/file", "language_id": "haskell" } }
Closes a file in the LSP server when you're done working with it. This helps manage resources and cleanup.
{ "tool": "close_document", "arguments": { "file_path": "/path/to/your/file" } }
Gets diagnostic messages (errors, warnings) for one or all open files.
- file_path: (Optional) Path to the file to get diagnostics for. If not provided, returns diagnostics for all open files.
{ "tool": "get_diagnostics", "arguments": { "file_path": "/path/to/your/file" } }
{ "tool": "get_diagnostics", "arguments": {} }
Sets the server's logging level to control verbosity of log messages.
- level: The logging level to set. One of:debug,info,notice,warning,error,critical,alert,emergency.
{ "tool": "set_log_level", "arguments": { "level": "debug" } }
In addition to tools, the server provides resources for accessing LSP features including diagnostics, hover information, and code completions:
- lsp-diagnostics://- Diagnostics for all open files
- lsp-diagnostics:///path/to/file- Diagnostics for a specific file
Important: Files must be opened using theopen_documenttool before diagnostics can be accessed.
The server exposes hover information via thelsp-hover://resource scheme. This allows you to get information about code elements at specific positions in files.
lsp-hover:///path/to/file?line={line}&column={column}&language_id={language_id}
- line: Line number (1-based)
- column: Column position (1-based)
- language_id: The programming language (e.g., "haskell")
lsp-hover:///home/user/project/src/Main.hs?line=42&column=10&language_id=haskell
The server exposes code completion suggestions via thelsp-completions://resource scheme. This allows you to get completion candidates at specific positions in files.
lsp-completions:///path/to/file?line={line}&column={column}&language_id={language_id}
- line: Line number (1-based)
- column: Column position (1-based)
- language_id: The programming language (e.g., "haskell")
lsp-completions:///home/user/project/src/Main.hs?line=42&column=10&language_id=haskell
To discover available resources, use the MCPresources/listendpoint. The response will include all available resources for currently open files, including:
- Diagnostics resources for all open files
- Hover information templates for all open files
- Code completion templates for all open files
Note: Hover and completion resources don't support subscriptions as they represent point-in-time queries.
You can choose between two approaches for accessing LSP features:
- Tool-based approach: Use theget_diagnostics,get_info_on_location, andget_completionstools for a simple, direct way to fetch information.
- Resource-based approach: Use thelsp-diagnostics://,lsp-hover://, andlsp-completions://resources for a more RESTful approach.
Both approaches provide the same data in the same format and enforce the same requirement that files must be opened first.
- If the server fails to start, make sure the path to the LSP executable is correct
- Check the log file (if configured) for detailed error messages
The LSP-MCP server supports language-specific extensions that enhance its capabilities for different programming languages. Extensions can provide:
- Custom LSP-specific tools and functionality
- Language-specific resource handlers and templates
- Specialized prompts for language-related tasks
- Custom subscription handlers for real-time data
Currently, the following extensions are available:
- Haskell: Provides specialized prompts for Haskell development, including typed-hole exploration guidance
Extensions are loaded automatically when you specify a language ID when starting the server:
npx tritlo/lsp-mcp haskell /path/to/haskell-language-server-wrapper lsp
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.





