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.
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
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>"
]
}
}
}
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"
}
}
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"
}
}
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
}
}
Get suggestions while typing:
{
"tool": "get_completions",
"arguments": {
"file_path": "/path/to/your/file",
"language_id": "haskell",
"line": 3,
"column": 10
}
}
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
}
}
Retrieve errors and warnings for files:
{
"tool": "get_diagnostics",
"arguments": {
"file_path": "/path/to/your/file"
}
}
For all open files:
{
"tool": "get_diagnostics",
"arguments": {}
}
Close files when you're done working with them:
{
"tool": "close_document",
"arguments": {
"file_path": "/path/to/your/file"
}
}
Restart the LSP server when needed:
{
"tool": "restart_lsp_server",
"arguments": {
"root_dir": "/path/to/your/project"
}
}
Control the verbosity of logs:
{
"tool": "set_log_level",
"arguments": {
"level": "debug"
}
}
Available levels: debug
, info
, notice
, warning
, error
, critical
, alert
, emergency
.
As an alternative to tools, you can also access LSP features through MCP resources:
Access diagnostics information:
lsp-diagnostics://
lsp-diagnostics:///path/to/file
Get information about code elements:
lsp-hover:///path/to/file?line=42&column=10&language_id=haskell
Get completion suggestions:
lsp-completions:///path/to/file?line=42&column=10&language_id=haskell
start_lsp
before using other toolsopen_document
before accessing their diagnostics or other informationdebug
for more detailed informationrestart_lsp_server
if the LSP connection becomes unresponsiveThere 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.
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"
]
}
}
}
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.
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.