LeanBack
Lean back and let the AI agent write the proof.
Lightweight MCP server for Lean 4 theorem proving. Exposes six tools — project_info, check, prove, goals, eval, search — via the Model Context Protocol, enabling AI assistants to verify proofs, inspect goal states, evaluate expressions, and search Mathlib.
Prerequisites
- Lean 4 with elan (the Lean version manager)
- At least one Lean project (see Project Setup)
Installation
Claude Code
Simply run:
claude mcp add leanback -- uvx leanback
No installation required — uvx automatically downloads and runs LeanBack in an isolated environment.
Other MCP Clients
Any MCP-compatible client can connect. Run uvx leanback as a stdio MCP server, or use --transport sse --port 3000 for HTTP.
Manual Install (optional)
If you prefer a permanent installation:
uv tool install leanback
Project Setup
LeanBack works with any Lean project on disk — just pass its absolute path. To create a new project with Mathlib:
cd /path/to/parent/directory
lake +leanprover-community/mathlib4:lean-toolchain new myproject math
cd myproject
lake exe cache get
This takes a few minutes (downloading precompiled Mathlib). Once done, the project is ready to use.
You can also call project_info(project="/path/to/myproject") to check if a project is properly set up, or to get the exact shell commands to create one.
Tools
All tools require project as an absolute path (e.g., "/home/user/lean/myproject").
project_info
Check project status and get setup instructions. Call this first.
project_info(project="/home/user/lean/myproject")
→ { "valid": true, "lean_version": "...", "has_mathlib": true, "built": true }
If the path doesn't exist, returns setup commands to create the project.
check
Verify Lean code correctness — entire projects, specific files, or expressions.
check(project="/home/user/lean/myproject")
check(project="/home/user/lean/myproject", file="MyProof.lean")
check(project="/home/user/lean/myproject", expr="#check Nat.add", imports=["Mathlib.Tactic"])
Repeated check(file=...) calls on the same file reuse a warm Lean server: the first check pays the import cost, subsequent checks after edits take seconds (as long as the file's import lines are unchanged). Idle servers shut down automatically after 10 minutes; set LEANBACK_NO_WARM=1 to disable warm sessions entirely.
prove
Verify theorem proofs with tactics, or check proof files.
prove(project="/home/user/lean/myproject", theorem="2 + 2 = 4", tactics=["rfl"])
prove(project="/home/user/lean/myproject", theorem="∀ n : Nat, n + 0 = n", tactics=["intro n", "rfl"])
prove(project="/home/user/lean/myproject", theorem="∃ x : Nat, x > 0", tactics=["use 1", "simp"], mathlib=True)
prove(project="/home/user/lean/myproject", file="MyTheorems.lean")
goals
Inspect the proof state during proof construction. See what goals remain after applying tactics.
goals(project="/home/user/lean/myproject", theorem="∀ n : Nat, n + 0 = n")
goals(project="/home/user/lean/myproject", theorem="∀ n : Nat, n + 0 = n", tactics=["intro n"])
goals(project="/home/user/lean/myproject", theorem="True ∧ True", tactics=["constructor"])
eval
Execute Lean expressions and see results.
eval(project="/home/user/lean/myproject", code="#eval 2 + 2")
eval(project="/home/user/lean/myproject", code="#check List.map")
eval(project="/home/user/lean/myproject", code="#eval Nat.gcd 12 18", mathlib=True)
eval(project="/home/user/lean/myproject", code="#eval myFunc 3", imports=["MyProject.Definitions"], build=True)
With build=True, imported modules of the project itself are compiled first (lake build), so they don't need to be built manually before use.
search
Find declarations in Mathlib by pattern.
search(project="/home/user/lean/myproject", pattern="add_comm")
search(project="/home/user/lean/myproject", pattern="reverse", filter_namespace="List")
search(project="/home/user/lean/myproject", batch="add_assoc,mul_assoc,add_comm")
All Tools Are Read-Only
LeanBack never modifies your source files. It only reads project structure and runs Lean to check/evaluate code. File creation and editing is left to your agent's own tools. Two exceptions write build artifacts to the project's .lake directory: eval with build=True runs lake build, and check with file= compiles out-of-date imports of the checked file, as the Lean language server does.
Response Format
All tools return JSON with a success (or valid) boolean. On failure, an error_code and message explain what went wrong. Detailed response schemas are documented in each tool's description (visible to your AI assistant via MCP).
Testing
leanback-test --tool-descriptions
leanback-test --project /path/to/myproject
leanback-test --project /path/to/myproject --tool check
License
Apache 2.0 — see LICENSE.
Metadata
Release files for leanback 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| leanback-0.1.6.tar.gz | 51.4 kB | Without provenance | Details for leanback-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| leanback-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for leanback-0.1.6-py3-none-any.whl |
Total release size: 111.1 kB
Release files / leanback-0.1.6.tar.gz
| Download URL | leanback-0.1.6.tar.gz |
|---|---|
| Size | 51.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3fb77369c3b08b9a0a2b654952b8142c00fae24b87ef6f974bbee5c4e19c8bab
|
|
BLAKE2b-256 checksum How to use checksums |
a1d14a9cf522997784e096194e68fba471c54179342be0eda1b15db39f1d5996
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|
Release files / leanback-0.1.6-py3-none-any.whl
| Download URL | leanback-0.1.6-py3-none-any.whl |
|---|---|
| Size | 59.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f1f72dcada26bc467993e6f4270c878c6541f466c752071f427f1d2c77332a6
|
|
BLAKE2b-256 checksum How to use checksums |
0994440535d42dc8620b0b150dc7b3fa51dd8451325179fbc9a1ef224149479c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|
Security for leanback 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.