leanforge-mcp
Provides local LLM integration via Ollama using the deepseek-prover-v2:7b model for tier-1 proof search, enabling free local proof generation.
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., "@leanforge-mcpProve that the sum of the first n natural numbers is n*(n+1)/2"
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.
leanforge-mcp
MCP server for AI-driven formal proof search in Lean 4. Submit a theorem with sorry; get back a machine-verified proof. Implements Agent A from AlphaProof Nexus (DeepMind, May 2026).
Stack: Python 3.12+ . FastMCP 3.4+ . FastAPI . React/Vite . Tailwind . Lean 4 / Mathlib
Table of Contents
Related MCP server: Lean LSP MCP
What it does
Feed it a Lean 4 theorem with a sorry placeholder. It runs N parallel agents in a loop: the LLM proposes a proof edit, the Lean compiler judges it, errors feed back to the LLM. First agent to produce a sorry-free compile wins.
-- Input
theorem sum_formula (n : ℕ) : 2 * ∑ i ∈ Finset.range (n + 1), i = n * (n + 1) := by
sorry
-- Output (machine-verified)
theorem sum_formula (n : ℕ) : 2 * ∑ i ∈ Finset.range (n + 1), i = n * (n + 1) := by
induction n with
| zero => simp
| succ n ih => rw [Finset.sum_range_succ]; ring_nf; linarithThe compiler is the only oracle -- if it compiles without sorry, the proof is correct.
Quick Install
git clone https://github.com/sandraschi/leanforge-mcp
cd leanforge-mcp
uv sync
Copy-Item config.example.toml config.tomlThen add to claude_desktop_config.json:
{
"mcpServers": {
"leanforge": {
"command": "uv",
"args": ["--directory", "C:\\path\\to\\leanforge-mcp", "run", "python", "-m", "leanforge_mcp"],
"env": { "DEEPSEEK_API_KEY": "...", "ANTHROPIC_API_KEY": "..." }
}
}
}See INSTALL.md for the Lean + Mathlib workspace setup (~4GB, one-time -- already provisioned and verified on Goliath as of 2026-07-09).
What You Can Do
"Prove that the sum of the first n natural numbers is n*(n+1)/2"
"Submit this MiniF2F problem and check back in 10 minutes"
"Show me all the proof attempts for job abc-123 -- why is it stuck?"
"Run validate_lean on this tactic proof to see if it compiles"Tools
Tool | Description |
| Submit a theorem statement → job ID (async) |
| Submit a full |
| Poll job status; returns proof when complete |
| Inspect the attempt trajectory per agent/turn |
| List all jobs with status summary |
| Raw Lean 4 compile -- no job tracking |
| Cancel a running job |
| Natural language search over Mathlib theorems |
Requirements
Python 3.11+
Lean 4 via elan (
winget install leanprover.elan)Mathlib workspace with cached oleans (~4GB, one-time setup -- see INSTALL.md)
Ollama with
deepseek-prover-v2:7bfor tier-1 (local, free)DeepSeek or Anthropic API key for tier-2/3 (optional)
Documentation
Doc | Contents |
Prerequisites, Lean workspace setup, Claude Desktop config | |
All config options and environment variables | |
Full tool reference with parameters and examples | |
Proof loop, tier escalation, job lifecycle, SQLite schema | |
Lean 4 language reference, tactic guide, bibliography, link collection | |
Quick Lean 4 intro for engineers (short version) | |
The technique: AlphaProof Nexus paper explained | |
Why DeepMind got MSM coverage and a startup wouldn't | |
MiniF2F, PutnamBench, Erdős results | |
Contributing, dev setup, test commands | |
Common errors and fixes |
Roadmap
Phase | What | Status |
A | Core loop: LLM proposes, Lean judges, error feeds back | Done |
B | Correctness hardening, edge case handling, timeout tuning | Done (2026-07-09) -- tamper guard closed against default-arg truncation and a decoy-duplicate attack, cross-process job ownership/cancellation fixed, stateless-prompting mitigations added. 56/56 tests passing on real hardware. See docs/ASSESSMENT_2026-06-24.md |
C | Performance and safety: REPL worker pool (compile-time is the real bottleneck), LLM timeout/retry, token/cost accounting (hard gate before any batch run) | In progress -- see TODO.md |
D | Multi-agent parallel scheduling (Agent B from paper) -- run N loops in parallel, first to finish wins | Planned |
E | Self-critique step -- LLM reviews its own proof before compile, catches obvious errors early | Planned |
F | Webapp proof explorer -- interactive tree view of attempted proof paths, live tactic streaming | Planned |
G | Premise selection -- before generating tactics, search Mathlib for relevant lemmas | Planned |
H | Cumulative context windowing -- smart summarization of long error chains instead of blind concatenation | Planned |
I | Benchmark dashboard -- webapp page tracking MiniF2F, PutnamBench, Erdős results per model/config | Stretch |
J | Human-in-the-loop -- when the agent is stuck, pause and surface the current state for a human hint | Stretch |
K | Proof caching -- deduplicate sub-proofs so repeated lemmas compile instantly | Stretch |
What each phase enables
A + B let you submit a theorem and get a proof back on the other end. It works, it's useful, but it's single-threaded, pays a full compile per turn, and has no spend controls -- Phase C closes those gaps.
D changes the game: N parallel agents means wall-clock time drops from "however long one LLM takes" to "however long the fastest of N LLMs takes." For hard theorems where the LLM wanders into dead ends, this is the difference between 5 minutes and 30 seconds.
E prevents the LLM from wasting compiles on obviously wrong tactics. Cheap to add (one extra LLM call per attempt) and the paper shows it improves solve rate by ~15 percentage points on Agent A alone.
F is the user-facing payoff: instead of staring at "status: running" and polling, you watch the LLM try tactics in real time, see which paths it abandoned, and understand why it eventually succeeded or failed.
G addresses the most common failure mode: the LLM writes a correct tactic for a lemma that doesn't exist in the current context. Premise selection (a small retrieval step before tactic generation) cuts this dramatically.
H is invisible but critical: as the LLM accumulates 10+ failed attempts, the error context grows past the model's window. Smart summarization keeps relevant signal without drowning the LLM in noise.
Full gap analysis: docs/ASSESSMENT_2026-06-24.md
License
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Search, reuse, verify AI reasoning. Task marketplace with leaderboard. Zero-barrier, no auth.
Search arXiv/Semantic Scholar/OpenAlex + medical evidence (PubMed/Europe PMC) + LaTeX/PDF tools.
Ingest and search LogsLoom logs from coding agents.
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Related MCP Servers
- FlicenseBqualityDmaintenanceEnables LLMs to prove theorems in Lean and formalize mathematical problems using the Aristotle API, supporting both formal Lean code and natural language problem submissions.61-
- AlicenseAqualityAmaintenanceEnables 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.2272,807 PyPI522MIT
- FlicenseNot gradedqualityDmaintenanceIntegrates the AXLE (Axiom Lean Engine) CLI with AI assistants to provide comprehensive tools for Lean 4 proof engineering. It enables users to validate, repair, and transform Lean theorems through a remote API without requiring a local Lean installation.2-
- AlicenseNot gradedqualityDmaintenanceEnables verification of Lean 4 mathematical proofs via MCP tools, allowing AI clients to compile and check theorems with Mathlib.1MIT