lean-lsp-mcp

v0.33.0
lean-lsp-mcp Checked 11 hours ago Published 27 days ago

Lean 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).

ParameterTypeDescription
cleanbooleanRun lake clean first (slow)
fetch_cachebooleanRun lake exe cache get before building (slow)
lean_project_pathPath to Lean project
output_linesintegerReturn 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.

ParameterTypeDescription
file_path *stringAbsolute path to Lean file
line *integerLine number (1-indexed)

lean_completions

Get IDE autocompletions. Use on INCOMPLETE code (after `.` or partial name).

ParameterTypeDescription
column *integerColumn number (1-indexed characters)
file_path *stringAbsolute or project-root-relative path to Lean file
line *integerLine number (1-indexed)
max_completionsintegerMax completions
resolve_detailsintegerFetch 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).

ParameterTypeDescription
file_path *stringAbsolute or project-root-relative path to Lean file
symbol *stringCase-sensitive Lean name in the file or project environment
context_linesintegerLines of context around the declaration
full_filebooleanReturn the entire declaration file (large!)

lean_diagnostic_messages

Get compiler diagnostics (errors, warnings, infos) for a Lean file.

ParameterTypeDescription
file_path *stringAbsolute or project-root-relative path to Lean file
declaration_nameFilter to declaration (slow)
end_lineFilter to line
interactivebooleanReturns verbose nested TaggedText with embedded widgets. Only use when plain text is insufficient. For 'Try This' suggestions, prefer lean_code_actions.
severitystringFilter by severity level. Returns all levels when omitted.
start_lineFilter from line
timeout_sMax 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.

ParameterTypeDescription
file_path *stringAbsolute or project-root-relative path to Lean file
max_declarationsMax 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.

ParameterTypeDescription
file_path *stringAbsolute path to Lean file
javascript_hash *stringjavascriptHash 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.

ParameterTypeDescription
column *integerColumn number (1-indexed)
file_path *stringAbsolute path to Lean file
line *integerLine 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).

ParameterTypeDescription
file_path *stringAbsolute or project-root-relative path to Lean file
line *integerLine number (1-indexed)
columnColumn (1-indexed). Omit for before/after
formatstringOutput format: 'text' (default) or 'structured'
timeout_sMax 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.

ParameterTypeDescription
column *integerColumn number (1-indexed)
file_path *stringAbsolute or project-root-relative path to Lean file
line *integerLine number (1-indexed)
num_resultsintegerMax results

lean_hover_info

Get type signature and docs for a symbol. Essential for understanding APIs.

ParameterTypeDescription
column *integerColumn at START of identifier (1-indexed characters)
file_path *stringAbsolute or project-root-relative path to Lean file
line *integerLine 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.

ParameterTypeDescription
query *stringMathematical concept or proof state
num_resultsintegerMax results
versionstringMathlib 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"

ParameterTypeDescription
query *stringNatural language or Lean term query
num_resultsintegerMax results

lean_loogle

Search Mathlib by type signature via loogle.lean-lang.org. Examples: `Real.sin`, `"comm"`, `(?a → ?b) → List ?a → List ?b`, `_ * (_ ^ _)`, `|- _ < _ → _ + 1 < _ + 1`

ParameterTypeDescription
query *stringType pattern, constant, or name substring
num_resultsintegerMax 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.

ParameterTypeDescription
file_path *stringAbsolute path to Lean file
theorem_name *stringTheorem 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_timeoutnumberPer-hypothesis elaboration timeout (seconds)

lean_multi_attempt

Try multiple tactics without modifying file. Returns goal state for each.

ParameterTypeDescription
file_path *stringAbsolute or project-root-relative path to Lean file
line *integerLine number (1-indexed)
snippets *arrayTactics to try (3+ recommended)
columnColumn (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.

ParameterTypeDescription
file_path *stringAbsolute or project-root-relative path to Lean file
line *integerLine where theorem starts (1-indexed)
timeoutnumberMax seconds to wait
top_nintegerNumber of slowest lines to return

lean_references

Find all references to a symbol (including the declaration). Position cursor at the symbol.

ParameterTypeDescription
column *integerColumn at START of identifier (1-indexed)
file_path *stringAbsolute path to Lean file
line *integerLine number (1-indexed)
max_resultsMax locations to return (default 50)

lean_run_code

Run a code snippet and return diagnostics. Must include all imports.

ParameterTypeDescription
code *stringSelf-contained Lean code with imports

lean_term_goal

Get the expected type at a position.

ParameterTypeDescription
file_path *stringAbsolute or project-root-relative path to Lean file
line *integerLine number (1-indexed)
columnColumn (defaults to end of line)

lean_verify

Check theorem axioms + optional source scan. Only scans the given file, not imports.

ParameterTypeDescription
file_path *stringAbsolute path to Lean file
theorem_name *stringFully qualified name (e.g. `Namespace.theorem`)
scan_sourcebooleanScan source file for suspicious patterns