mcp-lsp

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mcp-lsp

test pkg.go.dev Go module codecov.io

mcp-lsp provides an MCP server that runs and exposes Language Server Protocol capabilities to agents over MCP stdio.

Runtime language registry

mcp-lsp does not activate hardcoded language-server defaults at startup. Active downstream language servers come from these sources, in order of precedence from highest to lowest:

  1. an explicit one-off -lsp CLI override,
  2. a runtime JSON config file,
  3. PATH discovery for known language-server commands, unless -discover=false.

The built-in language catalog contains identity metadata such as aliases, extensions, LSP language IDs, and discovery candidates. That catalog is not an active server registry by itself.

# Infer Python from the common BasedPyright command.
mcp-lsp -lsp basedpyright-langserver -- --stdio

# Use a workspace-local or explicit runtime registry config.
mcp-lsp -config .mcp-lsp.json

# Disable PATH discovery for deterministic environments.
mcp-lsp -discover=false -config .mcp-lsp.json

If no config is supplied, mcp-lsp also checks for .mcp-lsp.json in the workspace root. If the workspace does not provide .mcp-lsp.json, mcp-lsp then checks a global runtime config. Set MCP_LSP_CONFIG to override the global path; otherwise the default global path is $XDG_CONFIG_HOME/mcp-lsp/config.json when XDG_CONFIG_HOME is set to an absolute path. When XDG_CONFIG_HOME is blank or unset, the default global path falls back to $HOME/.config/mcp-lsp/config.json. Missing workspace and default global configs are ignored; a relative XDG_CONFIG_HOME value does not define a default global config path. A missing or unreadable explicit -config path or MCP_LSP_CONFIG path is an error.

Config file path precedence is:

  1. -config <path>,
  2. <workspace>/.mcp-lsp.json,
  3. MCP_LSP_CONFIG,
  4. $XDG_CONFIG_HOME/mcp-lsp/config.json when XDG_CONFIG_HOME is absolute,
  5. $HOME/.config/mcp-lsp/config.json when XDG_CONFIG_HOME is blank or unset.

A minimal config looks like this:

{
  "servers": {
    "python": {
      "command": "basedpyright-langserver",
      "args": ["--stdio"],
      "languageId": "python",
      "extensions": [".py", ".pyi"],
      "aliases": ["py", "pyright", "basedpyright"]
    },
    "go": {
      "command": "gopls",
      "languageId": "go",
      "extensions": [".go"]
    }
  }
}

The built-in catalog covers the standard LSP language IDs for identity, canonicalization, file inference, and conservative PATH discovery. Catalog support does not mean every language server is installed or active; a language server becomes active only through config, discovery of a known executable, or a CLI override.

The runtime config can also define languages that are not built into the catalog. If languageId is omitted, the normalized config key is used as the LSP TextDocumentItem.languageId.

{
  "servers": {
    "gleam": {
      "command": "gleam",
      "args": ["lsp"],
      "languageId": "gleam",
      "extensions": [".gleam"]
    }
  }
}

One MCP process can manage multiple languages. Each downstream LSP process is spawned lazily on the first request for its configured language and then reused.

For file-based tools such as diagnostics, hover, definition, formatting, rename, code actions, and code lenses, language may be omitted when the file extension or shebang identifies a configured language. Explicit language still wins for generated or unusual files. If a file extension is unknown, or the matching language has no configured server, the tool returns a clear error rather than routing to another language.

File-less tools are deterministic:

  • lsp_workspace_symbol uses the explicit language, or the single configured language when exactly one server is active.
  • lsp_execute_command never fans out across multiple language servers; omit language only when exactly one server is configured.

Composite tools

Alongside the thin, one-request-per-tool wrappers, mcp-lsp exposes composite tools that fuse several language-server requests into one call, returning judgement an agent cannot cheaply assemble by chaining raw tools:

  • lsp_impact_analysis — the blast radius of changing a symbol: references, call graph, type graph, implementations, and diagnostics. References is the epicenter; the rest fan out and degrade independently.
  • lsp_symbol_context — a dense symbol card: hover, enclosing outline, signature, navigation targets, same-file occurrences, and inlay context. Hover is the epicenter.
  • lsp_change_guard — a verify-after-edit report over the post-edit, on-disk state of a changed file, ending in an advisory verdict. Diagnostics is the epicenter.
  • lsp_override_contract_audit — the contract counterparts to change together when editing an interface/trait/base method: the concrete implementations, each with a hover summary and its depth-1 callers, plus the type graph, references, and diagnostics. Implementation is the epicenter. Because textDocument/implementation is bidirectional on some servers, anchoring at a concrete method resolves the interface methods it satisfies, so the result is framed as "contract counterparts" rather than a fixed direction.
  • lsp_call_path_tracer — a bounded, direction-parameterized walk of the caller/callee graph around a function: named nodes with concrete call sites, cycle detection, and the entrypoints and leaves of fully-explored paths. Call-hierarchy prepare is the epicenter. direction selects incoming (callers), outgoing (callees), or both; maxDepth (1–4, default 3) bounds the walk. Entrypoints and leaves are reported only for nodes whose expansion completed, and truncation is stated rather than letting a cut-off node read as a dead end, so a partial graph never manufactures a "no further callers" claim.
  • lsp_file_intelligence_map — a one-call semantic map of a single file: its outline, foldable regions, code lenses, inlay hints, and diagnostics. The document outline is the epicenter, resolved directly rather than through the readiness loop because it is syntax-derived and file-scoped. The diagnostics leg carries its own readiness: cold or unsettled diagnostics report notReady (and stopReason exhausted) rather than a false-empty clean signal, while the outline and other legs stay valid. Code lenses being empty is normal on config-dependent servers, distinct from unsupported.
  • lsp_mutation_flow — only the sites where a variable or field is written, with passive reads filtered out, so a state-corruption debug reads as a pure state-transition log. Document-highlight is the epicenter and supplies the parser-level write/read classification; cross-file writes come from references and are re-classified by re-running highlight per file. A line that takes the target's address is flagged, and the result carries an aliasing caveat in meta.caveats: a write through such an alias cannot be traced, so the write list is never claimed to be exhaustive.
  • lsp_symbol_xray — a semantic audit of one symbol in a single call: its hover signature and docs, its parameter schema with one level of struct-field unpacking, its type lineage (supertypes and interfaces), and its inlay context. Hover is the epicenter. Field unpacking is a single non-recursive level: a parameter whose type is itself a struct is named but not expanded, so a deeply nested or self-referential type cannot explode the payload.
  • lsp_dead_weight_reaper — a directory-scoped sweep for dead weight: unreferenced symbols and dangling imports across a package, each carrying an advisory safelyRemovable recommendation. Unlike the other composites it takes a directory, not a file: the epicenter is a bounded file walk plus per-file document-symbol enumeration. Because "safe to delete" is a destructive recommendation drawn from read-only data, a symbol is flagged safelyRemovable only when it is unreferenced on a two-pass confirmation (guarding against a cold index under-reporting references), is not exported (an uppercase-first Go name or a pub Rust item with zero internal references is listed but never green-lit, since it may be public API), and the diagnostics cross-check settled. referencesFound is surfaced so the agent sees the evidence, not just the verdict — the caller owns the deletion and must verify first.

All are read-only and share a metadata block: readiness, stopReason, epicenterTextHash (a SHA-256 of the file text the call actually analyzed, so a concurrent on-disk edit is detectable), and capabilitiesUsed/ capabilitiesMissing.

Degradation contract

Each composite has one epicenter leg that is fatal when its capability is unsupported — lsp_impact_analysis needs references, lsp_symbol_context needs hover, lsp_change_guard needs diagnostics, lsp_override_contract_audit needs implementation, lsp_call_path_tracer needs call hierarchy, lsp_file_intelligence_map needs the document outline, lsp_mutation_flow needs document highlight, both lsp_symbol_context and lsp_symbol_xray need hover, and lsp_dead_weight_reaper needs document symbol (the per-file enumeration that anchors its directory walk) — and the tool returns an error in that case. Every other leg degrades on its own, carrying a per-leg status:

  • ok / empty — the leg ran; empty is a trustworthy zero, only reported after a readiness check.
  • unsupported — the server does not advertise the capability. This is distinct from empty, so an absent capability is never read as "no results".
  • truncated — a budget cap was hit and the data is partial.
  • error — the leg failed for a reason other than an unsupported capability.
  • notReady — the leg could not be trusted within its readiness budget (the server was likely still indexing, or a fan-out deadline cut it short).

Because capabilities differ per server, the same composite returns different legs as unsupported on different servers: lsp_impact_analysis and lsp_override_contract_audit report the declaration leg unsupported on gopls and the type-graph leg unsupported on rust-analyzer and basedpyright. These rows are asserted against each live server, not assumed. basedpyright, in particular, advertises no type-hierarchy, folding-range, or code-lens provider, so lsp_symbol_xray's type-lineage leg and lsp_file_intelligence_map's folding and code-lens legs all degrade to unsupported there; it also publishes diagnostics rather than answering diagnostic pulls, so the settle-gated legs below apply to it exactly as they do to gopls.

Readiness and the advisory verdict

Reference, call-hierarchy, and type-hierarchy legs are readiness-gated: a language server returns empty or partial results while it is still indexing, so an empty result is only trusted once two consecutive lookups agree. An epicenter that never stabilizes yields readiness: notReady and skips the rest of the analysis rather than reporting a misleading zero.

lsp_change_guard's advisoryVerdict (clean / attention / broken) is advisory and settle-gated: it reflects only static diagnostics settled at analysis time — not tests or runtime — and clean is emitted only when diagnostics are both ready and empty. Cold or unsettled diagnostics yield notReady, never a false clean. The basis field names exactly which legs produced the verdict, and the agent owns the decision to ship.

lsp_dead_weight_reaper's safelyRemovable carries the same false-clean guarantee: when the diagnostics cross-check is notReady (an unsettled compiler state), no symbol is marked removable and stopReason is exhausted, so the reaper never green-lights a deletion on cold diagnostics. Note the recommendation follows the language server's own reference view — a call rust-analyzer does not count (for instance from an unreachable function) can make a live symbol read as unreferenced, which is exactly why the recommendation is advisory.

The exported-symbol guard is name-based and language-specific: a Go uppercase name or a Rust pub item is never green-lit, and for Python a leading underscore is treated as an intentional marker, so a symbol such as _Private is protected from the removal recommendation rather than deleted on the basis of zero internal references. The dangling-import leg matches each server's own unused-import phrasing — gopls's "imported and not used", rust-analyzer's "unused import", and basedpyright's "is not accessed" — so an unused import surfaces in danglingImports across all three, asserted against each live server.

Provenance

Composite input is disk-only: the tools read the named file (or, for lsp_dead_weight_reaper, the named directory's source files) from disk at call time, so an agent must write its edits to disk before calling. Unsaved editor buffers are not visible.

Documentation

Overview

Command mcp-lsp runs language servers and exposes their capabilities to an AI agent as Model Context Protocol tools over stdio.

Directories

Path Synopsis
internal
version
Package version derives the build version exposed by mcp-lsp.
Package version derives the build version exposed by mcp-lsp.
pkg
lsp
Package lsp drives language servers over jsonrpc2 and exposes their capabilities as a small, MCP-friendly domain API.
Package lsp drives language servers over jsonrpc2 and exposes their capabilities as a small, MCP-friendly domain API.
lsp/composite
Package composite orchestrates multiple language-server requests into single agent-facing tools.
Package composite orchestrates multiple language-server requests into single agent-facing tools.
mcp
Package mcp exposes language server capabilities as Model Context Protocol tools over stdio.
Package mcp exposes language server capabilities as Model Context Protocol tools over stdio.
tests
internal/lsptest
Package lsptest provides small shared helpers for opt-in integration tests that extract txtar workspaces and drive real language servers.
Package lsptest provides small shared helpers for opt-in integration tests that extract txtar workspaces and drive real language servers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址