dsh-lean-mcp
v1.0.0
Published
Bridges the Lean 4 language server into DeepSeek Harness so agents can inspect proof goals, run Lean code, build projects, and search Mathlib.
Maintainers
Readme
dsh-lean-mcp
Connect Lean 4 to DeepSeek Harness: proof goals, compiler errors, tactic trials, project builds, axiom checks, and Mathlib search — all as tools the agent can call.
Under the hood this bundle mounts @deepseek-ai/dsh-mcp-client against lean-lsp-mcp over stdio. No wrapper code, no fork: the tools the agent sees are lean-lsp-mcp's own tools, namespaced as mcp__lean4__*.
Not affiliated with the Lean FRO, leanprover, or OpenAI. "Lean" refers to the Lean 4 theorem prover.
What you get
| Tool | What it does |
|---|---|
| lean_goal | Proof state at a line (before/after), the single most useful tool |
| lean_diagnostic_messages | Compiler errors and warnings, categorised |
| lean_multi_attempt | Try several tactics at one position without editing the file |
| lean_run_code | Run a standalone snippet |
| lean_verify | Axiom check — catches sorry and non-standard axioms |
| lean_build | lake build + restart the language server |
| lean_local_search / lean_leansearch / lean_loogle / lean_leanfinder / lean_hammer_premise | Find the lemma instead of guessing |
| lean_hover_info, lean_completions, lean_file_outline, lean_references, lean_declaration_file, lean_code_actions, lean_term_goal, lean_minimal_hypotheses, lean_profile_proof | The rest of the IDE surface |
Requirements
- DSH ≥ 0.2.2-rc.2
- uv — the bundle runs
uvx --from lean-lsp-mcp==0.33.0 lean-lsp-mcp - Lean 4 via elan —
elanonPATH, plus a project that builds (lake build) - ripgrep — required by
lean_local_search;brew install ripgrep,apt install ripgrep, or a release binary - macOS or Linux. Windows is not supported by the bundled
PATHcomposition yet.
Lean itself is not installed by this plugin. Install it first:
curl -sSf https://elan.lean-lang.org/elan-init.sh | sh
elan default leanprover/lean4:stableInstall
From a local checkout:
git clone <this repo> dsh-lean-mcpthen Plugins → Add plugin and pick the directory, or:
plugin_manager install_bundle { "target": "/absolute/path/to/dsh-lean-mcp" }From npm (once published):
plugin_manager install_bundle { "target": "[email protected]" }After installation, 20+ mcp__lean4__* tools appear in the session. Startup downloads the pinned lean-lsp-mcp through uvx on first run; later starts are instant.
Pointing it at a project
The server infers the Lean project from the file paths you pass. Give the agent an absolute path inside a project:
Prove
demo_add_zeroin~/work/lean-demo/LeanDemo/Basic.lean; uselean_goalbefore each step.
Tools that take no path (lean_run_code, lean_local_search) fall back to the project the server learned last. Call any path-based tool first after a restart.
Projects with Mathlib work the same way; build once (lake build, or lake exe cache get && lake build) before the agent starts, otherwise the first language-server start can take minutes.
Configuration
This is a configuration-only bundle, so the settings live in cordis.patch.yml and are not editable from the settings UI. Pin a different lean-lsp-mcp version or raise the timeouts by editing that file in your plugin directory:
args:
- --from
- lean-lsp-mcp==0.33.0 # pin changes here
- lean-lsp-mcp
toolCallTimeoutMs: 900000 # 15 min per tool callfailOnStartupError: true means a missing uvx or an unreachable PyPI fails the plugin row instead of silently yielding no tools — check Plugins for the error.
Limitations
- No cross-platform PATH magic. macOS and Linux only, and it expects
~/.elan/binand~/.local/bin. - Mathlib is not bundled. Small proofs work on core Lean;
norm_num,ring,linarithneed a Mathlib project. - First call after a restart is slow — the language server has to elaborate the file.
lake buildis expensive.lean_buildis for new imports, not for iterating; preferlean_goal+lean_multi_attempt.- The server caches detection at startup. A tool installed later (for example
rg) needs a plugin reload or a DSH restart before it is noticed.
Security
lean_run_code executes Lean code, and lean_build runs the project's own build definitions. Pointing this plugin at an untrusted repository therefore means letting that repository's build run on your machine. Use a container or a dedicated user when working with code you do not trust. No credentials are read or sent by this bundle.
Troubleshooting
| Symptom | Cause |
|---|---|
| No mcp__lean4__* tools | uvx missing or PyPI unreachable; check Plugins for the row error |
| No valid Lean project path found | No path-based tool call yet, or the file is outside a Lake project |
| unknown tactic for norm_num/ring | Project has no Mathlib |
| ripgrep (rg) was not found | Install rg, then reload the plugin |
| Everything times out on the first request | Mathlib project cold start; build it once first |
License
MIT. See LICENSE.
