lean-lsp-mcp
v0.33.0Lean Theorem Prover MCP
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
lean_build
Build the Lean project and restart LSP. Use only if needed (e.g. new imports).
| Parameter | Type | Description |
|---|---|---|
clean | boolean | Run lake clean first (slow) |
fetch_cache | boolean | Run lake exe cache get before building (slow) |
lean_project_path | Path to Lean project | |
output_lines | integer | Return last N lines of build log (0=none) |
lean_code_actions
Get LSP code actions for a line. Returns resolved edits for TryThis suggestions (simp?, exact?, apply?) and other quick fixes.
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute path to Lean file |
line * | integer | Line number (1-indexed) |
lean_completions
Get IDE autocompletions. Use on INCOMPLETE code (after `.` or partial name).
| Parameter | Type | Description |
|---|---|---|
column * | integer | Column number (1-indexed characters) |
file_path * | string | Absolute or project-root-relative path to Lean file |
line * | integer | Line number (1-indexed) |
max_completions | integer | Max completions |
resolve_details | integer | Fetch type signatures for the top N results |
lean_declaration_file
Get declaration source with the source-line range and surrounding context. Generated declarations include their source declaration when it is clear. Set full_file=True for the whole file (can be very large).
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute or project-root-relative path to Lean file |
symbol * | string | Case-sensitive Lean name in the file or project environment |
context_lines | integer | Lines of context around the declaration |
full_file | boolean | Return the entire declaration file (large!) |
lean_diagnostic_messages
Get compiler diagnostics (errors, warnings, infos) for a Lean file.
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute or project-root-relative path to Lean file |
declaration_name | Filter to declaration (slow) | |
end_line | Filter to line | |
interactive | boolean | Returns verbose nested TaggedText with embedded widgets. Only use when plain text is insufficient. For 'Try This' suggestions, prefer lean_code_actions. |
severity | string | Filter by severity level. Returns all levels when omitted. |
start_line | Filter from line | |
timeout_s | Max seconds to wait for elaboration. On timeout returns partial=true with still_elaborating_lines - poll again. Omit to wait for full elaboration. |
lean_file_outline
Get imports and declarations with type signatures. Token-efficient.
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute or project-root-relative path to Lean file |
max_declarations | Max declarations to return |
lean_get_widget_source
Get JavaScript source of a widget by hash. Useful for understanding custom widget rendering logic. Returns full JS module - may be large.
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute path to Lean file |
javascript_hash * | string | javascriptHash from a widget instance |
lean_get_widgets
Get panel widgets at a position (proof visualizations, #html, custom widgets). Returns raw widget data - may be large.
| Parameter | Type | Description |
|---|---|---|
column * | integer | Column number (1-indexed) |
file_path * | string | Absolute path to Lean file |
line * | integer | Line number (1-indexed) |
lean_goal
Get proof goals at a position. MOST IMPORTANT tool - use often! Omit column to see goals_before (line start) and goals_after (line end), showing how the tactic transforms the state. status='complete' means the proof is finished at this point; status='no_goal_at_position' means the position carries no proof state (e.g. outside a proof).
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute or project-root-relative path to Lean file |
line * | integer | Line number (1-indexed) |
column | Column (1-indexed). Omit for before/after | |
format | string | Output format: 'text' (default) or 'structured' |
timeout_s | Max seconds to wait for elaboration. On timeout returns status='still_elaborating' - poll again. |
lean_hammer_premise
Limit: 6req/30s. Get premise suggestions for automation tactics at a goal position. Returns lemma names to try with `simp only [...]`, `aesop`, or as hints.
| Parameter | Type | Description |
|---|---|---|
column * | integer | Column number (1-indexed) |
file_path * | string | Absolute or project-root-relative path to Lean file |
line * | integer | Line number (1-indexed) |
num_results | integer | Max results |
lean_hover_info
Get type signature and docs for a symbol. Essential for understanding APIs.
| Parameter | Type | Description |
|---|---|---|
column * | integer | Column at START of identifier (1-indexed characters) |
file_path * | string | Absolute or project-root-relative path to Lean file |
line * | integer | Line number (1-indexed) |
lean_leanfinder
Limit: 10req/30s. Semantic search by mathematical meaning via Lean Finder. Examples: "commutativity of addition on natural numbers", "I have h : n < m and need n + 1 < m + 1", proof state text. The `version` argument selects which mathlib snapshot to query (v4.19.0, v4.24.0, or v4.28.0). Default: v4.28.0.
| Parameter | Type | Description |
|---|---|---|
query * | string | Mathematical concept or proof state |
num_results | integer | Max results |
version | string | Mathlib version index to search |
lean_leansearch
Limit: 90req/30s. Search Mathlib via leansearch.net using natural language. Examples: "sum of two even numbers is even", "Cauchy-Schwarz inequality", "{f : A → B} (hf : Injective f) : ∃ g, LeftInverse g f"
| Parameter | Type | Description |
|---|---|---|
query * | string | Natural language or Lean term query |
num_results | integer | Max results |
lean_local_search
Fast local search to verify declarations exist. Use BEFORE trying a lemma name.
| Parameter | Type | Description |
|---|---|---|
query * | string | Declaration name or prefix |
limit | integer | Max matches |
project_root | Project root (inferred if omitted) |
lean_loogle
Search Mathlib by type signature via loogle.lean-lang.org. Examples: `Real.sin`, `"comm"`, `(?a → ?b) → List ?a → List ?b`, `_ * (_ ^ _)`, `|- _ < _ → _ + 1 < _ + 1`
| Parameter | Type | Description |
|---|---|---|
query * | string | Type pattern, constant, or name substring |
num_results | integer | Max results |
lean_minimal_hypotheses
For each explicit `(h : T)` hypothesis of a theorem, drop it and re-elaborate a scratch copy of the file. Reports which hypotheses are load-bearing and which are actually unused. Skips implicit `{x : α}` and instance `[inst : C]` binders (those are usually inferable / always load-bearing). Does not rewrite the proof body — a body that names `h` will fail to elaborate without the binder, which is the truthful answer (load-bearing). Variants are checked in parallel on scratch documents; the file is never edited.
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute path to Lean file |
theorem_name * | string | Theorem name. Either bare (e.g. `add_comm`) or fully qualified (e.g. `Namespace.add_comm`); only the trailing segment is used for source matching. |
inactivity_timeout | number | Per-hypothesis elaboration timeout (seconds) |
lean_multi_attempt
Try multiple tactics without modifying file. Returns goal state for each.
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute or project-root-relative path to Lean file |
line * | integer | Line number (1-indexed) |
snippets * | array | Tactics to try (3+ recommended) |
column | Column (1-indexed). Omit to target the tactic line |
lean_profile_proof
Run `lean --profile` on a theorem. Returns per-line timing and categories. SLOW - avoid on theorems that already hit heartbeat limits.
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute or project-root-relative path to Lean file |
line * | integer | Line where theorem starts (1-indexed) |
timeout | number | Max seconds to wait |
top_n | integer | Number of slowest lines to return |
lean_references
Find all references to a symbol (including the declaration). Position cursor at the symbol.
| Parameter | Type | Description |
|---|---|---|
column * | integer | Column at START of identifier (1-indexed) |
file_path * | string | Absolute path to Lean file |
line * | integer | Line number (1-indexed) |
max_results | Max locations to return (default 50) |
lean_run_code
Run a code snippet and return diagnostics. Must include all imports.
| Parameter | Type | Description |
|---|---|---|
code * | string | Self-contained Lean code with imports |
lean_term_goal
Get the expected type at a position.
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute or project-root-relative path to Lean file |
line * | integer | Line number (1-indexed) |
column | Column (defaults to end of line) |
lean_verify
Check theorem axioms + optional source scan. Only scans the given file, not imports.
| Parameter | Type | Description |
|---|---|---|
file_path * | string | Absolute path to Lean file |
theorem_name * | string | Fully qualified name (e.g. `Namespace.theorem`) |
scan_source | boolean | Scan source file for suspicious patterns |