lean4-mcp
Generates Mermaid flowchart TD dependency graphs from Lean 4 theorem/lemma/def/axiom declarations, showing how proofs depend on each other so they can be rendered and explored visually in VS Code or Markdown.
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., "@lean4-mcp audit this Lean 4 proof for sorry, axioms, and unsafe code"
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-mcp — Zero-Dependency MCP Server for Lean 4 Learning, Proof Auditing & Visualization
A lightweight Model Context Protocol (MCP) server written in pure Node.js (>= 18, zero external dependencies) that gives VS Code Copilot, Cursor, Claude Desktop, Claude Code, Codex, and Antigravity six interactive Lean 4 tools right inside your editor or AI chat:
MCP Tool | What it does |
| Scans any Lean 4 snippet for |
| Parses |
| Converts Lean 4 ASCII escapes ( |
| Instant before/after goal-state cheat-sheet for 14 core Lean 4 tactics ( |
| Returns structured beginner/intermediate Lean 4 exercises with starter code, hints, and 1-click zero-install browser links. |
| Verified primary GitHub repos, PDFs, and MIT multi-kernel logs for the 2026 Lean 4 Riemann Hypothesis formalization. |
Want to run Lean 4 proofs directly in your browser with zero installation? Try leanproofs.com/playground.
Quick Setup
Clone once
git clone https://github.com/wxyshihxs/lean4-mcp.gitVS Code (.vscode/mcp.json)
{
"servers": {
"lean4-mcp": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/lean4-mcp/src/server.mjs"]
}
}
}Cursor / Claude Desktop (claude_desktop_config.json)
{
"mcpServers": {
"lean4-mcp": {
"command": "node",
"args": ["/absolute/path/to/lean4-mcp/src/server.mjs"]
}
}
}Claude Code
claude mcp add lean4-mcp -- node /absolute/path/to/lean4-mcp/src/server.mjsRelated MCP server: lean-lsp-mcp
Example: Mermaid Proof Dependency Graph (visualize_proof_outline)
Given a Lean 4 file with lemmas and theorems, visualize_proof_outline returns:
flowchart TD
base["lemma base"]
main_thm["theorem main_thm"]
main_thm --> baseRun Tests
cd lean4-mcp
npm testLicense
MIT License.
Available Tools
6 toolsaudit_lean_proofA
Scan a Lean 4 proof for sorry, admit, custom axioms, unsafe blocks, and @[implemented_by] overrides, and optionally run local lean if installed.
Inputs: source (required), compile.
check_rh_2026_sourcesB
Return verified primary GitHub repositories, PDFs, and MIT multi-kernel verification logs for the 2026 Lean 4 Riemann Hypothesis proof.
Inputs: no named parameters.
convert_lean_unicodeA
Convert Lean 4 backslash shortcuts (\forall, \to, \and, \N, <, >, ...) to Unicode symbols or back to ASCII escapes.
Inputs: text (required), direction.
explain_lean_tacticA
Get a concise Lean 4 tactic cheat-sheet entry with before/after goal states and a minimal runnable example.
Inputs: tactic.
get_lean_practice_drillB
Fetch a structured Lean 4 practice exercise with starter code, progressive hints, and a zero-install browser playground link.
Inputs: id, level.
visualize_proof_outlineA
Parse a Lean 4 file’s theorem/lemma/def/axiom declarations and output a Mermaid flowchart TD dependency graph.
Inputs: source (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose: auditing, Unicode conversion, tactic explanation, proof visualization, practice drills, and source checking. There is no meaningful overlap in action or resource, so an agent should reliably select the right tool.
Most tools follow a predictable snake_case verb_noun pattern, often with 'lean' embedded, such as audit_lean_proof and explain_lean_tactic. The main deviation is check_rh_2026_sources, which is more specific and less aligned with the rest.
Six tools is well-scoped for a specialized Lean 4 assistant, with each tool covering a distinct capability. The set is neither thin nor bloated.
The surface covers proof auditing, tactic help, visualization, conversion, and practice, but lacks broader Lean workflow operations such as general code checking, diagnostics, project/build commands, or declaration/Mathlib search. The inclusion of a very narrow Riemann Hypothesis source-checking tool also makes the coverage feel uneven.
Maintenance
Related MCP Connectors
Lean 4 MCP server: compile, prove theorems, and formalize math with Mathlib.
Primary-source MCP server with epistemic compiler, Audit.lean & offline veriscope-verify CLI.
Render, verify, describe, and safely edit Mermaid diagrams through MCP.
Audit your MCP servers for poisoned tools and leaked secrets, and check AI-generated code for flaws.
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.2262,073 PyPI575MIT
- AlicenseBqualityDmaintenanceMCP server for agentic interaction with the Lean theorem prover via LSP, providing tools for understanding, analyzing, and interacting with Lean projects.2123MIT
- AlicenseNot gradedqualityDmaintenanceEnables verification of Lean 4 mathematical proofs via MCP tools, allowing AI clients to compile and check theorems with Mathlib.37 PyPI2MIT
- 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