Lean LSP
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
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
Maintainer
Works with
Installation
Manual Installation
npx lean-lsp-mcpConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
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
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-mcpSet 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"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 stdioConfigure 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"
}
}
}
}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"
}
}
}
}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.
Lean LSP Alternatives — Similar Coding Agents Servers
Looking for alternatives to Lean LSP? Here are other popular coding agents servers you can use with Claude, Cursor, and VS Code.
Dify
★ 142.2kProduction-ready platform for agentic workflow development.
Ruflo
★ 54.0k🌊 The leading agent orchestration platform for Claude. Deploy intelligent multi-agent swarms, coordinate autonomous workflows, and build conversational AI systems. Features enterprise-grade architecture, self-learning swarm intelligence, RAG integrat
Goose
★ 45.7kan open source, extensible AI agent that goes beyond code suggestions - install, execute, edit, and test with any LLM
Antigravity Awesome Skills
★ 38.3kInstallable GitHub library of 1,400+ agentic skills for Claude Code, Cursor, Codex CLI, Gemini CLI, Antigravity, and more. Includes installer CLI, bundles, workflows, and official/community skill collections.
AgentScope
★ 25.5kBuild and run agents you can see, understand and trust.
Serena
★ 24.5kA coding agent toolkit that provides IDE-like semantic code retrieval and editing tools, enabling LLMs to efficiently navigate and modify codebases using symbol-level operations instead of basic file reading and string replacements.
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.
Set Up Lean LSP in Your Editor
Choose your AI client for step-by-step setup instructions.
Quick Config Preview
Add this to your claude_desktop_config.json or .cursor/mcp.json
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.