Skip to main content

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 build completed)
  • Python 3.10+

Installation

pip install lean-mcp

Or 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-server

Client (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
lean_code string yes Lean 4 code to compile. If no import is present, import Mathlib is prepended automatically.
timeout int no Compilation timeout in seconds (default: 120).

Return Values

Prefix Meaning
[QED] Proof compiles successfully (returncode 0, no output).
[FEEDBACK DO COMPILADOR] Compilation error — includes compiler output for debugging.
[ERRO_SISTEMA] Infrastructure failure (timeout, lake not found, etc.).

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 verifier

Environment Variables

Variable Required Description
LEAN_PROJECT_PATH yes Absolute path to the Lean 4 project directory containing lakefile.toml.

License

MIT

Metadata

Release files for lean-mcp 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lean-mcp 0.1.1
File Size Uploaded Provenance
lean_mcp-0.1.1.tar.gz 5.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for lean-mcp 0.1.1
File Interpreter ABI Platform
lean_mcp-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / lean_mcp-0.1.1.tar.gz

Download URL lean_mcp-0.1.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3dc3a0507c41a6a49d8c96f3da53ef6cb99fbeba313c55bf8c1f82878b2bd668
BLAKE2b-256 checksum
How to use checksums
490c3844d7644ad706b6afda401e5bb3d771d3f486822cdb0d3ce1082ac2620e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / lean_mcp-0.1.1-py3-none-any.whl

Download URL lean_mcp-0.1.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1999cc9829d800f9f7ce9838556a15bf1bc42d0e53a70bd495d278b1ce5d419a
BLAKE2b-256 checksum
How to use checksums
b8565d616645e05b4f6a48213275da0ee79bed1ff8ccbcc3c06c9ddd8e67e7e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Security for lean-mcp 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page