LSP MCP Server Bridge for Claude Code
The `lsp-mcp-server` package acts as a crucial intermediary, bridging the gap between AI models like Claude Code (using the Model Context Protocol, MCP) and existing Language Server Protocol (LSP) servers. This enables powerful semantic code intelligence features within AI-powered development environments, including go-to-definition, find references, code completion, diagnostics, and safe renames across 10 different programming languages such as TypeScript/JavaScript, Python, Rust, Go, and Java. It supports multi-root workspaces for monorepos, provides push-based diagnostics, and features automatic language server management. The current stable version is 1.1.15, indicating active development and maintenance. Its key differentiator is providing a robust, configurable, and secure integration layer for AI agents to leverage the rich capabilities of established LSP ecosystems without directly reimplementing language-specific intelligence.
Common errors
-
Error: Cannot find module 'typescript-language-server'
cause The required language server for TypeScript/JavaScript is not installed or not accessible in the system's PATH.fixInstall the `typescript-language-server` globally: `npm install -g typescript-language-server typescript`. For other languages, install their respective language servers as per the `lsp-mcp-server` documentation. -
Error: EACCES: permission denied, open '/var/run/lsp-mcp-server.sock'
cause The `lsp-mcp-server` attempted to create a socket file in a directory where it lacks write permissions, or an existing socket file has incorrect permissions.fixEnsure the directory where the server tries to create its socket (often `/tmp` or a configured `socketDir`) has appropriate write permissions for the user running `lsp-mcp-server`. Alternatively, configure a `socketDir` in a user-writable location in your `lsp-mcp-server` configuration. -
Error: Unsupported language 'mylang' in client configuration.
cause The MCP client (e.g., Claude Code) is requesting a language that is not configured or supported by your `lsp-mcp-server` instance.fixAdd the configuration for 'mylang' to your `lsp-mcp-server` configuration, specifying the command and arguments for its corresponding language server. Ensure the language server itself is installed and functional. -
Error: The 'command' property in your lsp server configuration must be an absolute path: /path/to/my/server.js
cause The `command` specified in the `.mcp.json` for launching the `lsp-mcp-server` is a relative path.fixUpdate the `command` property in your `~/.mcp.json` or project-level `.mcp.json` to use an absolute path, e.g., `"command": "/usr/bin/node"` or `"command": "/home/user/.nvm/versions/node/v18.17.1/bin/node"`.
Warnings
- gotcha The `lsp-mcp-server` requires Node.js version 18.0.0 or higher. Running with older Node.js versions may lead to unexpected errors, compatibility issues, or failures during installation and execution.
- gotcha This package is a bridge and *requires* external language servers (e.g., `typescript-language-server`, `python-lsp-server`, `rust-analyzer`) to be installed and accessible in the system's PATH. Without these, code intelligence features for specific languages will not function.
- gotcha When configuring `lsp-mcp-server` in your MCP client (e.g., Claude Code's `.mcp.json`), the `command` and `args` paths must be absolute. Relative paths will likely cause the MCP client to fail to launch the server correctly.
- gotcha The server automatically manages language servers, including restarting them on crash. However, incorrect configuration (e.g., wrong server executable name, invalid arguments) can lead to language servers continuously crashing and restarting, consuming resources and preventing code intelligence.
- gotcha Security features like file size limits and workspace boundary validation are enabled by default. Large files or attempts to access files outside the designated workspace root might be rejected, leading to incomplete analysis or errors.
Install
-
npm install lsp-mcp-server -
yarn add lsp-mcp-server -
pnpm add lsp-mcp-server
Imports
- startServer
const { startServer } = require('lsp-mcp-server');import { startServer } from 'lsp-mcp-server'; - LspMcpServer
import { LspMcpServer } from 'lsp-mcp-server'; - main
import { main } from 'lsp-mcp-server';
Quickstart
import { startServer } from 'lsp-mcp-server';
// A minimal example showing how to programmatically start the server.
// In a real scenario, this server would typically be launched via a CLI
// command or an external system like Claude Code as configured in ~/.mcp.json.
async function runLspMcpServer() {
console.log('Starting lsp-mcp-server programmatically...');
try {
// In a production setup, command-line arguments would be parsed.
// For this example, we'll simulate a minimal configuration.
// The server listens on stdio by default when launched as a process.
// Programmatic start might require more explicit config or a mock stdio stream.
// The 'main' function typically handles argument parsing.
// For simplicity, we'll just demonstrate importing a function.
// To truly run it, you'd typically execute the built CLI:
// `node dist/index.js --stdio` or `lsp-mcp-server --stdio`
// Example of calling the main CLI entry point programmatically (if configured for direct call):
// await main(); // This would block and expect stdio for LSP/MCP communication
// For demonstration, let's just log and show a conceptual start.
console.log('lsp-mcp-server is designed to be run as a background process, listening on stdio.');
console.log('Refer to the README for installation and configuration with Claude Code.');
console.log('Example command line invocation: lsp-mcp-server --stdio');
// In a realistic scenario, you might do something like this for testing:
// const serverInstance = new LspMcpServer(/* config */);
// await serverInstance.start();
// This quickstart focuses on showing the import, not a fully functional embedded server,
// as its primary use case is CLI-based.
} catch (error) {
console.error('Failed to start lsp-mcp-server:', error);
process.exit(1);
}
}
// To run this script, you would first need to install and build the package:
// npm install && npm run build
// then `node your-script.js`
runLspMcpServer();