Liking cljdoc? Tell your friends :D

lsp-mcp

Clojars Project cljdoc release License: MIT

Clojure LSP analysis addon for hive-mcp. Provides structural code analysis via three strategies:

  1. Docker sidecar cache -- fast reads from pre-analyzed snapshots
  2. In-process clojure-lsp -- fallback when cache is unavailable
  3. Live LSP bridge -- real-time, position-aware queries through whichever bridge a vessel has registered

Registered as an IAddon (lsp.mcp). The engine discovers it automatically from the classpath manifest.

lsp-mcp names no vessel. It ships no editor code and starts no editor.

Project Structure

lsp-mcp/
  src/lsp_mcp/
    bridge.clj          # ILspBridge protocol + the live-bridge registry
    tools.clj            # MCP tool handlers + command dispatch
    init.clj             # IAddon implementation + nil-railway pipeline
    core.clj             # Analysis orchestration
    cache.clj            # Docker sidecar cache client
    analysis.clj         # Extraction helpers (vars, calls, ns-graph)
    kg_bridge.clj        # Knowledge Graph sync bridge
    log.clj              # Logging shim (timbre/stderr)
  resources/
    META-INF/hive-addons/
      lsp-mcp.edn          # Addon manifest

Live bridges

A live bridge is any lsp-mcp.bridge/ILspBridge. A vessel registers one under its own key:

;; soft-resolved, so the vessel does not compile against lsp-mcp
((requiring-resolve 'lsp-mcp.bridge/register-bridge!)
 :my-vessel
 ((requiring-resolve 'lsp-mcp.bridge/fn-bridge)
  {:available? (fn [] true)
   :call       (fn [method & args] ...)}))   ; method: "hover", "definition", ...

The tools ask active-bridge on every call, so a vessel that starts after lsp-mcp is picked up without a restart. With no bridge registered, the live commands answer :bridge/unavailable.

Known bridges:

BridgeLives inBackend
:emacshive-emacs (hive-emacs.lsp-bridge, elisp/hive-lsp-bridge.el)lsp-mode + clojure-lsp in a running Emacs

MCP Commands

Static analysis (strategies 1 & 2)

CommandDescription
analyzeProject summary (files, namespaces, vars)
definitionsList var definitions, optionally filtered by namespace
callsCall graph, filtered by namespace/function
callersFind callers of a function
referencesFind references to a function
ns-graphNamespace dependency graph
syncSync analysis to Knowledge Graph
statusCache and bridge status

Live LSP bridge (strategy 3)

CommandParametersDescription
bridge-status--Check bridge availability and workspace count
workspaces--List active LSP workspaces
hoverproject_root, file_path, line, columnHover info at position
definitionproject_root, file_path, line, columnGo-to-definition
live-referencesproject_root, file_path, line, columnFind all references
symbolsproject_root, file_pathDocument symbols
cursor-infoproject_root, file_path, line, columnclojure-lsp cursor info
server-infoproject_rootclojure-lsp server info

line and column are 0-based.

Architecture

MCP tool call
  -> tools.clj (command dispatch)
       |
       +-- Static: core.clj -> cache.clj / clojure-lsp.api
       |
       +-- Live:   bridge/active-bridge -> ILspBridge
                     |
                     +-- whatever a vessel registered (e.g. hive-emacs :emacs)

The ILspBridge protocol (DIP) decouples tools.clj from any LSP backend; the registry decouples lsp-mcp from any vessel.

License

MIT

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close