lean4-mcp
# `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](https://leanproofs.com/playground?lesson=first-proof&tutor=1)**.
---
## Quick Setup
### Clone once
```bash
git clone https://github.com/wxyshihxs/lean4-mcp.git
```
### VS Code (`.vscode/mcp.json`)
```json
{
"servers": {
"lean4-mcp": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/lean4-mcp/src/server.mjs"]
}
}
}
```
### Cursor / Claude Desktop (`claude_desktop_config.json`)
```json
{
"mcpServers": {
"lean4-mcp": {
"command": "node",
"args": ["/absolute/path/to/lean4-mcp/src/server.mjs"]
}
}
}
```
### Claude Code
```bash
claude mcp add lean4-mcp -- node /absolute/path/to/lean4-mcp/src/server.mjs
```
---
## Example: Mermaid Proof Dependency Graph (`visualize_proof_outline`)
Given a Lean 4 file with lemmas and theorems, `visualize_proof_outline` returns:
```mermaid
flowchart TD
base["lemma base"]
main_thm["theorem main_thm"]
main_thm --> base
```
---
## Run Tests
```bash
cd lean4-mcp
npm test
```
## License
MIT License.
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.