Lean LSP

v1.0.0Coding Agentsstable

Enables LLM agents to interact with the Lean theorem prover through the Language Server Protocol, providing tools for analyzing Lean projects, accessing diagnostics, goal states, documentation, and searching for theorems using both local and external

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

What is Lean LSP?

Lean LSP is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to enables llm agents to interact with the lean theorem prover through the language server protocol, providing tools for analyzing lean projects, accessing diagnostics, goal states, documentation, and se...

Enables LLM agents to interact with the Lean theorem prover through the Language Server Protocol, providing tools for analyzing Lean projects, accessing diagnostics, goal states, documentation, and searching for theorems using both local and external

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

Features

  • Enables LLM agents to interact with the Lean theorem prover

Use Cases

Interact with Lean theorem prover.
Access goal states and diagnostics.
Search theorems using LSP.
oOo0oOo

Maintainer

LicenseMIT License
Languagepython
Versionv1.0.0
UpdatedMay 22, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

Manual Installation

npx lean-lsp-mcp

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

lean-lsp-mcp connects AI agents to the Lean 4 theorem prover via the Language Server Protocol, providing a rich set of tools for navigating and proving theorems in Lean projects without leaving the LLM's conversation. It exposes diagnostics, proof goal states, hover documentation, project-wide builds, code execution, and five external theorem-search engines — LeanSearch, Loogle, Lean Finder, Lean Hammer, and Lean State Search — making it practical for AI-assisted formal verification, mathematical proof exploration, and teaching Lean interactively.

Prerequisites

  • Lean 4 installed with elan (https://leanprover.github.io/lean4/doc/setup.html)
  • Python 3.10 or later with the uv package manager (https://docs.astral.sh/uv/)
  • An existing Lean 4 project with a lakefile.lean or lakefile.toml
  • ripgrep installed for the lean_local_search tool (https://github.com/BurntSushi/ripgrep)
  • An MCP-compatible client such as Claude Desktop or Claude Code
1

Add lean-lsp-mcp to Claude Code (simplest method)

Run this command from inside your Lean project directory to register the server with Claude Code. The server will automatically use the current directory as the Lean project root.

claude mcp add lean-lsp uvx lean-lsp-mcp
2

Set the project path environment variable

For HTTP/SSE transport or when the client is not started from the project root, set LEAN_PROJECT_PATH to the directory containing your lakefile.

export LEAN_PROJECT_PATH="/path/to/your/lean-project"
export LEAN_LOG_LEVEL="WARNING"
3

Start the server manually (stdio mode)

Test that the server starts correctly by running it in stdio mode from your project directory.

cd /path/to/your/lean-project
uvx lean-lsp-mcp --transport stdio
4

Configure Claude Desktop

Add the server to ~/Library/Application Support/Claude/claude_desktop_config.json. Set LEAN_PROJECT_PATH to your project directory.

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

Enable REPL mode for faster iteration (optional)

Set LEAN_REPL=true to use the Lean REPL for faster repeated code execution, which avoids full LSP startup overhead for each attempt.

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

Restart the client and verify

Restart Claude Desktop or reload Claude Code. Ask Claude to check the Lean diagnostics for a file — it should invoke the LSP tools and return any errors or goals.

Lean LSP Examples

Client configuration

Claude Desktop config for lean-lsp-mcp with REPL mode and local Loogle enabled.

{
  "mcpServers": {
    "lean-lsp": {
      "command": "uvx",
      "args": ["lean-lsp-mcp"],
      "env": {
        "LEAN_PROJECT_PATH": "/Users/yourname/my-lean4-project",
        "LEAN_LOG_LEVEL": "WARNING",
        "LEAN_REPL": "true",
        "LEAN_LOOGLE_LOCAL": "true"
      }
    }
  }
}

Prompts to try

Example prompts that leverage the LSP tools and theorem search capabilities.

- "Show me all diagnostics (errors and warnings) in MyProof.lean"
- "What is the current proof goal after line 42 in Theorem.lean?"
- "Search LeanSearch for a lemma about the commutativity of natural number addition"
- "Build the entire Lean project and report any compilation errors"
- "Use Loogle to find all theorems that match the pattern 'Nat.add _ _ = Nat.add _ _'"
- "Run the code in this Lean snippet and show me the output: #eval Nat.succ 5"

Troubleshooting Lean LSP

LSP tools return 'project not found' or fail to start the language server

Confirm that LEAN_PROJECT_PATH points to a directory containing a valid lakefile.lean or lakefile.toml, and that 'lake build' runs successfully from that directory. The Lean toolchain must also be installed via elan ('elan show' should list an active toolchain).

lean_local_search returns an error about ripgrep not found

Install ripgrep for your platform ('brew install ripgrep' on macOS, 'apt install ripgrep' on Ubuntu). Alternatively, disable the tool by adding 'lean_local_search' to the LEAN_MCP_DISABLED_TOOLS environment variable.

External search tools (LeanSearch, Loogle) time out or rate-limit

Set LEAN_LOOGLE_LOCAL=true to use a locally hosted Loogle instance if you have one, which avoids rate limits. For LeanSearch, wait and retry — it is a public API with usage limits. Disable specific tools via LEAN_MCP_DISABLED_TOOLS if they are consistently unreliable.

Frequently Asked Questions about Lean LSP

What is Lean LSP?

Lean LSP is a Model Context Protocol (MCP) server that enables llm agents to interact with the lean theorem prover through the language server protocol, providing tools for analyzing lean projects, accessing diagnostics, goal states, documentation, and searching for theorems using both local and external It connects AI assistants to external tools and data sources through a standardized interface.

How do I install Lean LSP?

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

Which AI clients work with Lean LSP?

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

Is Lean LSP free to use?

Yes, Lean LSP is open source and available under the MIT License 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-mcp": { "command": "npx", "args": ["-y", "lean-lsp-mcp"] } } }

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

Read the full setup guide →

Ready to use Lean LSP?

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