lean-lsp-mcp
This MCP server exposes Lean 4 development tools for proof-state inspection, offline symbol lookup, module dependency analysis, and C FFI inspection.
Inspect interactive tactic proof goals at a given
.leanfile line/column vialean_goal.Inspect the expected term type/goal under the cursor via
lean_term_goal.Perform fast offline
.ileansymbol lookup and jump-to-definition vialean_lookup_symbol.Analyze forward and reverse module import dependencies (
imports,importedBy, orboth) vialean_module_hierarchy.Inspect Lean
@[extern]C FFI declarations, C implementations, and Lean sysroot include flags vialean_c_ffi_inspect.
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., "@lean-lsp-mcp Show me the proof state at line 42 in MyTheorem.lean"
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.
lean4-lsp-mcp
Give AI coding agents instant Lean 4 proof goals, sub-5ms symbol navigation, and automatic counterexample checks without waiting on full project rebuilds.
lean4-lsp-mcp (published on npm as lean4-lsp-mcp / lean-lsp-mcp) is a standalone Model Context Protocol (MCP)mcp server that connects AI coding agents (Claude Code, Cursor, Windsurf, Zed, and Antigravity) directly to your Lean 4 proof environment and C FFI headers.

Why Use lean4-lsp-mcp? (What Problem Does It Solve?)
When AI coding agents try to write or fix Lean 4 proofs using standard shell commands, they get stuck in a slow, expensive loop:
Running
lake buildafter every edit takes minutes: Standard agents edit a.leanfile, inserttrace_state, and recompile the whole module just to see the current proof goal.lean4-lsp-mcpkeeps a sharedlake servesession warm and returns the exact tactic goal at any line and column in milliseconds (lean_goal).Agents waste hours trying to prove false lemmas: If a helper lemma has a subtle boundary bug (like a natural number subtraction underflow), an agent will burn hundreds of tactic attempts trying to prove the impossible.
lean_counterexample_searchtests candidate theorems with Plausibleplausible first so false claims are caught in seconds.Searching large Mathlib or multi-file projects is slow: Starting a full language server just to find where a theorem is defined or used eats RAM and time.
lean4-lsp-mcpreads compiled.ileanindex files directly from disk in under 5 milliseconds (lean_lookup_symbol,lean_decl_references,lean_module_hierarchy).
Related MCP server: lsp-mcp-server
Start in 2 Minutes
1. Run via npx (Zero Manual Build Required)
Add lean-lsp to your coding agent's MCP configuration (.mcp.json, ~/.claude/claude_desktop_config.json, or .cursor/mcp.json):
{
"mcpServers": {
"lean-lsp": {
"command": "npx",
"args": ["-y", "lean4-lsp-mcp"],
"env": {
"PATH": "${HOME}/.elan/bin:/usr/bin:/bin"
}
}
}
}# Global npm install
npm install -g lean4-lsp-mcp
# Or build from a local clone
git clone https://github.com/r-irbe/lean4-lsp-mcp.git
cd lean4-lsp-mcp && npm install && npm run buildIf your IDE launches MCP servers from outside your Lean repository, set "LEAN_PROJECT_ROOT": "/path/to/your/lake/project" in the env block.
Adapt to Your Use Case (Customer Journeys)

Who this is for: Researchers, engineers, and AI agents actively closing
sorryplaceholders in Lean 4.How to use it:
Call
lean_goalwith{"filePath": "MyProj/Basic.lean", "line": 42, "col": 4, "target": "tactic"}to see the exact proof state at the cursor, or"target": "altproof"for ranked tactic suggestions.Call
lean_diagnosticswith{"filePath": "MyProj/Basic.lean"}to get live compiler errors plus automatic warnings for natural-number truncation (a - bwithoutb <= a) and division by zero.
Who this is for: Teams writing new formal specifications where edge cases (
0, empty lists, off-by-one bounds) are easy to miss.How to use it: Call
lean_counterexample_searchwith{"filePath": "MyProj/Spec.lean", "theoremName": "my_lemma", "strategy": "dense"}. It runs an isolated property check in a scratch directory and returns a concrete counterexample if the lemma is false.
Who this is for: Maintainers of large Lean 4 repositories, teams porting proofs from Rocq/Coq or Isabelle, and systems engineers binding Lean 4
@[extern]functions to C.How to use it:
Sub-5ms Offline Navigation:
lean_lookup_symbol,lean_decl_references, andlean_module_hierarchyquery.lake/build/lib/**/*.ileandirectly without bootinglake serve.Multi-Source Search:
lean_search,lean_book_index_lookup(65+ math/CS textbooks), andlean_cross_itp_concordance(Coq/Isabelle/HOL Light -> Lean 4 tactic equivalents).Trust & FFI Verification:
lean_axiom_closureverifies a theorem depends only on standard axioms (propext,Classical.choice,Quot.sound), andlean_ffichecks@[extern]C symbols against your C headers.
Complete 21-Tool Reference
See instructions.md for copy-paste JSON payloads and agent prompting guidelines.
Tool Name | Required Parameters | What It Does |
|
| Returns tactic goal, term goal, filtered goal, or |
|
| Live elaboration errors, unsolved goals, and static |
|
| Runs Plausible property testing in an isolated scratch dir to falsify broken theorems. |
|
| Instant offline |
|
| Finds declarations that |
|
| Returns module |
|
| Exports bounded module dependency subgraphs ( |
|
| Unified search across local code, Loogle, LeanSearch, Reservoir, arXiv, books, and graph. |
|
| Looks up concepts across 65+ curated theorem-proving and math textbook indexes. |
|
| Maps tactics and concepts across Coq/Rocq, Isabelle, HOL Light, Agda, and Lean 4. |
|
| Runs |
|
| Live LSP navigation (hover, definition, typeDefinition, declaration, implementation, references, documentSymbol, workspaceSymbol/findSymbol, call hierarchy, advertise-only codeAction) plus offline |
|
| Computes declaration counts, complexity metrics, and corpus censuses. |
| (optional) | Scaffolds and inspects Lean Blueprint LaTeX/dependency nodes and Zettelkasten links. |
|
| Extracts the high-level |
| (optional) | Inspects Lean C FFI sysroot headers and verifies |
|
| Executes a standalone Lean 4 snippet ( |
|
| Refreshes a file worker or reports the resolved Lake project root and server health. |
Optional knowledge graph
Set PROVER_KNOWLEDGE_KZ to the proof-skills release archive to enable concept
and tactic concordance lookup. For a private graph, set KUZU_ARCHIVE_PATH to
its archive, or set LEAN_KUZU_CONFIG_PATH to an explicit federation config
that lists its enabled databases. The server opens graphs only after explicit
configuration. Point standalone deployments at the small proof-skills release
archive when local collections must stay outside the search service.
See the graph examples and result limits.
Available Tools
5 toolslean_c_ffi_inspectA
Cross-language C FFI inspector: Lean @[extern] declarations, C implementations, and Lean sysroot include flags
Inputs: action, externName.
lean_goalA
Queries interactive Lean 4 tactic proof state at cursor position ($/lean/plainGoal)
Inputs: line (required), filePath (required), col, character.
lean_lookup_symbolA
Offline zero-latency symbol lookup and jump-to-definition via pre-compiled .ilean cache
Inputs: symbol (required), preferOfflineIlean.
lean_module_hierarchyB
Forward and reverse module import dependency hierarchy analysis
Inputs: moduleName (required), direction.
lean_term_goalB
Queries expected term type under cursor ($/lean/plainTermGoal)
Inputs: line (required), filePath (required), col, character.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool targets a distinct concern: tactic proof state, term type inspection, symbol lookup, module dependency analysis, and C FFI inspection. There is no overlap or ambiguity between these operations, even the two goal-related tools are clearly differentiated by context.
All tool names follow a uniform pattern with the 'lean_' prefix and snake_case, using noun-based or verb-noun combinations consistently (e.g., lean_goal, lean_lookup_symbol). The naming is predictable and easy to infer purpose from.
With 5 tools, the server is well-scoped for a Lean LSP integration, providing a focused set of capabilities without redundancy or bloat. Each tool serves a clear purpose in the interactive theorem proving workflow.
The tool set covers essential Lean-specific operations like goal queries and symbol lookup, but lacks common LSP features such as hover, diagnostics, or references. However, for a specialized Lean server, the core proving workflows are well-represented, with only minor gaps.
Maintenance
Related MCP Connectors
Architecture compiler for AI code. 11 tools, 92 actions, 872 Lean4 proofs, 100/100 self-cert.
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
AI-native programming language and toolchain for accountable, verifiable agent-driven development.
Code intelligence platform for AI agents. 20 tools for architecture, security & impact analysis.
Related MCP Servers
- AlicenseBqualityBmaintenanceEnables LLM agents to interact with the Lean theorem prover through the Language Server Protocol, providing tools for analyzing Lean projects, accessing diagnostics, goal states, documentation, and searching for theorems using both local and external search services.22148,993 PyPI559MIT
- AlicenseNot gradedqualityDmaintenanceExposes type-aware code navigation and fast file search to AI agents via language servers, enabling definitions, references, symbols, and file lookup without reading entire codebases.MIT
- AlicenseNot gradedqualityBmaintenanceEnables agents to perform local hybrid code search and code intelligence across a workspace, including semantic and full-text search, symbol lookup, file outlines, and caller analysis.MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI-driven formal proof search in Lean 4 by submitting theorems with sorry placeholders and running parallel LLM agents whose proposed edits are verified by the Lean compiler until a machine-checked proof is produced. Also provides Mathlib theorem search and job/attempt management tools.3MIT