Skip to content

About

Unified Lean tool server with MCP, HTTP API, remote CLI, local shell, and configurable backends for diagnostics, declarations, LSP, and search

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

54 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lean MCP Toolkit logo

Lean MCP Toolkit

One configurable Lean tool catalog across MCP, HTTP, remote CLI, and local shell.

Python 3.11+ Version 0.1.0 Lean 4 MCP and HTTP Structured tool catalog MIT License

Quick Start · Documentation · Tool Catalog · Architecture · Configuration · Lean Constellation

Lean MCP Toolkit is a unified Lean tool server for proof-engineering Agents, interactive clients, and application runtimes. It combines Lean LSP inspection, declaration analysis, source navigation, search, diagnostics, linting, and build operations behind shared contracts and a configurable tool catalog.

Each tool has one canonical specification and structured response shape. The same active catalog can be exposed as MCP tools, HTTP JSON endpoints, a remote-first CLI, or an in-process interactive shell.

One Tool Catalog

Enable groups, filter individual tools, select naming modes, and discover the exact live surface instead of maintaining separate client lists.
Shared Contracts

MCP output schemas and HTTP JSON payloads are generated from the same structured toolkit response contracts.
Pluggable Backends

Route selected capabilities through LSP, Lean, LeanInteract, text-based analysis, local or remote LeanExplore, and external search providers.

What It Provides

  • Lean inspection — goals, term goals, hover information, outlines, code actions, completions, widgets, proof profiles, and snippet execution.
  • Declarations and navigation — declaration extraction and location, repository and Mathlib trees, outlines, file windows, imports, scopes, references, and grep-style search.
  • Search — local or remotely deployed LeanExplore, LeanSearch, LeanDex, Loogle, LeanFinder, arXiv theorem retrieval, state search, and premise suggestions.
  • Diagnostics and trust checks — workspace builds, file/target diagnostics, no_sorry, direct axiom detection, axiom-usage probing, and configurable backend selection.
  • Consistent access — MCP, HTTP API, remote CLI, and local shell all derive their visible commands and schemas from the active server configuration.
  • Operational backends — reusable Lean command, LSP, LeanInteract, LeanExplore, external provider, and lightweight text_ast runtimes.

How It Fits Together

MCP client          HTTP client        lean-cli-toolkit       local shell
     │                   │                    │                    │
     └───────────────────┴──────────┬─────────┴────────────────────┘
                                    ▼
                           live tool catalog
                 canonical specs · aliases · output schemas
                                    │
                                    ▼
                              group plugins
       build · diagnostics · declarations · LSP · search · navigation
                                    │
                                    ▼
                         services and interfaces
                                    │
                                    ▼
 Lean/Lake · LSP · LeanInteract · text_ast · LeanExplore · search providers

The transport layer remains thin. Group plugins bind canonical tool specs to transport-independent services and backend dependencies, while selected capabilities use internal interfaces to switch implementations without changing their public contracts.

GET /api/v1/meta/tools is the canonical discovery endpoint. The remote CLI queries it at runtime and builds its command tree from the tools and aliases actually exposed by the target server.

Access Surfaces

Surface Entry point Best suited for
MCP Toolkit MCP server Agent runtimes and MCP-compatible clients
HTTP API /api/v1 JSON routes Services, scripts, health checks, and language-agnostic integrations
Remote CLI lean-cli-toolkit Operators and shell automation against a running server
Local shell lean-mcp-toolkit shell Direct interactive use with the local service graph

Visible aliases depend on enabled groups, naming mode, and include/exclude filters. Public documentation uses canonical names; live MCP/HTTP/CLI surfaces reflect the selected configuration.

Quick Start

Lean MCP Toolkit requires Python 3.11 or newer. Install the server dependencies from a source checkout:

python -m pip install -e '.[server]'

Start with the default configuration or an explicit YAML file:

lean-mcp-toolkit serve
lean-mcp-toolkit serve --config path/to/toolkit.yaml

Inspect the resolved configuration:

lean-mcp-toolkit print-config --config path/to/toolkit.yaml

Discover the live catalog and invoke a tool through the remote CLI:

lean-cli-toolkit tools

lean-cli-toolkit diagnostics lint \
  --project-root /path/to/project \
  --targets MyProject/Package.lean

Or call the shared HTTP surface directly:

curl http://127.0.0.1:18080/api/v1/meta/tools

curl -X POST http://127.0.0.1:18080/api/v1/diagnostics/lint \
  -H 'Content-Type: application/json' \
  -d '{
    "project_root": "/path/to/project",
    "targets": ["MyProject/Package.lean"]
  }'

For in-process interactive use:

lean-mcp-toolkit shell --config path/to/toolkit.yaml

Inside the shell, the same live command vocabulary is available without the lean-cli-toolkit prefix.

Tool Families

Group Theme Representative canonical tools
build_base Direct workspace build build.workspace
diagnostics Build/file diagnostics and lint checks diagnostics.build, diagnostics.lint, diagnostics.lint.no_sorry
declarations Declaration extraction and symbol location declarations.extract, declarations.locate
lsp_core Core Lean LSP inspection lsp.goal, lsp.hover, lsp.file_outline, lsp.run_snippet
lsp_assist Higher-level proof assistance lsp.completions, lsp.multi_attempt, lsp.declaration_soundness, lsp.declaration_soundness_batch, lsp.compiled_declaration_batch
lsp_heavy Widget and proof-profile inspection lsp.widgets, lsp.widget_source, lsp.proof_profile
search_core LeanExplore declaration search lean_explore.find, lean_explore.get
search_nav Local repository navigation repo_nav.tree, repo_nav.local_decl.find, repo_nav.grep
mathlib_nav Mathlib navigation mathlib_nav.tree, mathlib_nav.read, mathlib_nav.grep
search_alt External search adapters leansearch, leandex, loogle, leanfinder
proof_search_alt External proof-search adapters proof_search_alt.state_search, proof_search_alt.hammer_premise

The Tool Catalog provides the navigation map. The Tool Reference records detailed contracts, provenance, upstream names, and backend notes.

Configuration and Backends

Tool visibility is controlled by:

groups.enabled_groups
groups.disabled_groups
groups.include_tools
groups.exclude_tools
groups.tool_naming_mode

Selected capabilities expose stable contracts over multiple implementations:

Capability Available backends Default
Declaration extraction text_ast, lean_interact, simple_lean text_ast
No-sorry checking text_ast, lean text_ast
Direct axiom declarations text_ast, lean text_ast
LeanExplore search local runtime or remote HTTP service configuration-dependent

The axiom-usage probe remains Lean-backed even when direct declaration checks use text_ast. Backend differences are explicit rather than hidden behind a claim of identical implementation semantics.

See Configuration for server settings, group activation, backend fields, LSP runtime controls, startup warmup, and CLI defaults.

Remote LeanExplore

LeanExplore can run in the main Toolkit process or as a separately deployed HTTP service while Agent-facing contracts remain lean_explore.find and lean_explore.get.

Install the remote service dependencies:

python -m pip install -e '.[lean-explore-server]'

Start the service and point the main Toolkit at the example client config:

export LEANEXPLORE_API_KEY='replace-with-a-secret'

lean-mcp-toolkit-explore-server \
  --lean-version 4.32.0 \
  --host 127.0.0.1 \
  --port 18081

lean-mcp-toolkit serve \
  --config configs/lean_explore_remote_client.example.yaml

With startup verification enabled, the remote adapter checks the public health metadata and Lean version, then calls the protected /api/v2/auth/check endpoint before the Toolkit opens its transport. The public health endpoint is not proof that the bearer credential is accepted. See Remote LeanExplore Service for cache preparation, authentication, SSH forwarding, worker limits, and the currently supported index mappings.

Ecosystem

Project Relationship
Lean Constellation Uses Toolkit HTTP/MCP capabilities and ToolViews for multi-repository Lean formalization workflows.
Agent Runtime Kit Provides the provider-neutral Agent and Flow/Step runtime underneath Lean Constellation; application tools remain owned by Toolkit/LC.
IIIS LEAN GitHub organization for the Lean formalization and tooling projects.

Lean MCP Toolkit itself is Agent-agnostic: it exposes Lean capabilities but does not schedule Agents, define application workflows, or own project-level formalization policy.

Documentation

Area Entry point
Documentation Public documentation index
Usage Server, HTTP, remote CLI, shell, and LeanExplore
Tool catalog Group-level catalog
Tool reference Detailed tools, provenance, and backends
Architecture Server, plugin, service, backend, and interface layers
Configuration Runtime, groups, backends, and CLI defaults

Testing

With the development/test dependencies available, run the deterministic suite:

python -m pytest

Tests are organized around configuration, contracts, transports, application entry points, backends, group plugins, and integration behavior.

Development Status

Lean MCP Toolkit is under active development. Canonical tool contracts and structured response shapes are the stable integration surface; visible aliases, enabled groups, and backend availability remain deployment configuration.

IIIS LEAN

About

Unified Lean tool server with MCP, HTTP API, remote CLI, local shell, and configurable backends for diagnostics, declarations, LSP, and search

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages