Skip to main content
Glama

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

audit_lean_proof

Scans any Lean 4 snippet for sorry, admit, custom axiom, unsafe, and @[implemented_by] (plus optional local lean compilation).

visualize_proof_outline

Parses theorem / lemma / def / axiom declarations and outputs a Mermaid flowchart TD dependency graph for instant visual exploration in VS Code / Markdown.

convert_lean_unicode

Converts Lean 4 ASCII escapes (\forall, \to, \and, \N, \<...\>) ↔ Unicode (∀, →, ∧, ℕ, ⟨...⟩).

explain_lean_tactic

Instant before/after goal-state cheat-sheet for 14 core Lean 4 tactics (rfl, rw, intro, apply, exact, constructor, cases, induction, simp, ...).

get_lean_practice_drill

Returns structured beginner/intermediate Lean 4 exercises with starter code, hints, and 1-click zero-install browser links.

check_rh_2026_sources

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.git

VS 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.mjs

Related 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 --> base

Run Tests

cd lean4-mcp
npm test

License

MIT License.

Available Tools

6 tools
audit_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

    A3.7/5.0

    Scored across 6 tools

    Disambiguation5/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness3/5

    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

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      B
      maintenance
      Enables 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.
      22
      62,073 PyPI
      575
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables 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.
      3
      MIT