lean-mcp

lean-mcp

Enables verification of Lean 4 mathematical proofs via MCP tools, allowing AI clients to compile and check theorems with Mathlib.

Category
Visit Server

README

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured