lean-lsp-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@lean-lsp-mcp Show me the goal state in my current Lean file."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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 HammerandLean State Searchto find relevant theorems and definitions.Easy Setup: Simple configuration for various clients, including VSCode, Cursor and Claude Code.
Related MCP server: prova-mcp
Setup
Overview
Install uv, a Python package manager.
Make sure your Lean project builds quickly by running
lake buildmanually.Configure your IDE/Setup
(Optional, highly recommended) Install ripgrep (
rg) to reduce hallucinations using local search.
1. Install uv
Install uv for your system. On Linux/MacOS: curl -LsSf https://astral.sh/uv/install.sh | sh
2. Run lake build
lean-lsp-mcp will run lake serve in the project root to use the language server (for most tools). Some clients (e.g. Cursor) might timeout during this process. Therefore, it is recommended to run lake build manually before starting the MCP. This ensures a faster build time and avoids timeouts.
3. Configure your IDE/Setup
OR using the setup wizard:
Ctrl+Shift+P > "MCP: Add Server..." > "Command (stdio)" > "uvx lean-lsp-mcp" > "lean-lsp" (or any name you like) > Global or Workspace
OR manually adding config by opening mcp.json with:
Ctrl+Shift+P > "MCP: Open User Configuration"
and adding the following
{
"servers": {
"lean-lsp": {
"type": "stdio",
"command": "uvx",
"args": [
"lean-lsp-mcp"
]
}
}
}If you installed VSCode on Windows and are using WSL2 as your development environment, you may need to use this config instead:
{
"servers": {
"lean-lsp": {
"type": "stdio",
"command": "wsl.exe",
"args": [
"uvx",
"lean-lsp-mcp"
]
}
}
}If that doesn't work, you can try cloning this repository and replace "lean-lsp-mcp" with "/path/to/cloned/lean-lsp-mcp".
"+ Add a new global MCP Server" > ("Create File")
Paste the server config into
mcp.jsonfile:
{
"mcpServers": {
"lean-lsp": {
"command": "uvx",
"args": ["lean-lsp-mcp"]
}
}
}# Local-scoped MCP server
claude mcp add lean-lsp uvx lean-lsp-mcp
# OR project-scoped MCP server
# (creates or updates a .mcp.json file in the current directory)
claude mcp add lean-lsp -s project uvx lean-lsp-mcpYou can find more details about MCP server configuration for Claude Code here.
Claude Skill: Lean4 Theorem Proving
If you are using Claude Desktop or Claude Code, you can also install the Lean4 Theorem Proving Skill. This skill provides additional prompts and templates for interacting with Lean4 projects and includes a section on interacting with the lean-lsp-mcp server.
4. Install ripgrep (optional but recommended)
For the local search tool lean_local_search, install ripgrep (rg) and make sure it is available in your PATH.
MCP Tools
File interactions (LSP)
lean_file_outline
Get a concise outline of a Lean file showing imports and declarations with type signatures (theorems, definitions, classes, structures).
lean_file_contents (DEPRECATED)
Get the contents of a Lean file, optionally with line number annotations.
lean_diagnostic_messages
Get all diagnostic messages for a Lean file. This includes infos, warnings and errors.
l20c42-l20c46, severity: 1
simp made no progress
l21c11-l21c45, severity: 1
function expected at
h_empty
term has type
T ∩ compl T = ∅
...lean_goal
Get the proof goal at a specific location (line or line & column) in a Lean file.
Before:
S : Type u_1
inst✝¹ : Fintype S
inst✝ : Nonempty S
P : Finset (Set S)
hPP : ∀ T ∈ P, ∀ U ∈ P, T ∩ U ≠ ∅
hPS : ¬∃ T ∉ P, ∀ U ∈ P, T ∩ U ≠ ∅
compl : Set S → Set S := fun T ↦ univ \ T
hcompl : ∀ T ∈ P, compl T ∉ P
all_subsets : Finset (Set S) := Finset.univ
h_comp_in_P : ∀ T ∉ P, compl T ∈ P
h_partition : ∀ (T : Set S), T ∈ P ∨ compl T ∈ P
⊢ P.card = 2 ^ (Fintype.card S - 1)
After:
no goalslean_term_goal
Get the term goal at a specific position (line & column) in a Lean file.
lean_hover_info
Retrieve hover information (documentation) for symbols, terms, and expressions in a Lean file (at a specific line & column).
The `sorry` tactic is a temporary placeholder for an incomplete tactic proof,
closing the main goal using `exact sorry`.
This is intended for stubbing-out incomplete parts of a proof while still having a syntactically correct proof skeleton.
Lean will give a warning whenever a proof uses `sorry`, so you aren't likely to miss it,
but you can double check if a theorem depends on `sorry` by looking for `sorryAx` in the output
of the `#print axioms my_thm` command, the axiom used by the implementation of `sorry`.lean_declaration_file
Get the file contents where a symbol or term is declared.
lean_completions
Code auto-completion: Find available identifiers or import suggestions at a specific position (line & column) in a Lean file.
lean_run_code
Run/compile an independent Lean code snippet/file and return the result or error message.
l1c1-l1c6, severity: 3
38lean_multi_attempt
Attempt multiple lean code snippets on a line and return goal state and diagnostics for each snippet. This tool is useful to screen different proof attempts before using the most promising one.
rw [Nat.pow_sub (Fintype.card_pos_of_nonempty S)]:
S : Type u_1
inst✝¹ : Fintype S
inst✝ : Nonempty S
P : Finset (Set S)
hPP : ∀ T ∈ P, ∀ U ∈ P, T ∩ U ≠ ∅
hPS : ¬∃ T ∉ P, ∀ U ∈ P, T ∩ U ≠ ∅
⊢ P.card = 2 ^ (Fintype.card S - 1)
l14c7-l14c51, severity: 1
unknown constant 'Nat.pow_sub'
by_contra h_neq:
S : Type u_1
inst✝¹ : Fintype S
inst✝ : Nonempty S
P : Finset (Set S)
hPP : ∀ T ∈ P, ∀ U ∈ P, T ∩ U ≠ ∅
hPS : ¬∃ T ∉ P, ∀ U ∈ P, T ∩ U ≠ ∅
h_neq : ¬P.card = 2 ^ (Fintype.card S - 1)
⊢ False
...Local Search Tools
lean_local_search
Search for Lean definitions and theorems in the local Lean project and stdlib. This is useful to confirm declarations actually exist and prevent hallucinating APIs.
This tool requires ripgrep (rg) to be installed and available in your PATH.
External Search Tools
Currently most external tools are separately rate limited to 3 requests per 30 seconds. Please don't ruin the fun for everyone by overusing these amazing free services!
Please cite the original authors of these tools if you use them!
lean_leansearch
Search for theorems in Mathlib using leansearch.net (natural language search).
Github Repository | Arxiv Paper
Supports natural language, mixed queries, concepts, identifiers, and Lean terms.
Example:
bijective map from injective,n + 1 <= m if n < m,Cauchy Schwarz,List.sum,{f : A → B} (hf : Injective f) : ∃ h, Bijective h
{
"module_name": "Mathlib.Logic.Function.Basic",
"kind": "theorem",
"name": "Function.Bijective.injective",
"signature": " {f : α → β} (hf : Bijective f) : Injective f",
"type": "∀ {α : Sort u_1} {β : Sort u_2} {f : α → β}, Function.Bijective f → Function.Injective f",
"value": ":= hf.1",
"informal_name": "Bijectivity Implies Injectivity",
"informal_description": "For any function $f \\colon \\alpha \\to \\beta$, if $f$ is bijective, then $f$ is injective."
},
...leansearch_leandex
{'id': 25217,
'primary_declaration': {'lean_name': 'Nat.add'},
'source_file': 'Init/Prelude.lean',
'range_start_line': 1705,
'range_end_line': 1715,
'display_statement_text': '。。。',
'docstring': '...',
'informal_description': '...'},
...lean_loogle
Search for Lean definitions and theorems using loogle.lean-lang.org.
Supports queries by constant, lemma name, subexpression, type, or conclusion.
Example:
Real.sin,"differ",_ * (_ ^ _),(?a -> ?b) -> List ?a -> List ?b,|- tsum _ = _ * tsum _
[
{
"type": " (x : ℝ) : ℝ",
"name": "Real.sin",
"module": "Mathlib.Data.Complex.Trigonometric"
},
...
]lean_leanfinder
Semantic search for Mathlib theorems using Lean Finder.
Supports informal descriptions, user questions, proof states, and statement fragments.
Examples:
algebraic elements x,y over K with same minimal polynomial,Does y being a root of minpoly(x) imply minpoly(x)=minpoly(y)?,⊢ |re z| ≤ ‖z‖+transform to squared norm inequality,theorem restrict Ioi: restrict Ioi e = restrict Ici e
Query: Does y being a root of minpoly(x) imply minpoly(x)=minpoly(y)?
[
[
"/-- If `y : L` is a root of `minpoly K x`, then `minpoly K y = minpoly K x`. -/\ntheorem eq_of_root {x y : L} (hx : IsAlgebraic K x)\n (h_ev : Polynomial.aeval y (minpoly K x) = 0) : minpoly K y = minpoly K x :=\n ((eq_iff_aeval_minpoly_eq_zero hx.isIntegral).mpr h_ev).symm",
"Let $L/K$ be a field extension, and let $x, y \\in L$ be elements such that $y$ is a root of the minimal polynomial of $x$ over $K$. If $x$ is algebraic over $K$, then the minimal polynomial of $y$ over $K$ is equal to the minimal polynomial of $x$ over $K$, i.e., $\\text{minpoly}_K(y) = \\text{minpoly}_K(x)$. This means that if $y$ satisfies the polynomial equation defined by $x$, then $y$ shares the same minimal polynomial as $x$."
],
...
]lean_state_search
Search for applicable theorems for the current proof goal using premise-search.com.
Github Repository | Arxiv Paper
A self-hosted version is available and encouraged. You can set an environment variable LEAN_STATE_SEARCH_URL to point to your self-hosted instance. It defaults to https://premise-search.com.
Uses the first goal at a given line and column. Returns a list of relevant theorems.
[
{
"name": "Nat.mul_zero",
"formal_type": "∀ (n : Nat), n * 0 = 0",
"module": "Init.Data.Nat.Basic"
},
...
]lean_hammer_premise
Search for relevant premises based on the current proof state using the Lean Hammer Premise Search.
Github Repository | Arxiv Paper
A self-hosted version is available and encouraged. You can set an environment variable LEAN_HAMMER_URL to point to your self-hosted instance. It defaults to http://leanpremise.net.
Uses the first goal at a given line and column. Returns a list of relevant premises (theorems) that can be used to prove the goal.
Note: We use a simplified version, LeanHammer might have better premise search results.
[
"MulOpposite.unop_injective",
"MulOpposite.op_injective",
"WellFoundedLT.induction",
...
]Project-level tools
lean_build
Rebuild the Lean project and restart the Lean LSP server.
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).
MCP Configuration
This MCP server works out-of-the-box without any configuration. However, a few optional settings are available.
Environment Variables
LEAN_LOG_LEVEL: Log level for the server. Options are "INFO", "WARNING", "ERROR", "NONE". Defaults to "INFO".LEAN_PROJECT_PATH: Path to your Lean project root. Set this if the server cannot automatically detect your project.LEAN_LSP_MCP_TOKEN: Secret token for bearer authentication when usingstreamable-httporssetransport.LEAN_STATE_SEARCH_URL: URL for a self-hosted premise-search.com instance.LEAN_HAMMER_URL: URL for a self-hosted Lean Hammer Premise Search instance.
You can also often set these environment variables in your MCP client configuration:
{
"servers": {
"lean-lsp": {
"type": "stdio",
"command": "uvx",
"args": [
"lean-lsp-mcp"
],
"env": {
"LEAN_PROJECT_PATH": "/path/to/your/lean/project",
"LEAN_LOG_LEVEL": "NONE"
}
}
}
}Transport Methods
The Lean LSP MCP server supports the following transport methods:
stdio: Standard input/output (default)streamable-http: HTTP streamingsse: Server-sent events (MCP legacy, usestreamable-httpif possible)
You can specify the transport method using the --transport argument when running the server. For sse and streamable-http you can also optionally specify the host and port:
uvx lean-lsp-mcp --transport stdio # Default transport
uvx lean-lsp-mcp --transport streamable-http # Available at http://127.0.0.1:8000/mcp
uvx lean-lsp-mcp --transport sse --host localhost --port 12345 # Available at http://localhost:12345/sseBearer Token Authentication
Transport via streamable-http and sse supports bearer token authentication. This allows publicly accessible MCP servers to restrict access to authorized clients.
Set the LEAN_LSP_MCP_TOKEN environment variable (or see section 3 for setting env variables in MCP config) to a secret token before starting the server.
Example Linux/MacOS setup:
export LEAN_LSP_MCP_TOKEN="your_secret_token"
uvx lean-lsp-mcp --transport streamable-httpClients should then include the token in the Authorization header.
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.
No input or output validation.
Please be aware of these risks. Feel free to audit the code and report security issues!
For more information, you can use Awesome MCP Security as a starting point.
Development
MCP Inspector
npx @modelcontextprotocol/inspector uvx --with-editable path/to/lean-lsp-mcp python -m lean_lsp_mcp.serverRun Tests
uv sync --all-extras
uv run pytest testsPublications using lean-lsp-mcp
Ax-Prover: A Deep Reasoning Agentic Framework for Theorem Proving in Mathematics and Quantum Physics arxiv
Related Projects
License & Citation
MIT licensed. See LICENSE for more information.
Citing this repository is highly appreciated but not required by the license.
@software{lean-lsp-mcp,
author = {Oliver Dressler},
title = {{Lean LSP MCP: Tools for agentic interaction with the Lean theorem prover}},
url = {https://github.com/oOo0oOo/lean-lsp-mcp},
month = {3},
year = {2025}
}Available Tools
21 toolsdiscussion_partnerA
Use this tool to interact with a specialized partner model for proof strategies, reasoning, and formalization.
You can send Lean 4 code, natural language math problems, or proof strategies to different models
and get their suggestions. This is useful for:
- Discussing proof strategies and approaches
- Getting alternative reasoning paths
- Comparing suggestions from different models
- Debugging stuck proofs
Args:
question (str): Lean code, math problem, or any question you want to discuss.
model (str): Choose "gemini" (Google gemini-3-pro-preview) or "gpt" (OpenAI gpt-5.2-pro). Default is "gemini".
Returns:
str: The model's response.
Inputs: question (required), model. Returns: result
gemini_code_golfC
This tool uses the Google Gemini model to simplify Lean code compiled by the compiler.
It uses Google's Gemini API to generate text responses. You need to set the GOOGLE_API_KEY environment variable.
Args:
lean_code (str, optional): The lean code to be golfed.
model (str, optional): The Gemini model to use. The default is "gemini-3-pro-preview".
temperature (float, optional): The generated temperature, controlling randomness. The default is 0.7.
Returns:
str: Gemini model response or error message
Inputs: lean_code (required), model, temperature. Returns: result
gemini_informal_proverA
Use Google Gemini model to solve math problems and provide detailed solution.
This tool takes a raw math problem string, solves it, and explains the reasoning step-by-step.
Gemini's math skills are outstanding; you can trust the answers he gives you.
Use this tool frequently for natural language math problems.
You should mention that you’re aiming to formalize the solution in Lean 4, and ask Gemini for a detailed solution that would be easier to formalize.
Once you receive Gemini’s solution, use leandex to search mathlib for relevant theorems and lemmas.
If you discover that some necessary infrastructure is missing in mathlib, immediately switch to informal_prover: provide it with Gemini’s solution, explain what is missing, and ask it to propose an alternative approach that avoids those gaps or requires less infrastructure.
Args:
math_problem (str): The detailed text description of the math problem.
model (str, optional): The Gemini model to use. The default is "gemini-3-pro-preview".
temperature (float, optional): The generated temperature, controlling randomness. The default is 0.7.
Returns:
List[str]: [solution, verification_result] where solution is the step-by-step explanation and verification_result is the Gemini verification judgment.
Inputs: math_problem (required), model, temperature. Returns: result
gpt_informal_proverB
Use OpenAI GPT model to solve math problems and provide detailed solution.
This tool takes a raw math problem string, solves it, and explains the reasoning step-by-step.
GPT's math skills are outstanding; you can trust the answers he gives you.
Use this tool frequently for natural language math problems.
You should mention that you’re aiming to formalize the solution in Lean 4, and ask Gemini for a detailed solution that would be easier to formalize.
Once you receive Gemini’s solution, use leandex to search mathlib for relevant theorems and lemmas.
If you discover that some necessary infrastructure is missing in mathlib, immediately switch to informal_prover: provide it with Gemini’s solution, explain what is missing, and ask it to propose an alternative approach that avoids those gaps or requires less infrastructure.
Args:
math_problem (str): The detailed text description of the math problem.
model (str, optional): The GPT model to use. The default is "gpt-5.2-pro".
temperature (float, optional): The generated temperature, controlling randomness. The default is 0.7.
Returns:
List[str]: [solution, verification_result] where solution is the step-by-step explanation and verification_result is the GPT verification judgment.
Inputs: math_problem (required), model, temperature. Returns: result
lean_buildA
Build the Lean project and restart the LSP Server.
Use only if needed (e.g. new imports).
Args:
lean_project_path (str, optional): Path to the Lean project. If not provided, it will be inferred from previous tool calls.
clean (bool, optional): Run `lake clean` before building. Attention: Only use if it is really necessary! It can take a long time! Defaults to False.
Returns:
str: Build output or error msg
Inputs: clean, lean_project_path. Returns: result
lean_completionsA
Get code completions at a location in a Lean file.
Only use this on INCOMPLETE lines/statements to check available identifiers and imports:
- Dot Completion: Displays relevant identifiers after a dot (e.g., `Nat.`, `x.`, or `Nat.ad`).
- Identifier Completion: Suggests matching identifiers after part of a name.
- Import Completion: Lists importable files after `import` at the beginning of a file.
Args:
file_path (str): Abs path to Lean file
line (int): Line number (1-indexed)
column (int): Column number (1-indexed)
max_completions (int, optional): Maximum number of completions to return. Defaults to 32
Returns:
str: List of possible completions or error msg
Inputs: line (required), column (required), file_path (required), max_completions. Returns: result
lean_declaration_fileA
Get the file contents where a symbol/lemma/class/structure is declared.
Note:
Symbol must be present in the file! Add if necessary!
Lean files can be large, use `lean_hover_info` before this tool.
Args:
file_path (str): Abs path to Lean file
symbol (str): Symbol to look up the declaration for. Case sensitive!
Returns:
str: File contents or error msg
Inputs: symbol (required), file_path (required). Returns: result
lean_diagnostic_messagesA
Get all diagnostic msgs (errors, warnings, infos) for a Lean file.
"no goals to be solved" means code may need removal.
Args:
file_path (str): Abs path to Lean file
Returns:
List[str] | str: Diagnostic msgs or error msg
Inputs: file_path (required). Returns: result
lean_file_contentsA
DEPRECATED: Will be removed soon.
Get the text contents of a Lean file, optionally with line numbers.
Use sparingly (bloats context). Mainly when unsure about line numbers.
Args:
file_path (str): Abs path to Lean file
annotate_lines (bool, optional): Annotate lines with line numbers. Defaults to True.
Returns:
str: File content or error msg
Inputs: file_path (required), annotate_lines. Returns: result
lean_file_outlineA
Get a concise outline showing imports and declarations with type signatures (theorems, defs, classes, structures).
Highly useful and token-efficient. Slow-ish.
Args:
file_path (str): Abs path to Lean file
Returns:
str: Markdown formatted outline or error msg
Inputs: file_path (required). Returns: result
lean_goalA
Get the proof goals (proof state) at a specific location in a Lean file.
VERY USEFUL! Main tool to understand the proof state and its evolution!
Returns "no goals" if solved.
To see the goal at sorry, use the cursor before the "s".
Avoid giving a column if unsure-default behavior works well.
Args:
file_path (str): Abs path to Lean file
line (int): Line number (1-indexed)
column (int, optional): Column number (1-indexed). Defaults to None => Both before and after the line.
Returns:
str: Goal(s) or error msg
Inputs: line (required), file_path (required), column. Returns: result
lean_hammer_premiseA
Limit: 3req/30s. Search for premises based on proof state using the lean hammer premise search.
Args:
file_path (str): Abs path to Lean file
line (int): Line number (1-indexed)
column (int): Column number (1-indexed)
num_results (int, optional): Max results. Defaults to 32.
Returns:
List[str] | str: List of relevant premises or error message
Inputs: line (required), column (required), file_path (required), num_results. Returns: result
lean_hover_infoA
Get hover info (docs for syntax, variables, functions, etc.) at a specific location in a Lean file.
Args:
file_path (str): Abs path to Lean file
line (int): Line number (1-indexed)
column (int): Column number (1-indexed). Make sure to use the start or within the term, not the end.
Returns:
str: Hover info or error msg
Inputs: line (required), column (required), file_path (required). Returns: result
lean_leandexA
Search for theorems and definitions using leandex.
Leandex is a semantic search engine for Lean codebases.
It uses a combination of natural language processing and machine learning to search for theorems and definitions.
It's recommended to use leandex to search whether there exist relevant results before you start to prove a somewhat classic goal.
It's a good practice to query for more general / specific results and then use the results to refine the query if you failed to find the desired results.
You can also use leandex to check the definition of a term or a concept.
Query patterns:
- Natural language: "If there exist injective maps of sets from A to B and from B to A, then there exists a bijective map between A and B."
- Mixed natural/Lean: "natural numbers. from: n < m, to: n + 1 < m + 1", "n + 1 <= m if n < m"
- Concept names: "Cauchy Schwarz"
- Lean identifiers: "List.sum", "Finset induction"
- Lean term: "{f : A → B} {g : B → A} (hf : Injective f) (hg : Injective g) : ∃ h, Bijective h"
Args:
query (str): Search query
num_results (int, optional): Max results. Defaults to 5.
Returns:
List[Dict] | str: Search results or error msg
Inputs: query (required), num_results. Returns: result
lean_leanfinderA
Limit: 10req/30s. Search Mathlib theorems/definitions semantically by mathematical concept or proof state using Lean Finder.
Effective query types:
- Natural language mathematical statement: "For any natural numbers n and m, the sum n+m is equal to m+n."
- Natural language questions: "I'm working with algebraic elements over a field extension … Does this imply that the minimal polynomials of x and y are equal?"
- Proof state. For better results, enter a proof state followed by how you want to transform the proof state.
- Statement definition: Fragment or the whole statement definition.
Tips: Multiple targeted queries beat one complex query.
Args:
query (str): Mathematical concept or proof state
num_results (int, optional): Max results. Defaults to 5.
Returns:
List[Dict] | str: List of Lean statement objects (full name, formal statement, informal statement) or error msg
Inputs: query (required), num_results. Returns: result
lean_local_searchA
Confirm declarations exist in the current workspace to prevent hallucinating APIs.
VERY USEFUL AND FAST!
Pass a short prefix (e.g. ``map_mul``); the metadata shows the declaration kind and file.
The index spans theorems, lemmas, defs, classes, instances, structures, inductives, abbrevs, and opaque decls.
Args:
query (str): Declaration name or prefix.
limit (int): Max matches to return (default 10).
Returns:
List[Dict[str, str]] | str: Matches as ``{"name", "kind", "file"}`` or error message.
Inputs: query (required), limit, project_root. Returns: result
lean_loogleA
Limit: 3req/30s. Search for definitions and theorems using loogle.
Query patterns:
- By constant: Real.sin # finds lemmas mentioning Real.sin
- By lemma name: "differ" # finds lemmas with "differ" in the name
- By subexpression: _ * (_ ^ _) # finds lemmas with a product and power
- Non-linear: Real.sqrt ?a * Real.sqrt ?a
- By type shape: (?a -> ?b) -> List ?a -> List ?b
- By conclusion: |- tsum _ = _ * tsum _
- By conclusion w/hyps: |- _ < _ → tsum _ < tsum _
Args:
query (str): Search query
num_results (int, optional): Max results. Defaults to 8.
Returns:
List[dict] | str: Search results or error msg
Inputs: query (required), num_results. Returns: result
lean_multi_attemptA
Try multiple Lean code snippets at a line and get the goal state and diagnostics for each.
Use to compare tactics or approaches.
Use rarely-prefer direct file edits to keep users involved.
For a single snippet, edit the file and run `lean_diagnostic_messages` instead.
Note:
Only single-line, fully-indented snippets are supported.
Avoid comments for best results.
Args:
file_path (str): Abs path to Lean file
line (int): Line number (1-indexed)
snippets (List[str]): List of snippets (3+ are recommended)
Returns:
List[str] | str: Diagnostics and goal states or error msg
Inputs: line (required), snippets (required), file_path (required). Returns: result
lean_run_codeA
Run a complete, self-contained code snippet and return diagnostics.
Has to include all imports and definitions!
Only use for testing outside open files! Keep the user in the loop by editing files instead.
Args:
code (str): Code snippet
Returns:
List[str] | str: Diagnostics msgs or error msg
Inputs: code (required). Returns: result
lean_state_searchA
Limit: 3req/30s. Search for theorems based on proof state using premise-search.com.
Only uses first goal if multiple.
Args:
file_path (str): Abs path to Lean file
line (int): Line number (1-indexed)
column (int): Column number (1-indexed)
num_results (int, optional): Max results. Defaults to 5.
Returns:
List | str: Search results or error msg
Inputs: line (required), column (required), file_path (required), num_results. Returns: result
lean_term_goalA
Get the expected type (term goal) at a specific location in a Lean file.
Args:
file_path (str): Abs path to Lean file
line (int): Line number (1-indexed)
column (int, optional): Column number (1-indexed). Defaults to None => end of line.
Returns:
str: Expected type or error msg
Inputs: line (required), file_path (required), column. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 21 tools
Multiple search tools (lean_local_search, lean_leandex, lean_loogle, lean_leanfinder, lean_state_search, lean_hammer_premise) have overlapping purposes, differentiated only by backend or exact query type. The informal prover tools (gemini_informal_prover, gpt_informal_prover, discussion_partner) are nearly interchangeable, causing boundary confusion.
The core tools consistently use the lean_ prefix, but the AI tools break the pattern with gemini_, gpt_, and discussion_partner. Verb-noun and noun-only names are mixed (e.g., lean_build vs lean_goal), creating moderate inconsistency.
At 21 tools, the server is on the heavy side but each tool serves a niche purpose. The count is justified by the breadth of Lean development and search needs, though some redundancy inflates the count.
Core Lean workflows are well covered: file outline, diagnostics, goals, hover, completions, build, and run code. Search is extensive, and AI integrations fill the gap for proof strategy. Missing direct file editing is minor since edits happen outside the server.
Maintenance
Related MCP Connectors
Lean 4 MCP server: compile, prove theorems, and formalize math with Mathlib.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
MCP server for generating rough-draft project plans from natural-language prompts.
Related MCP Servers
- AlicenseBqualityAmaintenanceEnables 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 search services.2214,779 PyPI549MIT
- AlicenseAqualityDmaintenanceAn MCP server that exposes the Prova reasoning verifier, enabling AI agents to verify their own reasoning and kernel-check Lean 4 proofs before outputting answers.5MIT
- AlicenseNot gradedqualityDmaintenanceMCP server that bridges LLMs with the Rocq (Coq) proof assistant via LSP, enabling interactive theorem proving with AI.10Apache 2.0
- AlicenseNot gradedqualityBmaintenanceAn MCP server that exposes LSP-backed code navigation and editing tools to LLM agents using a single global config file to route file extensions to language servers.1MIT