Lean Lsp MCP

v1.0.0Coding Agentsstable

Lean Theorem Prover MCP

lean4lspmcp
Share:
382
Stars
0
Downloads
0
Weekly
0/5

What is Lean Lsp MCP?

Lean Lsp MCP is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to lean theorem prover mcp

Lean Theorem Prover MCP

This server falls under the Coding Agents category on MCPgee, the world's largest MCP server directory with 33,000+ servers.

Features

  • Lean Theorem Prover MCP

Use Cases

Query Lean theorem prover.
Access diagnostic information.
Explore mathematical proofs.
oOo0oOo

Maintainer

LicenseMIT
Languagepython
Versionv1.0.0
UpdatedMay 18, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

Manual Installation

npx lean-lsp

Configuration

Configuration Details

Config File

claude_desktop_config.json

Performance

Response Metrics

Response Time< 200ms
ThroughputMedium

Resource Usage

Memory UsageLow
CPU UsageLow

How to Set Up and Use Lean Lsp MCP

The Lean LSP MCP server bridges AI coding assistants with the Lean 4 theorem prover through the Language Server Protocol, enabling real-time diagnostics, goal state inspection, and theorem search from within your AI client. It exposes tools like LeanSearch, Loogle, Lean Finder, and Lean Hammer so agents can locate relevant theorems and definitions, execute Lean code, and validate proofs without leaving the conversation. This is particularly valuable for mathematicians and formal verification engineers who want AI assistance drafting or checking Lean 4 proofs. The server supports REPL mode for fast iterative attempts and can run a local Loogle search index for offline use.

Prerequisites

  • uv package manager installed (curl -LsSf https://astral.sh/uv/install.sh | sh)
  • A Lean 4 project with a lean-toolchain file and lakefile.lean or lakefile.toml
  • Run 'lake build' in your project before starting the server to avoid client timeouts
  • ripgrep (rg) installed for local file search functionality (optional but recommended)
  • An MCP-compatible client such as Claude Desktop, VS Code, Cursor, or Claude Code
1

Install uv package manager

The server is distributed via PyPI and run with uvx, so you need the uv tool installed first.

curl -LsSf https://astral.sh/uv/install.sh | sh
2

Build your Lean project first

Run a full lake build before starting the MCP server. Lean's initial elaboration can be slow and will cause timeout errors if the server has to trigger it during a client request.

cd /path/to/your/lean/project && lake build
3

Add the server to your MCP client

For Claude Code, add the server from the root of your Lean project directory. For other clients, use the JSON configuration in the next step.

claude mcp add lean-lsp uvx lean-lsp-mcp
4

Configure environment variables

Set LEAN_PROJECT_PATH to point to your project root, and optionally set LEAN_LOG_LEVEL and LEAN_MCP_DISABLED_TOOLS to control verbosity and which tools are active. LEAN_REPL=true enables a ~5x faster iterative mode if you add the repl dependency to lakefile.toml.

5

Enable REPL mode for faster iteration (optional)

Add the repl package to your lakefile.toml to unlock LEAN_REPL mode, which dramatically speeds up repeated line-level proof attempts.

require repl from git "https://github.com/leanprover-community/repl" @ "main"
6

Install ripgrep for local search

ripgrep enables the local file search tool so the agent can search through your project's Lean source files by pattern.

brew install ripgrep   # macOS
# or: apt install ripgrep  # Debian/Ubuntu

Lean Lsp MCP Examples

Client configuration

JSON configuration for Claude Desktop or VS Code MCP settings, pointing at the lean-lsp-mcp package with the project path and logging set.

{
  "mcpServers": {
    "lean-lsp": {
      "command": "uvx",
      "args": ["lean-lsp-mcp"],
      "env": {
        "LEAN_PROJECT_PATH": "/path/to/your/lean/project",
        "LEAN_LOG_LEVEL": "NONE",
        "LEAN_REPL": "true"
      }
    }
  }
}

Prompts to try

Example prompts you can send to your AI assistant once the server is connected to a Lean 4 project.

- "What are the current Lean diagnostics for the file Mathlib/Algebra/Group/Basic.lean?"
- "Search LeanSearch for theorems about natural number induction."
- "What is the goal state at line 42 of my current proof?"
- "Run this Lean snippet and show me the output: #check Nat.add_comm"
- "Use Loogle to find theorems with signature `Nat -> Nat -> Prop`"

Troubleshooting Lean Lsp MCP

Client times out when the server starts

This almost always means lake build has not been run. Run 'lake build' in your project root first, then restart the MCP server. Initial Lean elaboration can take several minutes.

Tools like LeanSearch or Loogle return no results

These tools require internet access to reach external backends by default. Set LEAN_LOOGLE_LOCAL=true (Unix only, ~2GB disk, ~5-10 min initial build) if you need offline support, or check that the server process has outbound network access.

LEAN_PROJECT_PATH is not being picked up

Ensure the env key is set correctly in your client config JSON (not as a shell variable). The path must point to the directory containing lean-toolchain, not to a subdirectory or a .lean file.

Frequently Asked Questions about Lean Lsp MCP

What is Lean Lsp MCP?

Lean Lsp MCP is a Model Context Protocol (MCP) server that lean theorem prover mcp It connects AI assistants to external tools and data sources through a standardized interface.

How do I install Lean Lsp MCP?

Follow the installation instructions on the Lean Lsp MCP GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.

Which AI clients work with Lean Lsp MCP?

Lean Lsp MCP works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.

Is Lean Lsp MCP free to use?

Yes, Lean Lsp MCP is open source and available under the MIT license. You can use it freely in both personal and commercial projects.

Browse More Coding Agents MCP Servers

Explore all coding agents servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.

Quick Config Preview

{ "mcpServers": { "lean-lsp": { "command": "npx", "args": ["-y", "lean-lsp"] } } }

Add this to your claude_desktop_config.json or .cursor/mcp.json

Read the full setup guide →

Ready to use Lean Lsp MCP?

Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.

33,000+ ServersFree & Open SourceStep-by-Step Guides