Skip to main content

MCP server for Lean 4 theorem proving — check, prove, goals, eval, search

Project description

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"])

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)

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 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.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leanback-0.1.3.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leanback-0.1.3-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

Details for the file leanback-0.1.3.tar.gz.

File metadata

  • Download URL: leanback-0.1.3.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for leanback-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d119f96bc95d22a9e02dbc5968a9f5bec37634d98b7951af70ddbcd9630df1ab
MD5 ff41caec859afd3d8759e6e28522de79
BLAKE2b-256 cef39e4ac926785660d77479c733bfed4ca5cd4cd176029a08d5f420573f55bd

See more details on using hashes here.

File details

Details for the file leanback-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: leanback-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 43.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for leanback-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7f144c4036f248744f7a8297e97c66c27f2cdc041376a9e7f3833dd9a2cda084
MD5 ecb2f0adad77481291b4b50107f3176d
BLAKE2b-256 9a3a153aa295286587ca720f93401defd7afc54757c6499be6fa1b89b522074b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page