lean-mcp
Click on "Install 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: math-logic-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 installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/KrystianYCSilva/lean-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server