rocq-solid-mcp 1.0.0__py3-none-any.whl

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,156 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Annotated, Any
4
+
5
+ from fastmcp import Context, FastMCP
6
+ from fastmcp.server.lifespan import lifespan
7
+ from pydantic import Field
8
+
9
+ from .config import bounded_overall_timeout_seconds
10
+ from .manager import RocqLspManager
11
+ from .models import RenderOptions
12
+
13
+
14
+ @lifespan
15
+ async def app_lifespan(server: Any) -> Any:
16
+ manager = RocqLspManager()
17
+ manager.start_idle_cleanup()
18
+ try:
19
+ yield manager
20
+ finally:
21
+ await manager.close()
22
+
23
+
24
+ mcp = FastMCP("rocq-solid", lifespan=app_lifespan)
25
+
26
+
27
+ @mcp.tool()
28
+ async def rocq_check_file(
29
+ ctx: Context,
30
+ file: Annotated[
31
+ str,
32
+ Field(
33
+ description="Absolute path to a .v file.",
34
+ ),
35
+ ],
36
+ command_timeout_seconds: Annotated[
37
+ float | None,
38
+ Field(
39
+ description=(
40
+ "Per Rocq sentence watchdog for checking. None uses the server "
41
+ "default, 0 disables it, and positive values abort on slow sentences."
42
+ ),
43
+ ),
44
+ ] = None,
45
+ timeout_after_error_seconds: Annotated[
46
+ float | None,
47
+ Field(
48
+ description=(
49
+ "Overall deadline once the first error has been reported: "
50
+ "the whole check is stopped at most this many seconds after "
51
+ "the first error. None uses the server default, 0 disables "
52
+ "it, and positive values enable it."
53
+ ),
54
+ ),
55
+ ] = None,
56
+ clear_cache: Annotated[
57
+ bool,
58
+ Field(
59
+ description=(
60
+ "Restart this file's coq-lsp process before checking."
61
+ ),
62
+ ),
63
+ ] = False,
64
+ ) -> dict[str, Any]:
65
+ """Check a Rocq file and report diagnostics.
66
+
67
+ Use this to check files for errors. (To find warnings, recompile the file
68
+ manually.) Error diagnostics include the source sentence and the proof state
69
+ at error positions.
70
+
71
+ The first error in a file is always reported, along with later errors
72
+ reached within the after-error deadline. The list of errors may be
73
+ truncated. The tool also reports Rocq sentences running for long time.
74
+
75
+ This tool is efficient due to per-file caching. For dune-based Rocq projects,
76
+ it attempts to rebuild dependencies before checking and restarts the cached
77
+ coq-lsp process when that applies. Use `clear_cache = true` when project
78
+ files have changed or dependencies were rebuilt outside dune.
79
+
80
+ Timeouts are handled gracefully, and partial diagnostics are returned when
81
+ possible. Repeated checks after timeouts use the cache.
82
+ """
83
+ manager: RocqLspManager = ctx.request_context.lifespan_context
84
+ result = await manager.check_file(
85
+ file,
86
+ command_timeout_seconds=command_timeout_seconds,
87
+ timeout_after_error_seconds=timeout_after_error_seconds,
88
+ long_running_seconds=_long_running_alert_threshold(
89
+ manager.config.timeout_policy.request_seconds
90
+ ),
91
+ clear_cache=clear_cache,
92
+ )
93
+ return result.render(RenderOptions(message_limit=manager.config.message_limit))
94
+
95
+
96
+ @mcp.tool()
97
+ async def rocq_run_at(
98
+ file: Annotated[str, Field(description="Absolute path to a .v file.")],
99
+ commands: Annotated[
100
+ str,
101
+ Field(
102
+ description=(
103
+ "One string containing one or more complete Rocq commands to run at "
104
+ "the same file position, e.g. 'Require Import List. Check list.'"
105
+ ),
106
+ ),
107
+ ],
108
+ line: Annotated[
109
+ int,
110
+ Field(
111
+ description=(
112
+ "1-based line number in the file at which the commands "
113
+ "string is ran."
114
+ ),
115
+ ),
116
+ ],
117
+ ctx: Context,
118
+ character: Annotated[
119
+ int,
120
+ Field(description="1-based column offset. Defaults to 1 (start of line)."),
121
+ ] = 1,
122
+ ) -> dict[str, Any]:
123
+ """Run Rocq commands at a file position and return their output.
124
+
125
+ Use this for running Rocq commands, such as:
126
+ - Search Nat.add.
127
+ - Search insert delete "_eq".
128
+ - Check (3 + 4).
129
+ - About Nat.add.
130
+ - Locate "+".
131
+ - Show. (to show the proof state at a position)
132
+ The tool is also useful for one-off debugging tasks.
133
+
134
+ Prefer calling this tool right after imports or between lemmas/definitions.
135
+ Only use within proofs when necessary.
136
+ """
137
+ manager: RocqLspManager = ctx.request_context.lifespan_context
138
+ result = await manager.run_at(
139
+ file,
140
+ commands,
141
+ line,
142
+ character,
143
+ )
144
+ return result.render()
145
+
146
+
147
+ def _long_running_alert_threshold(request_timeout_seconds: float | None) -> float:
148
+ return bounded_overall_timeout_seconds(request_timeout_seconds) * 0.8
149
+
150
+
151
+ def main() -> None:
152
+ mcp.run()
153
+
154
+
155
+ if __name__ == "__main__":
156
+ main()
@@ -0,0 +1,84 @@
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ import time
5
+ from contextlib import suppress
6
+ from pathlib import Path
7
+
8
+ from .config import RocqLspConfig
9
+ from .notifications import NotificationStore
10
+ from .rocq_client import RocqLspClient
11
+
12
+
13
+ class RocqLspSession:
14
+ def __init__(
15
+ self,
16
+ *,
17
+ workspace: Path,
18
+ config: RocqLspConfig,
19
+ ) -> None:
20
+ self.workspace = workspace
21
+ self.config = config
22
+ self.lock = asyncio.Lock()
23
+ self.active_requests = 0
24
+ self.last_used_at = time.monotonic()
25
+ self.versions: dict[str, int] = {}
26
+ self._client: RocqLspClient | None = None
27
+ self._notifications = NotificationStore()
28
+
29
+ @property
30
+ def client(self) -> RocqLspClient:
31
+ if self._client is None:
32
+ raise RuntimeError("rocq-lsp session has not been started")
33
+ return self._client
34
+
35
+ @property
36
+ def notifications(self) -> NotificationStore:
37
+ return self._notifications
38
+
39
+ async def start(self) -> None:
40
+ if self._client is not None:
41
+ raise RuntimeError("rocq-lsp session has already been started")
42
+ self.versions.clear()
43
+ self._notifications = NotificationStore()
44
+ request_timeout = max(
45
+ 10.0,
46
+ self.config.timeout_policy.request_seconds
47
+ + self.config.timeout_policy.cancel_grace_seconds
48
+ + 5,
49
+ )
50
+ client = RocqLspClient(
51
+ binary=self.config.binary,
52
+ use_opam=self.config.use_opam,
53
+ workspace=self.workspace,
54
+ max_errors=self.config.max_errors,
55
+ request_timeout=request_timeout,
56
+ notifications=self._notifications,
57
+ )
58
+ self._client = client
59
+ try:
60
+ await client.start()
61
+ await client.notify_change_configuration()
62
+ except Exception:
63
+ await self.stop(hard=True)
64
+ raise
65
+
66
+ async def restart(self) -> None:
67
+ await self.stop(hard=True)
68
+ await self.start()
69
+
70
+ async def stop(self, *, hard: bool = False) -> None:
71
+ client = self._client
72
+ self._client = None
73
+ if client is None:
74
+ return
75
+
76
+ if hard:
77
+ with suppress(Exception):
78
+ client.clear_pending_requests()
79
+ with suppress(Exception):
80
+ await client.kill_server()
81
+ return
82
+
83
+ with suppress(Exception):
84
+ await client.close()
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: rocq-solid-mcp
3
+ Version: 1.0.0
4
+ Summary: RocqSolid: an MCP server for Rocq proof development, backed by rocq-lsp
5
+ Author: Benjamin Peters
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/bn-peters/rocq-solid-mcp
8
+ Project-URL: Repository, https://github.com/bn-peters/rocq-solid-mcp
9
+ Project-URL: Issues, https://github.com/bn-peters/rocq-solid-mcp/issues
10
+ Keywords: rocq,coq,mcp,proof assistant,lsp,agent
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Operating System :: MacOS
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Requires-Python: >=3.11
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: fastmcp<5,>=4.1
29
+ Requires-Dist: pydantic<3,>=2.13
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=8.0; extra == "dev"
32
+ Requires-Dist: pytest-asyncio>=0.25; extra == "dev"
33
+ Requires-Dist: pytest-xdist>=3.6; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ # RocqSolid
37
+
38
+ [![PyPI](https://img.shields.io/pypi/v/rocq-solid-mcp)](https://pypi.org/project/rocq-solid-mcp/)
39
+ [![CI](https://github.com/bn-peters/rocq-solid-mcp/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/bn-peters/rocq-solid-mcp/actions/workflows/ci.yml)
40
+
41
+ An MCP server for Rocq proof development.
42
+
43
+ The MCP is deliberately small:
44
+ 1. `check` generates diagnostics for a given file. It tries to return errors
45
+ from proofs throughout the file. Proof states are cached for efficiency.
46
+ 2. `run_at` runs a command at a given position in a file. This is useful for
47
+ queries like `Search` or `Check`, and for one-off debugging commands.
48
+
49
+ ## Requirements
50
+
51
+ *RocqSolid appears to be more stable on OCaml 5 than on OCaml 4. Consider
52
+ upgrading if you're experiencing crashes.*
53
+
54
+ RocqSolid depends on a [patched version](https://github.com/bn-peters/coq-lsp)
55
+ of [`coq-lsp`](https://github.com/rocq-community/coq-lsp). It improves the
56
+ stability and error reporting of `coq-lsp`, and RocqSolid does not work
57
+ without. It is compatible with Rocq 9.0, 9.1, and 9.2. It needs to be installed
58
+ in all opam switches RocqSolid should work with:
59
+ ```bash
60
+ opam repo add rocq-solid https://github.com/bn-peters/rocq-solid-mcp-opam.git
61
+ opam install rocq-solid-mcp-lsp
62
+ ```
63
+ You might be asked to uninstall `coq-lsp`. Don't worry, `rocq-solid-mcp-lsp` is compatible with standard `coq-lsp`.
64
+
65
+ ## Agent Setup
66
+
67
+ We recommend using [`uv`](https://docs.astral.sh/uv/), a Python packaging tool.
68
+ To teach your favorite agent about RocqSolid:
69
+ ```bash
70
+ claude mcp add --scope user rocq-solid -- uvx rocq-solid-mcp
71
+ codex mcp add rocq-solid -- uvx rocq-solid-mcp
72
+ ```
73
+
74
+ ## Project Setup
75
+
76
+ The MCP looks for `_CoqProject` and `_RocqProject` files to set up file
77
+ dependencies correctly. To generate them in a `dune`-based project, add
78
+ `(generate_project_file)` to your `rocq.theory` stanzas:
79
+ ```
80
+ ; in theories/dune
81
+ (rocq.theory
82
+ (name my-project)
83
+ (generate_project_file)
84
+ (theories Stdlib))
85
+ ```
86
+ You need to link the right opam switch to your development so that RocqSolid
87
+ knows which one to use:
88
+ ```
89
+ opam switch link [switch] .
90
+ ```
91
+
92
+ ## Timeouts
93
+
94
+ If you have files that compile very slowly, RocqSolid may time out. You can
95
+ raise this limit with `ROCQ_LSP_TIMEOUT`.
96
+
97
+ For Claude, re-register RocqSolid with a higher limit:
98
+ ```bash
99
+ claude mcp remove --scope user rocq-solid
100
+ claude mcp add --scope user rocq-solid -e ROCQ_LSP_TIMEOUT=290 -- uvx rocq-solid-mcp
101
+ ```
102
+
103
+ For Codex, add the last two options to the existing entry in
104
+ `~/.codex/config.toml`:
105
+ ```toml
106
+ [mcp_servers.rocq-solid]
107
+ command = "uvx"
108
+ args = ["rocq-solid-mcp"]
109
+ # add these two options:
110
+ tool_timeout_sec = 300
111
+ env = { ROCQ_LSP_TIMEOUT = "290" } # slightly lower than tool_timeout_sec
112
+ ```
113
+
114
+ ## Upgrading
115
+
116
+ To upgrade RocqSolid:
117
+ ```
118
+ uvx rocq-solid-mcp@latest --help
119
+ ```
120
+ To upgrade `coq-lsp`, run in your switch:
121
+ ```
122
+ opam update && opam upgrade rocq-solid-mcp-lsp
123
+ ```
124
+
125
+ ## Troubleshooting
126
+
127
+ RocqSolid needs Python 3.11 or newer. If your default `python3` is older, `uvx`
128
+ reports that no solution was found. Use `uvx --python 3.12 rocq-solid-mcp`
129
+ instead.
130
+
131
+ You can check a single file from the command line, which prints the diagnostics
132
+ as JSON:
133
+ ```bash
134
+ uvx rocq-solid-mcp check path/to/file.v
135
+ ```
136
+
137
+ ## Environment Variables
138
+
139
+ All optional; defaults in parentheses.
140
+
141
+ - `ROCQ_LSP_BINARY` (`coq-lsp`): the `coq-lsp` executable
142
+ - `ROCQ_LSP_USE_OPAM` (`1`): run via `opam exec --`; `0` runs the binary
143
+ directly
144
+ - `ROCQ_LSP_WORKSPACE` (unset): override the inferred workspace root
145
+ - `ROCQ_LSP_TIMEOUT` (`55`, max `3600`): deadline per call; set slightly below
146
+ the MCP tool timeout
147
+ - `ROCQ_LSP_HARD_TIMEOUT_GRACE` (`5`): extra wait after cancellation before the
148
+ session is killed
149
+ - `ROCQ_LSP_COMMAND_TIMEOUT` (`5`): default per-sentence timeout; `0` disables
150
+ - `ROCQ_LSP_TIMEOUT_AFTER_ERROR` (`10`): overall deadline for the rest of a
151
+ check after its first error; `0` disables
152
+ - `ROCQ_LSP_MESSAGE_LIMIT` (`10`, max `50`): max errors returned per check
153
+ - `ROCQ_LSP_MAX_ERRORS` (`1000000`): max errors `coq-lsp` collects
154
+ - `ROCQ_LSP_IDLE_TTL_SECONDS` (`1800`): idle time before cached sessions are
155
+ stopped
156
+ - `ROCQ_LSP_DUNE_BUILD` (`1`): build dune dependencies before checks; `0`
157
+ disables
158
+ - `ROCQ_LSP_DUNE_TIMEOUT` (`55`, max `3600`): limit per dune detection or build
159
+ command
160
+
161
+
162
+ ## Support
163
+
164
+ Join us on the Iris Mattermost!
165
+ 1. Go to the [GitLab log-in page](https://gitlab.mpi-sws.org/users/sign_in) and select the "GitHub" button, then log in with your GitHub account.
166
+ 2. Log in to Mattermost; this should use your GitLab login.
167
+ 3. Join the [RocqSolid](https://mattermost.mpi-sws.org/iris/channels/bens-rocq-mcp) channel.
168
+
169
+ If you notice that your agent misbehaves with this MCP, please let us know! It
170
+ would be particularly helpful if you could share your transcripts.
171
+
172
+ ## Development
173
+
174
+ In a clone of this repository:
175
+ ```bash
176
+ uv venv .venv && uv pip install -e ".[dev]"
177
+ make test
178
+ ```
179
+ `uv tool install -e .` installs a development version of `rocq-solid-mcp` to
180
+ `~/.local/bin/`.
181
+
182
+ To release a new version, bump `version` in `pyproject.toml` and push a tag
183
+ `vX.Y.Z`. The `release` GitHub workflow builds the package and publishes it to
184
+ PyPI.
@@ -0,0 +1,17 @@
1
+ rocq_solid_mcp/__init__.py,sha256=gU22t96hwNKt2vjLV7SVqpCK77_cJv34CU1ZfUhGHrE,186
2
+ rocq_solid_mcp/cli.py,sha256=X-9_S7IQnpwFrCHRUvA9NLbiMLQJE4VTSdUyxfycsHU,1583
3
+ rocq_solid_mcp/config.py,sha256=okA3J6HZuom15mZOOzeI8I4rn-KIbNNtvKbsFlsA_74,5158
4
+ rocq_solid_mcp/manager.py,sha256=eVfN7Vg6TR7G0QXkwkC0n5jp2BxqQ2Wxa_OzyhuxFXA,39457
5
+ rocq_solid_mcp/models.py,sha256=JKBmR_W9cwXR3M8_L8VD08wUbq9ts3hKk6PhmvBbz0E,25280
6
+ rocq_solid_mcp/notifications.py,sha256=h4vrkQqPJsxDZGTr7SYPrYWSj7TAnJxtsZx7bAkrwsM,9426
7
+ rocq_solid_mcp/pipeline.py,sha256=J5_lv2lC4Mjj2ZBHxruLtYJ24CRhey1Z6HvXxsIaTEE,3027
8
+ rocq_solid_mcp/pretty.py,sha256=ZF5tiyvMkiBwyaIdTIsT_6b8Qc5rwpi--kjIFd5QK4A,5272
9
+ rocq_solid_mcp/rocq_client.py,sha256=GdT-LTkA86j3DHUncGmKL7rBqyiA8TfjEKNqwiUrDCU,37096
10
+ rocq_solid_mcp/server.py,sha256=yAosV75ChCJ9rHW9UvSId2V5KOhZViinN085EBvUvz4,4782
11
+ rocq_solid_mcp/session.py,sha256=UwZ1QxFlR809GRzuP2CeuyUEgUIhz_9QFnn4hMcwHPY,2455
12
+ rocq_solid_mcp-1.0.0.dist-info/licenses/LICENSE,sha256=VuNQ6H1MkB-flnJc5QcRPYwSS57yluqfhLrFXeQ754M,1089
13
+ rocq_solid_mcp-1.0.0.dist-info/METADATA,sha256=qzp2iGVtlSh3ZWS2mQ1pHhtYdJbSjgkIrUvEFAlf4FY,6669
14
+ rocq_solid_mcp-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
15
+ rocq_solid_mcp-1.0.0.dist-info/entry_points.txt,sha256=RLoXJs-mK9gJwZdvArKgX1N-E27OnNK3-ane6uGlk38,99
16
+ rocq_solid_mcp-1.0.0.dist-info/top_level.txt,sha256=pJxThN1rbjFtzEddrni0dGYkggz_bHOAFihHCAUC34U,15
17
+ rocq_solid_mcp-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ bens-rocq-mcp = rocq_solid_mcp.cli:main
3
+ rocq-solid-mcp = rocq_solid_mcp.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Benjamin Peters and contributors
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.
@@ -0,0 +1 @@
1
+ rocq_solid_mcp