Skip to main content

Model Context Protocol (MCP) server for Rocq/Coq proof assistant based on Coq-LSP and Petanque

Project description

Rocq MCP Server

Tests Python 3.10+ License

Overview

This MCP server exposes the functionality of the Rocq/Coq proof assistant through a set of tools that can be used by MCP-compatible clients (like Claude Desktop). It uses the Pytanque to communicate with a coq-lsp via a Petanque server.

Features

Available Tools

  • rocq_start_proof: Start a proof session for a specific theorem in a Coq/Rocq file
  • rocq_run_tactic: Execute tactics or commands on the current proof state
  • rocq_get_goals: Get the current proof goals for a session
  • rocq_get_premises: Get available premises (lemmas, definitions) for the current proof state
  • rocq_get_file_toc: Get table of contents (available definitions and theorems) for a Coq/Rocq file
  • rocq_search: Search for theorems, definitions, and other objects in the current context
  • rocq_parse_ast: Parse a command and return its Abstract Syntax Tree (only with the dev version of coq-lsp)
  • rocq_get_state_at_position: Get the proof state at a specific position in a file (only with the dev version of coq-lsp)

Key Capabilities

  • Two communication modes:

    • Stdio mode (default): direct communication with pet process via stdin/stdout.
    • TCP mode: socket-based communication with pet-server via TCP.
  • Interactive theorem proving: Execute tactics and commands step by step

  • Comprehensive feedback: Access all Rocq messages (errors, warnings, search results)

  • State management: Navigate proof states and compare them

  • Session management: Support multiple concurrent proof sessions

  • AST parsing: Get abstract syntax trees for commands and file positions (only with the dev version of coq-lsp)

  • Position-based queries: Get states at specific file positions (only with the dev version of coq-lsp)

Prerequisites

Install coq-lsp with Petanque support:

# Install dependencies
opam install lwt logs coq-lsp

# Or install one of the dev versions of coq-lsp, e.g., for Coq.8.20
opam install lwt logs coq.8.20.0
opam pin add coq-lsp https://github.com/ejgallego/coq-lsp.git#v8.20

Installation

Install from GitHub (Recommended)

pip install git+https://github.com/llm4rocq/rocq-mcp.git

Development Installation

We recommand using uv.

  1. Clone this repository
  2. Use the project workflow:
    cd rocq-mcp
    uv sync
    

Usage

Running the MCP Server

# Default: stdio mode (uses 'pet' command directly)
rocq-mcp

# Use TCP mode for multi-client usage
rocq-mcp --tcp

# TCP mode with custom server configuration  
rocq-mcp --tcp --host 127.0.0.1 --port 8833

Development mode (if using uv sync):

uv run rocq-mcp
uv run rocq-mcp --tcp

Communication Modes:

  • Stdio mode (default): Spawns and communicates directly with the pet process via stdin/stdout. This is more efficient and simpler as it doesn't require a separate server process.
  • TCP mode: Starts a pet-server process and communicates via TCP socket. Use this for multi-client usage scenarios where multiple applications need to connect to the same Petanque instance.

MCP Client Configuration

Run the following command to install rocq-mcp for claude code.

claude mcp add rocq-mcp -- rocq-mcp

Note: If you are using virtual envs, rocq-mcp may not be in the path by default. First, activate the venv, and copy the path returned by which rocq-mcp. Then install rocq-mcp using this absolute path:

claude mcp add rocq-mcp -- /path/to/rocq-mcp

When you start a claude session, you can check the server with:

> /mcp

Then, simply ask claude a question.

> help me prove addnC in test.v

Testing

# Install with dev dependencies
uv sync --dev

# Run tests
uv run pytest tests/

Troubleshooting

Common Issues

Server Connection Errors

  • Verify port availability
  • Check that coq-lsp is properly installed

Installation Issues

  • Ensure coq-lsp is properly installed
  • Install lwt and logs before coq-lsp (required for pet and pet-server)
  • Verify pytanque dependency is correctly resolved

Note: This project was build with the help of Claude from the code of pytanque.

Related Projects

  • pytanque: Python client for the Petanque protocol
  • coq-lsp: Language server for Coq/Rocq
  • MCP: Model Context Protocol specification

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_rocq-0.1.2.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iflow_mcp_rocq-0.1.2-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file iflow_mcp_rocq-0.1.2.tar.gz.

File metadata

  • Download URL: iflow_mcp_rocq-0.1.2.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for iflow_mcp_rocq-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6a490f9df3e173b8b0e49cb3c2419618c55e68e0d4802b09b630634044b99d14
MD5 8564f0dab0c04de4a5c82daccb1ead2d
BLAKE2b-256 f6c750313fac7e421cd7643595e51a3e495a7f6b82de67b41457d6988c037af7

See more details on using hashes here.

File details

Details for the file iflow_mcp_rocq-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_rocq-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for iflow_mcp_rocq-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3cba686da87923fbf8f9ebf670c54880748130993c26901910f8ff8589e5c5ca
MD5 9f99fe29ab81bf94d5448ebc10caade6
BLAKE2b-256 8e1fabf9f7db52ed01a2a0c5f053a889ec84dcc5fe2e482f6fa64a779019b572

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page