This file provides guidance to Claude Code (claude.ai/claude-code) when working with code in this repository.
lean-proof-auto-mcp is a Model Context Protocol (MCP) server for Lean 4 proof automation analysis and annotation discovery. It provides deterministic tooling to analyze Lean proofs, assess automation potential (e.g., aesop, grind), and discover automation annotations.
- API Version: 1.0 (Production Ready)
- Python Version: 3.10+
- Package Manager: uv
# Install dependencies
uv sync --dev
# Run all tests
uv run pytest
# Run specific test categories
uv run pytest tests/unit/ # Unit tests
uv run pytest tests/property/ # Property-based tests (Hypothesis)
uv run pytest tests/integration/ # Integration tests
uv run pytest tests/mcp_contract/ # Contract tests
# Type checking
uv run mypy .
# Linting and formatting
uv run ruff check . --fix
uv run ruff format .
# Run pre-commit hooks
uv run pre-commit run --all-files
# Run the MCP server
uv run lean-proof-auto-mcpThe codebase follows hexagonal architecture with strict separation of concerns:
src/lean_proof_auto_mcp/
├── core/ # Pure domain logic (no external dependencies)
│ ├── automation_detection.py # Detect existing automation in proofs
│ ├── config.py # Configuration management
│ ├── features.py # Feature extraction from Lean code
│ ├── format.py # Output formatting
│ ├── indexer.py # Theorem indexing
│ ├── lean_syntax.py # Lean syntax parsing
│ ├── ranking.py # Theorem ranking algorithms
│ ├── scoring.py # Automation scoring heuristics
│ ├── segmenter.py # Code segmentation
│ ├── source.py # Source code handling
│ └── verify_domain.py # Verification domain types
├── adapters/ # External interface adapters
│ ├── errors.py # Error handling
│ └── router.py # Request routing
├── tools/ # MCP tool implementations
│ ├── scan_file.py # scan_file tool
│ ├── scan_theorem.py # scan_theorem tool
│ └── rank_targets.py # rank_targets tool
├── lean/ # Lean-specific utilities
├── workspace/ # Workspace management
├── observability/ # Logging and metrics
├── server.py # MCP server entry point
├── config.py # Top-level configuration
└── heuristics.yaml # Default heuristic parameters
These patterns are enforced throughout the codebase (see .kiro/steering/code-conventions.md):
- Hexagonal Architecture: Core logic has no external dependencies; all I/O through ports/adapters
- Dependency Injection: Objects receive dependencies via constructor, wiring in composition root
- Command Pattern: Operations encapsulated as immutable data structures with handlers
- Strategy Pattern: Behavioral variation via interchangeable algorithms, not if/else chains
- Builder Pattern: Complex objects constructed step-by-step with invariant validation
- Result/Either Pattern: Explicit success/failure in return values; exceptions for programmer errors only
The server exposes three main tools:
- scan_file: Analyze all theorems in a Lean file for automation potential
- scan_theorem: Deep structural analysis of a single theorem
- rank_targets: Rank theorems by automation potential using configurable objectives
maximize_success: Quick wins, high success ratemaximize_impact: Maximum time savedmaximize_subgoal_automation: Partial automation opportunitiesbalanced: General-purpose ranking
Each theorem gets an automation profile with:
whole_goal_potential: Likelihood aesop/grind can solve entire goalsubgoal_potential: Likelihood automation can help with subgoalsannotation_value: ROI of adding automation annotations
Theorems are classified into tiers (relative to file):
- S-tier (top 10%): Exceptional candidates
- A-tier (10-25%): Strong candidates
- B-tier (25-50%): Good candidates
- C-tier (50-75%): Acceptable candidates
- D-tier (75-100%): Weak candidates
The system detects existing automation:
- Tactic usage:
by aesop,by grind,by simp - Attributes:
@[aesop],@[simp] - Trivial proofs:
:= rfl,:= trivial
All heuristics are configurable via YAML. Priority order:
config_pathparameter in requestLEAN_PROOF_AUTO_MCP_CONFIGenvironment variable- Package default (
heuristics.yaml)
- Unit tests: Test core logic in isolation
- Property tests: Hypothesis-based testing for invariants
- Integration tests: Test component interactions
- Contract tests: Verify MCP API contract compliance
Design specifications live in .kiro/specs/. Key specs:
lean-verify-tool/: Verification tool designrank-targets/: Ranking system designscan-rank-shared-semantics/: Shared concepts between scan/rankstatic-analysis-tools/: Static analysis design
Steering files in .kiro/steering/ define architectural constraints.