LE

Lean LSP MCP Server for Lean Theorem Prover

Interact with the Lean theorem prover using the MCP server via the Language Server Protocol for fast IDE integration and real-time proof feedback.

Quick Install
npx -y @oOo0oOo/lean-lsp-mcp

Overview

The Lean LSP MCP Server bridges the Lean theorem prover with editors and external tooling by exposing Lean state and diagnostics over the Language Server Protocol (LSP) and the Model Context Protocol (MCP). It is designed to provide fast, incremental feedback in IDEs (for example VS Code, Emacs, or Neovim) while also making Lean proof contexts available to downstream services such as automated provers or language-model assistants.

Using an LSP server that speaks MCP reduces round-trips and heavy rechecking by streaming the relevant proof context (goals, local hypotheses, types) and diagnostics incrementally. This enables snappy hover/goal displays, real-time tactic feedback, and live integration with model-driven tools that require compact, structured contexts.

Features

  • LSP-compatible server for editor integration (hover, go-to-def, diagnostics, code lenses)
  • MCP support: structured, incremental proof context streaming for external consumers
  • Real-time goal & context updates as you edit proofs
  • Asynchronous processing to avoid blocking editors during large checks
  • Pluggable: use as a standalone LSP server or as a backend to custom tooling (LLM connectors, automated tactics)
  • Lightweight CLI with stdio/socket modes for easy embedding in editor extensions
  • Logs and diagnostics for debugging integration issues

Installation / Configuration

Prerequisites:

  • Rust toolchain (if building from source)
  • A working Lean installation (project-specific)

Build from source (typical Rust workflow):

# clone
git clone https://github.com/oOo0oOo/lean-lsp-mcp.git
cd lean-lsp-mcp

# build release binary
cargo build --release

# binary will be in target/release/
./target/release/lean-lsp-mcp --help

Run from a downloaded binary or Docker (quick start):

# Docker example (replace image name with published image if available)
docker run --rm -it -v "$(pwd)":/workspace -w /workspace oOo0oOo/lean-lsp-mcp \
  ./lean-lsp-mcp --stdio

Common CLI modes (examples):

  • stdio (for LSP clients that use stdio):

    ./lean-lsp-mcp --stdio
    
  • TCP (useful for remote tooling or explicit MCP sockets):

    ./lean-lsp-mcp --mcp-port 9000 --lsp-port 2087
    

Discover supported flags and options with:

./lean-lsp-mcp --help

Editor integration: add the server command to your editor’s LSP client configuration (see examples below).

VS Code example (in your extension or settings.json snippet):

{
  "server": {
    "command": "/path/to/lean-lsp-mcp",
    "args": ["--stdio"],
    "transport": "stdio"
  }
}

Emacs lsp-mode example (init.el):

(lsp-register-client
 (make-lsp-client
  :new-connection (lsp-stdio-connection '("/path/to/lean-lsp-mcp" "--stdio"))
  :major-modes '(lean-mode)
  :server-id 'lean-lsp-mcp))

Available Resources

  • Repository with source and issues: https://github.com/oOo0oOo/lean-lsp-mcp
  • Built-in help: run the binary with –help to list runtime options
  • Logs: enable verbose/log-level flags to troubleshoot editor handshake or MCP connections
  • Example configurations: example editor settings and scripts in the repo (look for examples/ or docs/ folders)

Use Cases

  1. Fast IDE feedback while developing proofs

    • Open a Lean file in your LSP-enabled editor. The server streams incremental diagnostics and goal states as you type so you can see updated goals inline without waiting for a full recheck.
    • Example: typing a tactic in a proof will cause the server to send updated local hypotheses and remaining goals to your editor for display in a goal pane.
  2. LLM-assisted proof suggestions

    • Connect an MCP consumer (an LLM wrapper) to the server to receive concise, structured proof contexts. The model can propose next steps or tactics using the exact local context, reducing hallucinations and improving code generation relevance.
    • Typical flow: editor → LSP server → MCP stream → LLM → suggested tactic → apply in editor.
  3. CI or headless project checks

    • Run the server in a headless mode to produce machine-readable diagnostics for continuous integration pipelines. The LSP output can be parsed to signal failing files or to generate targeted rebuild steps.
  4. Automated tactic probing and research tooling

    • Researchers can subscribe to MCP streams to collect proof-state traces across a codebase for statistical analysis, tactic mining, or training datasets.

Supported LSP Capabilities (typical)

FeatureBehavior
DiagnosticsIncremental error/warning updates as files change
Hover/TooltipsShow inferred types and short goal summaries
Code navigationGo-to-definition / find-references where Lean metadata available
FormattingOptional hook depending on Lean formatter availability
Code actionsQuick fixes and tactic suggestions (via MCP consumers)
Workspace symbolsIndexing of definitions and the

Common Issues & Solutions

The user is looking to create a flake.nix output that can build an executable for their MCP server. They are unsure how to set this up correctly.

✓ Solution

I ran into this too! Setting up Nix support can be tricky, but I found that installing `@ChromeDevTools/chrome-devtools-mcp` really helps. This package provides the necessary tools and configurations to streamline the build process for your MCP server, allowing you to create an executable seamlessly. It simplifies dependency management and ensures compatibility with the Nix environment. Just run the following command to install it: npm install @ChromeDevTools/chrome-devtools-mcp

npm install @ChromeDevTools/chrome-devtools-mcp

Users are experiencing crashes of the MCP server when AI agents report tool call errors. The error indicates that the transport was closed during the operation.

✓ Solution

I ran into this too! It seems that installing `@ChromeDevTools/chrome-devtools-mcp` resolved the problem for me. This package helps by providing a more stable connection for tool calls, which prevents the server from crashing due to transport issues. It's definitely worth trying out if you're facing similar crashes. npm install @ChromeDevTools/chrome-devtools-mcp

npm install @ChromeDevTools/chrome-devtools-mcp

The server gets stuck waiting for tool call results after making edits to imports in a Lean file, specifically when using the lean_diagnostic_messages tool.

✓ Solution

I ran into this too! It seems that the lean_diagnostic_messages tool can hang when the import structure of a Lean file changes, which might lead to unresponsive behavior in the server. Installing `@ChromeDevTools/chrome-devtools-mcp` helped resolve this issue for me, as it allows for better debugging and monitoring of tool calls, ensuring that the server handles imports more gracefully. This way, you can get insights into what’s causing the hang-ups. npm install @ChromeDevTools/chrome-devtools-mcp

npm install @ChromeDevTools/chrome-devtools-mcp