Labsco
oOo0oOo logo

Lean LSP

β˜… 424

from oOo0oOo

Interact with the Lean theorem prover via the Language Server Protocol (LSP), enabling LLM agents to understand, analyze, and modify Lean projects.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup
<h1 align="center"> lean-lsp-mcp </h1> <h3 align="center">Lean Theorem Prover MCP</h3> <p align="center"> <a href="https://pypi.org/project/lean-lsp-mcp/"> <img src="https://img.shields.io/pypi/v/lean-lsp-mcp.svg" alt="PyPI version" /> </a> <a href=""> <img src="https://img.shields.io/github/last-commit/oOo0oOo/lean-lsp-mcp" alt="last update" /> </a> <a href="https://github.com/oOo0oOo/lean-lsp-mcp/blob/master/LICENSE"> <img src="https://img.shields.io/github/license/oOo0oOo/lean-lsp-mcp.svg" alt="license" /> </a> </p>

MCP server that allows agentic interaction with the Lean theorem prover via the Language Server Protocol using leanclient. This server provides a range of tools for LLM agents to understand, analyze and interact with Lean projects.

Key Features

  • Rich Lean Interaction: Access diagnostics, goal states, term information, hover documentation and more.
  • External Search Tools: Use LeanSearch, Loogle, Lean Finder, Lean Hammer and Lean State Search to find relevant theorems and definitions.
  • Easy Setup: Simple configuration for various clients, including VSCode, Cursor and Claude Code.

MCP Tools

List of available tools

See Tools documentation for the full list of available tools.

Disabling Tools

Many clients allow the user to disable specific tools manually (e.g. lean_build).

VSCode: Click on the Wrench/Screwdriver icon in the chat.

Cursor: In "Cursor Settings" > "MCP" click on the name of a tool to disable it (strikethrough).

You can also disable tools at server startup:

  • LEAN_MCP_DISABLED_TOOLS: Comma-separated tool names (for example lean_run_code,lean_build).
  • LEAN_MCP_INSTRUCTIONS: Replacement server instructions string.
  • LEAN_MCP_TOOL_DESCRIPTIONS: JSON object to override tool descriptions.

Example:

export LEAN_MCP_DISABLED_TOOLS="lean_run_code,lean_build"
export LEAN_MCP_INSTRUCTIONS="Prefer lean_local_search before remote search tools."
export LEAN_MCP_TOOL_DESCRIPTIONS='{"lean_goal":"Primary proof-state inspection tool."}'

Notes on MCP Security

There are many valid security concerns with the Model Context Protocol (MCP) in general!

This MCP server is meant as a research tool and is currently in beta. While it does not handle any sensitive data such as passwords or API keys, it still includes various security risks:

  • Access to your local file system.
  • Powerful local build and analysis capabilities.
  • External network access for remote search tools unless disabled by the operator.

Please be aware of these risks. Feel free to audit the code and report security issues!

Containerized setup (recommended for stricter isolation)

Build image:

docker build -t lean-lsp-mcp:containerized .

Run with a mounted project root (read-only source + writable Lake cache):

docker run --rm -i \
  -v "$PWD":/workspace:ro \
  -v lean-lsp-mcp-lake-cache:/workspace/.lake \
  lean-lsp-mcp:containerized

The included Docker image defaults to:

  • LEAN_PROJECT_PATH=/workspace
  • LEAN_MCP_DISABLED_TOOLS=lean_run_code

Notes:

  • LEAN_MCP_DISABLED_TOOLS is a startup default and can be overridden by docker run -e.
  • Using --network none can break tools that require network access (leansearch, loogle, leanfinder, state_search, hammer_premise) and dependency downloads.
  • The entrypoint exits immediately if LEAN_PROJECT_PATH does not exist.

For more information, you can use Awesome MCP Security as a starting point.

Development

See Adding a new tool for a step-by-step guide to implementing a new MCP tool (return models, helper modules, registration, tests, and docs).

MCP Inspector

npx @modelcontextprotocol/inspector uvx --with-editable path/to/lean-lsp-mcp python -m lean_lsp_mcp.server

Run Tests

uv sync --all-extras
uv run pytest tests

Publications and Formalization Projects using lean-lsp-mcp

  • Ax-Prover: A Deep Reasoning Agentic Framework for Theorem Proving in Mathematics and Quantum Physics arxiv
  • Numina-Lean-Agent: An Open and General Agentic Reasoning System for Formal Mathematics arxiv github
  • MerLean: An Agentic Framework for Autoformalization in Quantum Computation arxiv
  • M2F: Automated Formalization of Mathematical Literature at Scale arxiv
  • A Group-Theoretic Approach to Shannon Capacity of Graphs and a Limit Theorem from Lattice Packings github

Talks

lean-lsp-mcp: Tools for agentic interaction with Lean (Lean Together 2026) youtube

Related Projects