Skip to main content
Glama

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+

Related MCP server: lean-lsp-mcp

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

A
license - permissive license
-
quality - not tested
D
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    A
    maintenance
    MCP 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.
    89
    207
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.

  • AI Reasoning Cache & Consensus Layer with 11 MCP tools via Streamable HTTP.

  • A paid remote MCP for ZeroLang, built to return verdicts, receipts, usage logs, and audit-ready JSON

View all MCP Connectors

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