mcp-lsp-v1
Provides code intelligence tools for JavaScript projects using the TypeScript language server, including navigation, diagnostics, refactoring, and deep understanding.
Provides code intelligence tools for Python projects using the Pyright language server, including navigation, diagnostics, refactoring, and deep understanding.
Provides code intelligence tools for Rust projects using the rust-analyzer language server, including navigation, diagnostics, refactoring, and deep understanding.
Provides code intelligence tools for TypeScript projects using the TypeScript language server, including navigation, diagnostics, refactoring, and deep understanding.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-lsp-v1 show hover info for 'validateUser' in src/auth.ts"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP LSP — Code Intelligence Server
A Model Context Protocol (MCP) stdio server that wraps language servers to expose a safe, read-oriented code-intelligence tool surface for coding agents. Supports TypeScript, JavaScript, Python, Go, and Rust — 59 tools across navigation, diagnostics, refactoring, deep understanding, hierarchy, lifecycle, and operations.
Table of Contents
Related MCP server: lsp-tools-mcp
Quick Start
# Prerequisites: install language servers
npm install -g typescript-language-server pyright
# Go and Rust: install gopls and rust-analyzer via your package manager
# Clone and install
git clone https://github.com/beruang/lsp-mcp.git
cd lsp-mcp
pnpm install
# Build
pnpm run build
# Point at a workspace and start
WORKSPACE_PATH=/path/to/your/project node dist/index.jsConnect any MCP client to the server's stdio transport.
Prerequisites
Dependency | Version | Purpose |
Node.js | >= 20 | Runtime |
pnpm | — | Package management |
| — | TypeScript/JavaScript LSP backend |
| — | Python LSP backend |
| — | Go LSP backend |
| — | Rust LSP backend |
Language servers must be on $PATH. The server checks availability via lsp_list_supported_languages.
Installation
pnpm installDependencies: @modelcontextprotocol/sdk, vscode-jsonrpc, vscode-languageserver-types, zod, diff.
Configuration
Environment Variables
Variable | Required | Default | Description |
| No |
| Absolute path to the workspace root |
Runtime Config (V4)
Variable | Default | Description |
| 200 | Max references returned |
| 100 | Max workspace symbols |
| 500 | Max diagnostics |
| 50 | Max completion items |
| 100 | Max files in rename preview |
| 1000 | Max edits in workspace edit |
| 20000 | Max context characters |
| 3000 | Hover timeout |
| 5000 | Definition timeout |
| 10000 | References timeout |
| 500 | Request log ring buffer size |
| false | Enable debug raw request tool |
| false | Verbose logging |
Use lsp_get_config to inspect effective configuration and lsp_update_runtime_config to adjust limits, timeouts, cache TTLs, and debug flags at runtime (in-memory only).
Architecture
src/
├── index.ts # Entry point — MCP server bootstrap
├── config/
│ ├── languageServers.ts # Language server registry
│ ├── defaults.ts # Default runtime config values
│ ├── envConfig.ts # Environment variable parsing
│ └── runtimeConfig.ts # In-memory config merge + validation
├── lsp/
│ ├── LspClient.ts # LSP connection: spawn, initialize, request, shutdown
│ ├── LspClientManager.ts # Per-language client pool + state queries
│ ├── LspState.ts # 8-state machine with validated transitions
│ ├── capabilities.ts # Server capabilities extraction
│ ├── diagnosticsCache.ts # publishDiagnostics notification cache
│ ├── documentStore.ts # didOpen/didChange state tracking
│ └── normalize.ts # LSP → normalized shape converters
├── mcp/
│ ├── registerTools.ts # All 59 MCP tool registrations
│ ├── toolErrors.ts # Structured error envelope
│ └── schemas.ts # Zod schemas
├── navigation/ # V3: declaration, typeDef, implementation, signatureHelp, completion
├── hierarchy/ # V3: call hierarchy + type hierarchy (prepare, incoming/outgoing, super/subtypes)
├── workspaceEdit/ # V2: parse, validate, preview workspace edits
├── codeActions/ # V2: code action cache + normalization
├── diagnostics/ # V2: snapshot store, compare, wait-for-diagnostics
├── context/ # V3: enclosing symbol, symbol context, file outline
├── analysis/ # V3: change impact, fix candidates, explain diagnostics
├── formatting/ # V2: format + range format preview
├── refactor/ # V2: prepare rename, organize imports
├── composite/ # V1: diagnostics summary, inspect symbol
├── diff/ # V1: applyTextEdits, workspaceEditToDiff
├── semantic/ # V3: fixDiagnosticCandidates, explainDiagnostics, analyzeChangeImpact
├── documents/ # V4: open, close, sync, save, list documents
├── ops/ # V4: server status, restart, shutdown, readiness, liveness, workspace status
├── observability/ # V4: request tracker, request log
├── cache/ # V4: cache status + selective clearing
├── debug/ # V4: raw request (disabled by default, method denylist)
├── safety/
│ ├── paths.ts # Workspace containment check
│ └── limits.ts # Truncation caps and timeouts
└── utils/
├── asyncTimeout.ts # Promise race with timeout
├── uri.ts # URI ↔ path conversion
├── symbols.ts # Symbol kind normalization
├── ids.ts # ID generation
├── text.ts # Text utilities
└── time.ts # Time utilitiesAPI Reference
Every tool returns either a success payload or a structured error:
{
"error": {
"code": "path_outside_workspace",
"message": "Human-readable description",
"details": {}
}
}Navigation & Discovery
Tool | LSP Method | Description |
|
| Type information and documentation at cursor |
|
| Go-to-definition locations |
|
| Find all references to a symbol |
|
| Symbol outline for a file |
|
| Workspace-wide symbol search |
|
| Go-to-declaration |
|
| Go-to-type-definition |
|
| Find implementations |
Diagnostics
Tool | Description |
| Cached diagnostics for a file or workspace-wide |
| Grouped diagnostics with root-cause heuristic |
| Wait for fresh diagnostics after a change |
| Save a named diagnostic snapshot for comparison |
| Diff two diagnostic snapshots |
| Cluster diagnostics and identify root causes |
| Multi-source fix suggestions (hover + code actions + definition) |
Refactoring & Editing
Tool | LSP Method | Description |
|
| Preview rename via |
|
| Check if rename is valid at a position |
|
| Preview code actions with diffs |
|
| Resolve a cached code action |
|
| Preview formatting with diff |
|
| Preview range formatting with diff |
|
| Preview import organization with diff |
| — | Preview any |
| — | Validate |
Deep Understanding
Tool | LSP Method | Description |
|
| Function signature at call site |
|
| Code completion suggestions |
| composite | Aggregate: hover + definition + refs + risk hints |
| composite | Surrounding symbols at a position |
| composite | Innermost enclosing symbol |
| composite | File-level symbol outline |
Hierarchy & Impact
Tool | LSP Method | Description |
|
| Prepare call hierarchy for a symbol |
|
| Who calls this symbol |
|
| What this symbol calls |
|
| Prepare type hierarchy |
|
| Super-types of a symbol |
|
| Sub-types of a symbol |
| composite | Cross-file impact analysis for a proposed change |
Server Lifecycle
Tool | Description |
| Runtime status for all configured language servers |
| Restart a language server (reopens docs, clears diagnostics) |
| Graceful shutdown with timeout |
| Configured languages, extensions, commands, binary availability |
| Normalized LSP capabilities per language |
Document Lifecycle
Tool | LSP Method | Description |
|
| Register a document with the LSP server |
|
| Unregister a document |
|
| Notify LSP of content changes |
|
| Notify LSP of a save |
| — | All currently tracked open documents |
Health
Tool | Description |
| Server health and per-language LSP capabilities |
| Workspace + language server availability check |
| Fast liveness check + optional memory stats |
Observability & Cache
Tool | Description |
| LSP request history with filtering |
| Clear request log entries |
| Entry counts for all internal caches |
| Selective or full cache clearing |
Configuration
Tool | Description |
| Effective config (defaults → env → runtime overrides) |
| In-memory config updates (limits, timeouts, caches, debug) |
Debug
Tool | Description |
| Raw LSP request with method denylist (disabled by default) |
Multi-Workspace
Tool | Description |
| Known workspaces (foundation) |
| Status for a specific workspace (foundation) |
Error Handling
Every tool returns errors in a uniform envelope:
{
"error": {
"code": "path_outside_workspace",
"message": "Path is outside workspace: /etc/passwd",
"details": {}
}
}Error Codes
Code | Trigger |
|
|
| File extension has no registered LSP server |
| File does not exist on disk |
| Language server binary not on |
| Server not initialized |
| LSP request returned an error |
| LSP request exceeded its deadline |
| Server does not support the capability |
| Server lacks declaration provider |
| Server lacks type definition provider |
| Server lacks implementation provider |
| Server lacks signature help provider |
| Server lacks completion provider |
| Server lacks call hierarchy provider |
| Hierarchy item ID not found |
| Hierarchy item TTL expired |
| Server lacks type hierarchy provider |
| Type hierarchy item ID not found |
| Type hierarchy item TTL expired |
| Change impact partial results |
| Diagnostic index not found |
| Unknown config key in update |
| Invalid config value (e.g., negative limit) |
| Attempt to change workspacePath at runtime |
| Language not configured |
| Too many restarts in window |
| Debug tool is disabled |
| LSP method blocked by denylist |
| Document not in open documents store |
Safety Model
The server is designed for read-oriented coding agents:
Guard | Mechanism |
Workspace containment | Every file path validated against |
No file writes | All tools are read-only; |
Result caps | All list results are truncated with configurable limits |
Timeouts | Every LSP request has a per-method deadline |
Structured errors | All errors use the uniform |
Request log privacy | Logs method, duration, status — never full file contents (unless verbose logging explicitly enabled) |
Method denylist |
|
Restart rate limiting | Max 3 restarts per 60s per language |
State machine validation | Invalid LSP state transitions are logged and rejected |
Development
pnpm run typecheck # TypeScript type-check
pnpm run lint # ESLint (zero warnings)
pnpm run lint:fix # ESLint auto-fix
pnpm run dev # Run with tsx (no build)
pnpm run build # Build to dist/
pnpm run start # Start built artifactPre-commit Hook
husky + lint-staged:
eslint --fix --max-warnings 0pnpm run typecheckpnpm run verify:decoupling
Conventions
Module system: ESM (
"type": "module",NodeNext)TypeScript: strict, target ES2022
Testing:
node --test+tsxLinting: ESLint with
@typescript-eslint, zero-warnings policy
Testing
pnpm test # All unit tests
npm run test:safety # Safety tests
npm run test:integration # Integration tests (requires language servers)Coverage
106+ tests across unit, integration, and safety suites
5 languages: TypeScript, JavaScript, Python, Go, Rust
V1-V3 regression: all passing with every V4 change
Supported Languages
Language | Extensions | Language Server | Language ID |
TypeScript |
|
|
|
JavaScript |
|
|
|
Python |
|
|
|
Go |
|
|
|
Rust |
|
|
|
Adding a language:
Entry in
src/config/languageServers.tsBinary on
$PATHOptional
waitConfiginsrc/lsp/diagnosticsCache.ts
Troubleshooting
lsp_server_unavailable
which typescript-language-server pyright-langserver gopls rust-analyzer
npm install -g typescript-language-server pyrightUse lsp_list_supported_languages to check binary availability at runtime.
path_outside_workspace
Set WORKSPACE_PATH to the project root. Symlinks are resolved before containment check.
No diagnostics
Diagnostics are cached from publishDiagnostics notifications. For cold cache, use lsp_diagnostics with workspaceWide: true to trigger a warm-up pass, or lsp_wait_for_diagnostics.
Stale diagnostics after external edit
Use lsp_sync_document to notify the LSP of changes, then lsp_wait_for_diagnostics. For bulk recovery, lsp_restart_server with reopenDocuments: true.
Changelog
Version | Focus | Key Additions |
V4 | Production operations | Server lifecycle, document lifecycle, observability, cache, config, health, debug, multi-workspace (21 tools) |
V3 | Deep understanding | Hierarchy (call + type), declaration, type definition, implementation, signature help, completion, impact analysis (17 tools) |
V2 | Safe refactoring | Preview-first editing — rename, code actions, formatting, organize imports, diagnostics snapshots (11 tools) |
V1 | Semantic navigation | Hover, definition, references, symbols, diagnostics, rename preview, inspect (10 tools) |
License
MIT
Available Tools
56 toolslsp_analyze_change_impactA
Analyze the likely impact of changing a symbol using LSP-only semantic data. Composes hover, definition, type definition, implementation, references, call hierarchy, and diagnostics. Does NOT call AST tools.
Inputs: filePath (required), position (required), changeKind, maxReferences, +3 more.
lsp_cache_statusA
Return entry counts for all registered caches.
Inputs: no named parameters.
lsp_clear_cachesA
Clear specified caches by name. Omit caches to clear all.
Inputs: caches.
lsp_clear_request_logA
Clear request log entries. Omit all filters to clear everything.
Inputs: method, status, language.
lsp_close_documentB
Close a document in the LSP server (textDocument/didClose) and remove it from tracking.
Inputs: filePath (required), language (required).
lsp_code_actions_previewA
Return available LSP code actions (quickfixes, refactors, source actions) for a range or diagnostic, with safe edit previews. No commands are executed and no files are written.
Inputs: filePath (required), only, range, maxActions, +2 more.
lsp_compare_diagnosticsA
Compare two diagnostic snapshots to identify fixed, introduced, and unchanged diagnostics.
Inputs: afterId (required), beforeId (required).
lsp_completionA
Return constrained completion candidates at a position without applying them. Maps to textDocument/completion. Read-only — never applies insertText or additionalTextEdits.
Inputs: filePath (required), position (required), maxResults, includeInsertText, +1 more.
lsp_declarationA
Find declarations for a symbol. Maps to textDocument/declaration. Useful for C/C++ header/source split, TypeScript interfaces, Java abstract methods.
Inputs: filePath (required), position (required), maxResults.
lsp_definitionC
Request textDocument/definition from the LSP server and return normalized locations.
Inputs: filePath (required), position (required), maxResults.
lsp_diagnosticsA
Return cached diagnostics for a file or the whole workspace. Triggers warm-up if workspaceWide is requested and cache is empty.
Inputs: filePath, severity, maxResults, workspaceWide.
lsp_diagnostics_summaryA
Return a summary of cached diagnostics grouped by severity, file, source, and message with a likely root cause.
Inputs: filePath, workspaceWide.
lsp_document_symbolsB
Request textDocument/documentSymbol from the LSP server and return normalized symbols.
Inputs: filePath (required).
lsp_explain_diagnosticsA
Explain diagnostics using LSP-only information. Groups diagnostics by root cause and proposes fix order. Does NOT use AST extraction.
Inputs: filePath, workspaceWide, maxDiagnostics, includeFixCandidates.
lsp_fix_diagnostic_candidatesB
Return LSP-based fix candidates for a diagnostic. Composes code actions, hover, definition, and signature help. Does NOT use AST context.
Inputs: filePath (required), range, includeHover, diagnosticCode, +4 more.
lsp_format_previewA
Preview formatting changes for a file. Returns a unified diff without writing any files.
Inputs: filePath (required), tabSize, includeDiff, insertSpaces.
lsp_get_capabilitiesC
Return normalized LSP capabilities for a language server. Optionally initializes the server.
Inputs: language (required), startIfNeeded.
lsp_get_configA
Return the effective runtime configuration merged from defaults, environment variables, and runtime overrides.
Inputs: includeEnv, includeDefaults.
lsp_health_checkB
Return server health status and available LSP capabilities across all registered language servers.
Inputs: no named parameters.
lsp_hoverB
Request textDocument/hover from the LSP server and return normalized contents.
Inputs: filePath (required), position (required).
lsp_implementationA
Find implementations of an interface, trait, abstract class, or method. Maps to textDocument/implementation. Answers 'who implements this?'
Inputs: filePath (required), position (required), maxResults.
lsp_incoming_callsA
Find callers of a function or method using a cached call hierarchy item ID. Maps to callHierarchy/incomingCalls.
Inputs: itemId (required), maxResults.
lsp_inspect_symbolB
Return hover, definitions, references, enclosing symbols, and risk hints for a symbol at a position.
Inputs: filePath (required), position (required), maxReferences.
lsp_list_open_documentsA
Return all documents currently tracked as open in the LSP servers, optionally filtered by language.
Inputs: language.
lsp_list_supported_languagesA
Return configured languages with extensions, commands, and binary availability. Does not start language servers.
Inputs: no named parameters.
lsp_list_workspacesA
Return the list of known workspaces. Currently single-workspace (foundation for future multi-root).
Inputs: no named parameters.
lsp_livenessA
Fast liveness check. Does not start any language servers. Returns uptime and optional memory stats.
Inputs: includeMemory.
lsp_open_documentA
Open a document in the LSP server (textDocument/didOpen). Tracks the document for lifecycle management.
Inputs: filePath (required), language (required), text.
lsp_organize_imports_previewA
Preview import organization changes using source.organizeImports code action. Returns a unified diff without writing files.
Inputs: filePath (required), includeDiff.
lsp_outgoing_callsA
Find functions/methods called by a function or method using a cached call hierarchy item ID. Maps to callHierarchy/outgoingCalls.
Inputs: itemId (required), maxResults.
lsp_prepare_call_hierarchyA
Prepare call hierarchy items for a symbol. Returns cached opaque IDs used by lsp_incoming_calls and lsp_outgoing_calls. Maps to textDocument/prepareCallHierarchy.
Inputs: filePath (required), position (required), maxItems.
lsp_prepare_renameB
Check rename viability at a position. Returns range and placeholder if the symbol can be renamed.
Inputs: filePath (required), position (required).
lsp_prepare_type_hierarchyA
Prepare type hierarchy items for a class, interface, trait, or type. Returns cached opaque IDs used by lsp_supertypes and lsp_subtypes. Maps to textDocument/prepareTypeHierarchy.
Inputs: filePath (required), position (required), maxItems.
lsp_range_format_previewA
Preview formatting changes for a range within a file. Returns a unified diff without writing any files.
Inputs: range (required), filePath (required), tabSize, includeDiff, +1 more.
lsp_raw_requestA
Send a raw LSP request to a language server. Disabled by default — enable via LSP_RAW_REQUEST_ENABLED env var or update_runtime_config. Dangerous methods are always blocked.
Inputs: method (required), language (required), params.
lsp_readinessB
Check if the MCP LSP server is ready to handle agent work. Optionally initializes language servers.
Inputs: language, initServers.
lsp_referencesB
Request textDocument/references from the LSP server and return normalized locations.
Inputs: filePath (required), position (required), maxResults, includeDeclaration.
lsp_rename_previewA
Preview a rename operation. Returns the WorkspaceEdit and a unified diff. No files are written to disk.
Inputs: newName (required), filePath (required), position (required), includeDiff.
lsp_request_logA
Return LSP request log entries with optional filtering by language, method, status, and time.
Inputs: limit, since, method, status, +1 more.
lsp_resolve_code_actionB
Resolve a lazy code action from the cache and return a validated edit preview.
Inputs: actionId (required), includeDiff.
lsp_restart_serverA
Restart a language server. Clears stale diagnostics and optionally reopens tracked documents.
Inputs: language (required), reopenDocuments, shutdownTimeoutMs.
lsp_save_documentA
Notify the LSP server that a document was saved (textDocument/didSave). Does NOT write to disk.
Inputs: filePath (required), language (required), text.
lsp_server_statusB
Return runtime status for all configured language servers. Does not start any server.
Inputs: language.
lsp_shutdown_serverA
Gracefully shut down a language server. Subsequent code-intelligence calls restart lazily.
Inputs: language (required), forceTimeoutMs.
lsp_signature_helpA
Return function/method call signature information at a position. Maps to textDocument/signatureHelp. Useful for checking wrong arguments, missing parameters, incorrect overloads.
Inputs: filePath (required), position (required).
lsp_snapshot_diagnosticsA
Take a snapshot of current diagnostic state. Returns a snapshot ID for later comparison.
Inputs: name, filePath.
lsp_subtypesB
Find subclasses, implementers, child interfaces, or subtypes. Maps to typeHierarchy/subtypes.
Inputs: itemId (required), maxResults.
lsp_supertypesA
Find parent classes, implemented interfaces, extended interfaces, parent traits, or supertypes. Maps to typeHierarchy/supertypes.
Inputs: itemId (required), maxResults.
lsp_sync_documentA
Sync document content changes to the LSP server (textDocument/didChange). Auto-opens if not already tracked.
Inputs: filePath (required), language (required), text.
lsp_type_definitionA
Find the definition of the type of a symbol. Maps to textDocument/typeDefinition. Resolves variable types to their type/interface/class definitions.
Inputs: filePath (required), position (required), maxResults.
lsp_update_runtime_configA
Update runtime configuration in memory. Immutable keys (workspacePath, server commands) are rejected. Changes are lost on restart.
Inputs: config (required).
lsp_validate_workspace_editA
Validate a raw LSP WorkspaceEdit without generating a diff. Returns violations only.
Inputs: workspaceEdit (required), maxEdits, maxFiles.
lsp_wait_for_diagnosticsA
Wait for diagnostics to arrive after a document sync or external edit. Useful for agent synchronization loops.
Inputs: filePath, settleMs, timeoutMs, workspaceWide.
lsp_workspace_edit_previewA
Parse, validate, and preview a raw LSP WorkspaceEdit. Returns a unified diff without writing any files to disk.
Inputs: workspaceEdit (required), maxEdits, maxFiles, includeDiff.
lsp_workspace_statusC
Return status for a specific workspace including its language servers.
Inputs: workspacePath (required).
lsp_workspace_symbolsC
Request workspace/symbol from the LSP server and return normalized symbols.
Inputs: query (required), language, maxResults.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 56 tools
Tools are mostly distinct, each targeting a specific LSP operation or management task. Some overlap exists among preview tools (format, rename, code action, etc.) and diagnostic tools, but descriptions clarify their differences.
All tools follow the 'lsp_' prefix with a consistent verb_noun pattern (e.g., lsp_hover, lsp_definition, lsp_rename_preview). Minor plural/singular variations (e.g., lsp_references vs lsp_definition) are acceptable and do not break consistency.
56 tools is on the high side, reflecting the comprehensive LSP protocol coverage. While each tool has a clear purpose, the large number may overwhelm agents and suggests some operations could be consolidated. Still within a reasonable range for a complex domain.
The tool set covers all major LSP features (hover, definition, references, completion, diagnostics, code actions, renaming, formatting, call/type hierarchies) plus lifecycle and configuration management. There are no obvious gaps for standard code intelligence workflows.
Related MCP Connectors
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Lean 4 MCP server: compile, prove theorems, and formalize math with Mathlib.
An MCP server that provides agents access to the KeldynAI platform
Related MCP Servers
- AlicenseAqualityDmaintenanceA TypeScript-aware MCP server that provides coding agents with repository discovery, code intelligence, and web project context for local codebases. It enables deep symbol navigation, diagnostic reporting, and structural analysis of monorepos without requiring full IDE integration.711 npm1MIT
- AlicenseNot gradedqualityDmaintenanceExposes Language Server Protocol (LSP) tools such as diagnostics, goto definition, find references, symbols, and rename as a stdio MCP server.9MIT
- AlicenseNot gradedqualityCmaintenanceSemantic code intelligence MCP server for TypeScript/JavaScript codebases, enabling AI agents to retrieve specific symbols, types, and relationships without reading entire files.21MIT
- AlicenseNot gradedqualityCmaintenanceMCP server that gives AI coding agents codebase navigation intelligence, enabling symbol lookup, reference finding, type inspection, and diagnostics through tools like locate, refs, hover, diagnostics, status, and rename.MIT