paperproof-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ dist/
5
+ *.egg-info/
6
+ uv.lock
@@ -0,0 +1,29 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Evgenia Karunus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ -------------------------------------------------------------------------------
24
+
25
+ This package bundles Paperproof's Lean parser source, embedded in
26
+ src/paperproof_mcp/lean_parsers/*.lean, which is licensed under the MIT License:
27
+
28
+ Copyright (c) 2023 Anton Kovsharov
29
+ https://github.com/Paper-Proof/paperproof
@@ -0,0 +1,160 @@
1
+ Metadata-Version: 2.4
2
+ Name: paperproof-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server that exposes Lean proofs in the Paperproof boxes format, without installing Paperproof
5
+ Project-URL: Homepage, https://github.com/Paper-Proof/paperproof-mcp
6
+ Project-URL: Repository, https://github.com/Paper-Proof/paperproof-mcp
7
+ Project-URL: Issues, https://github.com/Paper-Proof/paperproof-mcp/issues
8
+ Author-email: Evgenia Karunus <lakesare@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: lean,lean4,mcp,paperproof,proof-visualization,theorem-proving
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: leanclient>=0.3.0
23
+ Requires-Dist: mcp[cli]>=1.0.0
24
+ Description-Content-Type: text/markdown
25
+
26
+ # paperproof-mcp
27
+
28
+ MCP server that exposes Lean proofs in the **Paperproof "boxes" format** (`NaturalProofTree`) - **without requiring Paperproof to be installed** in the user's project.
29
+
30
+ Given a Lean file, the `paperproof_proof_tree` tool returns each theorem's proof as a hierarchical tree of **boxes**, where each box is one proof goal with the tactics that transform or close it - exactly the structure Paperproof draws.
31
+
32
+ ## How it works
33
+
34
+ The server runs **Paperproof's real parser** inside your Lean project, without you installing anything:
35
+
36
+ 1. It injects `import Lean` + Paperproof's bundled parser + a `#ppjson in` command into your file **in-memory** (via the LSP, same trick `#info_trees in` uses).
37
+ 2. Runs the parser on the target theorem and reads the resulting JSON off the diagnostics.
38
+
39
+ The bundled parser depends only on core `Lean` (no Mathlib), so it elaborates in any project. Because it's Paperproof's actual `BetterParser`, `have`/`calc`/case-splits are handled faithfully - including hypothesis-origin (`from`) links.
40
+
41
+ **No Paperproof dependency, no lakefile edit, no rebuild.** Only a working `lake serve` is needed (same requirement as `lean-lsp-mcp`).
42
+
43
+ ## Setup
44
+
45
+ ### Prerequisites
46
+
47
+ - [uv](https://docs.astral.sh/uv/getting-started/installation/)
48
+ - A Lean project that builds (`lake build`)
49
+
50
+ ### Claude Code - add once, works in every project
51
+
52
+ ```bash
53
+ claude mcp add -s user paperproof uvx paperproof-mcp
54
+ ```
55
+
56
+ (`-s user` installs at user scope so you don't repeat it per-project; the server infers each project root from the file path you pass.)
57
+
58
+ ### VS Code / Cursor - add to `mcp.json`
59
+
60
+ ```jsonc
61
+ {
62
+ "servers": {
63
+ "paperproof": {
64
+ "type": "stdio",
65
+ "command": "uvx",
66
+ "args": ["paperproof-mcp"]
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ ## Tool
73
+
74
+ ### `paperproof_proof_tree`
75
+
76
+ **Parameters:**
77
+ - `file_path` (required) - absolute path to a `.lean` file
78
+ - `theorem_name` (optional) - a specific theorem; omit to parse all theorems in the file
79
+ - `include_theorems` (optional, default `false`) - also return the signatures of every theorem/def/axiom the proof references, in each tree's `used_theorems`
80
+
81
+ **Returns:** `{ lean_version, trees: [{ theorem_name, proof_tree, used_theorems }] }`, where each `proof_tree` is a `NaturalProofTree`.
82
+
83
+ ### `used_theorems`
84
+
85
+ When `include_theorems=true`, each tree carries the lemmas it uses:
86
+
87
+ ```json
88
+ "used_theorems": [
89
+ { "kind": "def", "name": "AddCircle.liftIco", "signature": "{𝕜 : Type u_1} → ..." },
90
+ { "kind": "theorem", "name": "Function.comp_apply", "signature": "∀ {β δ α} {f : β → δ} {g : α → β} {x}, (f ∘ g) x = f (g x)" }
91
+ ]
92
+ ```
93
+
94
+ Referenced constants are collected by walking the proof's info tree and keeping every **identifier** the user wrote that resolves to a global constant - this targets exactly the lemmas named in the source and drops notation plumbing (`HAdd.hAdd`, `OfNat.ofNat`, ...) that `Expr.getUsedConstants` would include. `kind` is derived from the type (`Prop`-valued => `theorem`), so it stays correct even under Lean's module system where imported proofs are erased and constants otherwise appear as axioms.
95
+
96
+ Example for `have h2 : b = a := by rw [h]; exact h2`:
97
+
98
+ ```json
99
+ {
100
+ "tactic": "have h2 : b = a := by",
101
+ "newHyps": [{ "name": "h2", "type": "b = a" }],
102
+ "haveBoxes": [
103
+ {
104
+ "goal": "b = a",
105
+ "newHyps": [],
106
+ "tactics": [
107
+ { "tactic": "rw [h]", "newGoal": "b = b" },
108
+ { "tactic": "rw [rfl]", "closed": true }
109
+ ]
110
+ }
111
+ ]
112
+ }
113
+ ```
114
+
115
+ ### NaturalProofTree shape
116
+
117
+ ```
118
+ NaturalProofTree (root box)
119
+ goal : string - goal at the top of this box
120
+ newHyps : NaturalHyp[] - hypotheses introduced on entry
121
+ tactics : NaturalStep[] - proof steps
122
+ format : "unicode"
123
+
124
+ NaturalHyp
125
+ name : string
126
+ type : string
127
+ from? : string - name of the hyp this one derives from (drives the arrow)
128
+
129
+ NaturalStep
130
+ tactic : string
131
+ dependsOn? : string[] - hyp names this step consumes
132
+ newHyps? : NaturalHyp[] - hyps this step introduces
133
+ newGoal? : string - new goal if the goal transformed
134
+ closed? : true - this step closes the current goal
135
+ newSubgoals? : NaturalBox[] - sub-boxes, one per case after a split
136
+ haveBoxes? : NaturalBox[] - sub-proof(s) of a `have`/anonymous `by`
137
+ ```
138
+
139
+ ## Lean version support
140
+
141
+ The parser must compile against your project's Lean version. Parsers are hand-maintained Lean files in `src/paperproof_mcp/lean_parsers/vX.Y.Z.lean`, each containing Paperproof's parser plus the `#ppjson` runner. The server picks the one matching your `lean-toolchain`; with no exact match it tries the nearest lower version, then the nearest higher.
142
+
143
+ To add a version, copy the closest existing parser to `vX.Y.Z.lean` and fix the Lean-API errors for that toolchain (they are usually small stdlib renames; e.g. for 4.25 vs 4.27: `Substring.Raw` -> `Substring`, `.trimAscii` -> `.trim`, `.dropEndWhile` -> `.dropRightWhile`).
144
+
145
+ Bundled versions: **v4.25.0**, **v4.27.0**. Module-system toolchains (Lean's `module` / `public import` / `public section`) are handled by the runner automatically: it marks the parser `meta` and `meta import`s the file's own imports.
146
+
147
+ ## Development
148
+
149
+ ```
150
+ src/paperproof_mcp/
151
+ server.py - MCP tool; orchestrates the pipeline
152
+ lean_runner.py - in-memory injection + revert, reads JSON off diagnostics
153
+ converter.py - port of Paperproof's converter.ts (LeanProofTree to ConvertedProofTree)
154
+ natural.py - port of copyAsNaturalProofTree.ts (ConvertedProofTree to NaturalProofTree)
155
+ lean_parsers/ - hand-maintained Paperproof parser + runner, one per Lean version
156
+ ```
157
+
158
+ ## License
159
+
160
+ MIT (see [LICENSE](LICENSE)). This package bundles [Paperproof](https://github.com/Paper-Proof/paperproof)'s Lean parser, which is MIT licensed, Copyright (c) 2023 Anton Kovsharov.
@@ -0,0 +1,135 @@
1
+ # paperproof-mcp
2
+
3
+ MCP server that exposes Lean proofs in the **Paperproof "boxes" format** (`NaturalProofTree`) - **without requiring Paperproof to be installed** in the user's project.
4
+
5
+ Given a Lean file, the `paperproof_proof_tree` tool returns each theorem's proof as a hierarchical tree of **boxes**, where each box is one proof goal with the tactics that transform or close it - exactly the structure Paperproof draws.
6
+
7
+ ## How it works
8
+
9
+ The server runs **Paperproof's real parser** inside your Lean project, without you installing anything:
10
+
11
+ 1. It injects `import Lean` + Paperproof's bundled parser + a `#ppjson in` command into your file **in-memory** (via the LSP, same trick `#info_trees in` uses).
12
+ 2. Runs the parser on the target theorem and reads the resulting JSON off the diagnostics.
13
+
14
+ The bundled parser depends only on core `Lean` (no Mathlib), so it elaborates in any project. Because it's Paperproof's actual `BetterParser`, `have`/`calc`/case-splits are handled faithfully - including hypothesis-origin (`from`) links.
15
+
16
+ **No Paperproof dependency, no lakefile edit, no rebuild.** Only a working `lake serve` is needed (same requirement as `lean-lsp-mcp`).
17
+
18
+ ## Setup
19
+
20
+ ### Prerequisites
21
+
22
+ - [uv](https://docs.astral.sh/uv/getting-started/installation/)
23
+ - A Lean project that builds (`lake build`)
24
+
25
+ ### Claude Code - add once, works in every project
26
+
27
+ ```bash
28
+ claude mcp add -s user paperproof uvx paperproof-mcp
29
+ ```
30
+
31
+ (`-s user` installs at user scope so you don't repeat it per-project; the server infers each project root from the file path you pass.)
32
+
33
+ ### VS Code / Cursor - add to `mcp.json`
34
+
35
+ ```jsonc
36
+ {
37
+ "servers": {
38
+ "paperproof": {
39
+ "type": "stdio",
40
+ "command": "uvx",
41
+ "args": ["paperproof-mcp"]
42
+ }
43
+ }
44
+ }
45
+ ```
46
+
47
+ ## Tool
48
+
49
+ ### `paperproof_proof_tree`
50
+
51
+ **Parameters:**
52
+ - `file_path` (required) - absolute path to a `.lean` file
53
+ - `theorem_name` (optional) - a specific theorem; omit to parse all theorems in the file
54
+ - `include_theorems` (optional, default `false`) - also return the signatures of every theorem/def/axiom the proof references, in each tree's `used_theorems`
55
+
56
+ **Returns:** `{ lean_version, trees: [{ theorem_name, proof_tree, used_theorems }] }`, where each `proof_tree` is a `NaturalProofTree`.
57
+
58
+ ### `used_theorems`
59
+
60
+ When `include_theorems=true`, each tree carries the lemmas it uses:
61
+
62
+ ```json
63
+ "used_theorems": [
64
+ { "kind": "def", "name": "AddCircle.liftIco", "signature": "{𝕜 : Type u_1} → ..." },
65
+ { "kind": "theorem", "name": "Function.comp_apply", "signature": "∀ {β δ α} {f : β → δ} {g : α → β} {x}, (f ∘ g) x = f (g x)" }
66
+ ]
67
+ ```
68
+
69
+ Referenced constants are collected by walking the proof's info tree and keeping every **identifier** the user wrote that resolves to a global constant - this targets exactly the lemmas named in the source and drops notation plumbing (`HAdd.hAdd`, `OfNat.ofNat`, ...) that `Expr.getUsedConstants` would include. `kind` is derived from the type (`Prop`-valued => `theorem`), so it stays correct even under Lean's module system where imported proofs are erased and constants otherwise appear as axioms.
70
+
71
+ Example for `have h2 : b = a := by rw [h]; exact h2`:
72
+
73
+ ```json
74
+ {
75
+ "tactic": "have h2 : b = a := by",
76
+ "newHyps": [{ "name": "h2", "type": "b = a" }],
77
+ "haveBoxes": [
78
+ {
79
+ "goal": "b = a",
80
+ "newHyps": [],
81
+ "tactics": [
82
+ { "tactic": "rw [h]", "newGoal": "b = b" },
83
+ { "tactic": "rw [rfl]", "closed": true }
84
+ ]
85
+ }
86
+ ]
87
+ }
88
+ ```
89
+
90
+ ### NaturalProofTree shape
91
+
92
+ ```
93
+ NaturalProofTree (root box)
94
+ goal : string - goal at the top of this box
95
+ newHyps : NaturalHyp[] - hypotheses introduced on entry
96
+ tactics : NaturalStep[] - proof steps
97
+ format : "unicode"
98
+
99
+ NaturalHyp
100
+ name : string
101
+ type : string
102
+ from? : string - name of the hyp this one derives from (drives the arrow)
103
+
104
+ NaturalStep
105
+ tactic : string
106
+ dependsOn? : string[] - hyp names this step consumes
107
+ newHyps? : NaturalHyp[] - hyps this step introduces
108
+ newGoal? : string - new goal if the goal transformed
109
+ closed? : true - this step closes the current goal
110
+ newSubgoals? : NaturalBox[] - sub-boxes, one per case after a split
111
+ haveBoxes? : NaturalBox[] - sub-proof(s) of a `have`/anonymous `by`
112
+ ```
113
+
114
+ ## Lean version support
115
+
116
+ The parser must compile against your project's Lean version. Parsers are hand-maintained Lean files in `src/paperproof_mcp/lean_parsers/vX.Y.Z.lean`, each containing Paperproof's parser plus the `#ppjson` runner. The server picks the one matching your `lean-toolchain`; with no exact match it tries the nearest lower version, then the nearest higher.
117
+
118
+ To add a version, copy the closest existing parser to `vX.Y.Z.lean` and fix the Lean-API errors for that toolchain (they are usually small stdlib renames; e.g. for 4.25 vs 4.27: `Substring.Raw` -> `Substring`, `.trimAscii` -> `.trim`, `.dropEndWhile` -> `.dropRightWhile`).
119
+
120
+ Bundled versions: **v4.25.0**, **v4.27.0**. Module-system toolchains (Lean's `module` / `public import` / `public section`) are handled by the runner automatically: it marks the parser `meta` and `meta import`s the file's own imports.
121
+
122
+ ## Development
123
+
124
+ ```
125
+ src/paperproof_mcp/
126
+ server.py - MCP tool; orchestrates the pipeline
127
+ lean_runner.py - in-memory injection + revert, reads JSON off diagnostics
128
+ converter.py - port of Paperproof's converter.ts (LeanProofTree to ConvertedProofTree)
129
+ natural.py - port of copyAsNaturalProofTree.ts (ConvertedProofTree to NaturalProofTree)
130
+ lean_parsers/ - hand-maintained Paperproof parser + runner, one per Lean version
131
+ ```
132
+
133
+ ## License
134
+
135
+ MIT (see [LICENSE](LICENSE)). This package bundles [Paperproof](https://github.com/Paper-Proof/paperproof)'s Lean parser, which is MIT licensed, Copyright (c) 2023 Anton Kovsharov.
@@ -0,0 +1,45 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "paperproof-mcp"
7
+ version = "0.1.0"
8
+ description = "MCP server that exposes Lean proofs in the Paperproof boxes format, without installing Paperproof"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ { name = "Evgenia Karunus", email = "lakesare@gmail.com" },
15
+ ]
16
+ keywords = ["lean", "lean4", "mcp", "theorem-proving", "paperproof", "proof-visualization"]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "Intended Audience :: Science/Research",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Scientific/Engineering :: Mathematics",
26
+ "Topic :: Software Development :: Libraries",
27
+ ]
28
+ dependencies = [
29
+ "mcp[cli]>=1.0.0",
30
+ "leanclient>=0.3.0",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/Paper-Proof/paperproof-mcp"
35
+ Repository = "https://github.com/Paper-Proof/paperproof-mcp"
36
+ Issues = "https://github.com/Paper-Proof/paperproof-mcp/issues"
37
+
38
+ [project.scripts]
39
+ paperproof-mcp = "paperproof_mcp.__main__:main"
40
+
41
+ [tool.hatch.build.targets.wheel]
42
+ packages = ["src/paperproof_mcp"]
43
+ # The .lean parsers live inside the package dir; make the inclusion explicit so
44
+ # they can never be pruned as non-Python files.
45
+ artifacts = ["src/paperproof_mcp/lean_parsers/*.lean"]
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json",
3
+ "name": "io.github.Paper-Proof/paperproof-mcp",
4
+ "description": "View Lean proofs as Paperproof box trees over MCP, no Paperproof install required",
5
+ "repository": {
6
+ "url": "https://github.com/Paper-Proof/paperproof-mcp",
7
+ "source": "github"
8
+ },
9
+ "version": "0.1.0",
10
+ "packages": [
11
+ {
12
+ "registryType": "pypi",
13
+ "identifier": "paperproof-mcp",
14
+ "version": "0.1.0",
15
+ "transport": {
16
+ "type": "stdio"
17
+ }
18
+ }
19
+ ]
20
+ }
File without changes
@@ -0,0 +1,9 @@
1
+ from paperproof_mcp.server import mcp
2
+
3
+
4
+ def main():
5
+ mcp.run()
6
+
7
+
8
+ if __name__ == "__main__":
9
+ main()