lean-mcp
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-mcpverify 'theorem trivial : 1 + 1 = 2 := by decide'"
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.
lean-mcp
MCP server and client for Lean 4 + Mathlib formal theorem verification.
Exposes the Lean 4 compiler as an MCP tool (verify_lean_theorem) via stdio transport, allowing any MCP-compatible AI client (OpenCode, Claude Desktop, Cursor, etc.) to verify mathematical proofs.
Prerequisites
Lean 4 installed via Elan
A Lean 4 project with Mathlib dependency (with
lake buildcompleted)Python 3.10+
Related MCP server: lean-lsp-mcp
Installation
pip install lean-mcpOr install from source:
git clone https://github.com/KrystianYCSilva/lean-mcp.git
cd lean-mcp
pip install -e .Quick Start
Server
Run the MCP server (stdio transport):
LEAN_PROJECT_PATH=/path/to/your/lean4/project lean-mcp-serverClient (Programmatic)
import asyncio
from lean_mcp.client import LeanMCPClient
async def main():
async with LeanMCPClient() as client:
await client.connect(lean_project_path="/path/to/lean4/project")
result = await client.verify(
"theorem modus_ponens (P Q : Prop) (hp : P) (hpq : P -> Q) : Q := hpq hp"
)
print(result) # [QED] Compilacao bem-sucedida. Nenhum erro. Prova completa.
asyncio.run(main())Client Configuration (Claude Desktop, OpenCode, etc.)
Add to your MCP client configuration:
{
"mcpServers": {
"lean-mcp": {
"command": "lean-mcp-server",
"env": {
"LEAN_PROJECT_PATH": "/absolute/path/to/lean4/project"
}
}
}
}Tool: verify_lean_theorem
Parameter | Type | Required | Description |
| string | yes | Lean 4 code to compile. If no |
| int | no | Compilation timeout in seconds (default: 120). |
Return Values
Prefix | Meaning |
| Proof compiles successfully (returncode 0, no output). |
| Compilation error — includes compiler output for debugging. |
| Infrastructure failure (timeout, |
Architecture
MCP Client (any)
|
| stdio (JSON-RPC)
v
lean_mcp/server.py Tool: verify_lean_theorem
|
| subprocess (lake env lean)
v
Lean 4 + Mathlib Formal verifierEnvironment Variables
Variable | Required | Description |
| yes | Absolute path to the Lean 4 project directory containing |
License
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Lean 4 MCP server: compile, prove theorems, and formalize math with Mathlib.
Official DevSpeak MCP server — translate technical text into formal specs from any AI IDE or agent
The OpenZeppelin Solidity Contracts MCP server integrates OpenZeppelin's security and style rules into AI-driven development workflows, enabling AI assistants to generate safe, correct, and production-ready smart contracts. It automatically validates generated code against OpenZeppelin standards (including imports, modifiers, naming conventions, and security checks) and supports various contract types including ERC-20, ERC-721, ERC-1155, Stablecoins, RWA, Governor, and Account contracts through prompt-driven workflows.
MCP-native AI evaluation: rubric audits, eval suites, and proof reports for AI/LLM output.
Related MCP Servers
- AlicenseAqualityDmaintenanceMCP server that gives small LLMs verified symbolic-math & logic tools.62Apache 2.0
- AlicenseBqualityDmaintenanceMCP server for agentic interaction with the Lean theorem prover via LSP, providing tools for understanding, analyzing, and interacting with Lean projects.2121MIT
- AlicenseNot gradedqualityBmaintenanceMCP server that gives LLMs access to formal verification via Z3 and SWI-Prolog, plus tree-sitter-based source code analysis. Translates natural language problems into formal logic using a template-based pipeline, verifies results with mathematical certainty, and analyzes call graphs for reachability, dead code, and impact analysis.26 npm213Apache 2.0
- AlicenseAqualityDmaintenanceAn MCP server that exposes the Prova reasoning verifier, enabling AI agents to verify their own reasoning and kernel-check Lean 4 proofs before outputting answers.5MIT