Coqtail-mcp
An MCP server that lets AI agents (Claude
Code, Codex, etc.) drive a live Rocq / Coq proof session: start a session,
step through a .v file, inspect the current goal and context, and fire
one-off queries like Check, Print, or Search.
Under the hood it talks to coqidetop / coqtop using the same XML protocol
that the Coqtail vim plugin uses. The
XML plumbing is not rewritten — three of Coqtail's Python modules are vendored
under src/coqtail_mcp/coqtail_lib/ and driven by a thin session layer.
xmlInterface.py and coqtail.py remain verbatim; coqtop.py carries small
backend-lifecycle changes for bounded timeout and cancellation recovery.
Why reuse Coqtail?
The hard parts — version-aware encoders/decoders (XMLInterface84 through
XMLInterface92), framing, richpp parsing, sentence boundary detection
(including bullets, attributes, lp:{{ }} elpi blocks, nested comments) —
already work. This project only adds:
- a single-process-per-session wrapper (
RocqSession)
- a session registry with thread-safe access
- a goal formatter that strips highlight tags for plain-text display
- a FastMCP server registering seven tools
Tools
| Tool | What it does |
|---|
rocq_start | Spawn a coqidetop subprocess. Accepts either file_path or inline content. Returns the session id and startup stderr. |
rocq_close | Terminate a session's subprocess and forget it. |
rocq_step_to | Advance or rewind so the session's state matches (line, col). Optionally re-reads the original file_path from disk (reload_from_file), admits opaque proofs (admit), and caps each Rocq sentence with step_timeout. |
rocq_goals | Return the current proof goal and hypothesis context as a structured summary. Accepts optional range, max_chars, and full_output_file controls for large contexts. |
rocq_query | Run a non-state-changing query (Check, Print, Search, …). Accepts optional max_chars, full_output_file, and query_timeout controls. |
rocq_status | Report whether one session is started. |
rocq_list | List active session ids. |
All line and column numbers at the tool boundary are 1-indexed.
For rocq_step_to, line=-1 is an explicit EOF target; use it when
running through a whole buffer, including files that end with blank lines.
Requirements
- Python ≥ 3.10
mcp SDK (installed automatically via pyproject.toml)
- A working Rocq / Coq install on
$PATH, or the path explicitly supplied via
coq_path / coq_prog on rocq_start
Install
cd Coqtail-mcp
pip install -e .
or with uv:
cd Coqtail-mcp
uv pip install -e .
This installs a coqtail-mcp command that runs the MCP server over stdio.
Claude Code configuration
Register the server with Claude Code by editing ~/.claude.json (or the
project-scoped .claude.json):
{
"mcpServers": {
"coqtail": {
"command": "coqtail-mcp"
}
}
}
If you didn't install with pip install -e ., point at the module instead:
{
"mcpServers": {
"coqtail": {
"command": "python",
"args": ["-m", "coqtail_mcp"],
"env": {
"PYTHONPATH": "/absolute/path/to/Coqtail-mcp/src"
}
}
}
}
An example config lives at examples/mcp_config.json.
Claude Code plugin (optional, recommended)
The repo also ships as a Claude Code plugin. Installing it gives you
two things on top of the raw MCP server:
- The skill (
plugins/coqtail-mcp/skills/coqtail-mcp/) — server
lifecycle, position conventions, error envelopes, proof-craft
recipes, subagent patterns.
- Four named subagents (
plugins/coqtail-mcp/agents/) —
proof-repair, admitted-filler-deep, axiom-auditor,
proof-golfer — that the main agent will reach for spontaneously
when their use conditions match.
| Subagent | Model | Use when |
|---|
coqtail-mcp:proof-repair | opus | A tactic / sentence fails to step (type mismatch, unification, missing reference, syntax, …). Two-stage budget. Outputs a unified diff. |
coqtail-mcp:admitted-filler-deep | opus | A stubborn Admitted resists 3+ candidate proofs, or needs a helper lemma / multi-step structuring. Plans before editing. |
coqtail-mcp:axiom-auditor | opus | Verify proof hygiene before a checkpoint. Two modes: audit (read-only) and eliminate. |
coqtail-mcp:proof-golfer | opus | Shorten / direct-ify proofs in a file that already type-checks end-to-end. |
Install as a plugin
The repo doubles as a single-plugin Claude Code marketplace. Register
it once, then install the plugin from it:
claude plugin marketplace add /abs/path/to/Coqtail-mcp
claude plugin install coqtail-mcp@coqtail-mcp