Metadata-Version: 2.5
Name: verifier-mcp
Version: 0.2.1
Summary: An MCP server that lets any LLM check its own work: symbolic math, sandboxed code, SQL, JSON-Schema, units and regex verification.
Project-URL: Homepage, https://github.com/Arashomranpour/Verifier_MCP
Project-URL: Repository, https://github.com/Arashomranpour/Verifier_MCP
Project-URL: Issues, https://github.com/Arashomranpour/Verifier_MCP/issues
Author: Alex Omra
License-Expression: MIT
License-File: LICENSE
Keywords: agents,jsonschema,llm,mcp,model-context-protocol,sql,sqlglot,sympy,verification
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Requires-Dist: jsonschema>=4.20
Requires-Dist: mcp<2,>=1.9
Requires-Dist: pint>=0.23
Requires-Dist: sqlglot>=25
Requires-Dist: sympy>=1.12
Provides-Extra: demo
Requires-Dist: langchain-groq>=0.2; extra == 'demo'
Requires-Dist: langchain-mcp-adapters>=0.1; extra == 'demo'
Requires-Dist: langgraph>=0.2; extra == 'demo'
Provides-Extra: dev
Requires-Dist: fastapi>=0.110; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Requires-Dist: uvicorn>=0.29; extra == 'dev'
Provides-Extra: web
Requires-Dist: fastapi>=0.110; extra == 'web'
Requires-Dist: uvicorn>=0.29; extra == 'web'
Description-Content-Type: text/markdown

# VerifierMCP

<!-- mcp-name: io.github.Arashomranpour/verifier-mcp -->

[![PyPI](https://img.shields.io/pypi/v/verifier-mcp)](https://pypi.org/project/verifier-mcp/)
[![Python](https://img.shields.io/pypi/pyversions/verifier-mcp)](https://pypi.org/project/verifier-mcp/)
[![MCP Registry](https://img.shields.io/badge/MCP%20Registry-io.github.Arashomranpour%2Fverifier--mcp-blue)](https://registry.modelcontextprotocol.io/v0/servers?search=io.github.Arashomranpour/verifier-mcp)
[![CI](https://github.com/Arashomranpour/Verifier_MCP/actions/workflows/ci.yml/badge.svg)](https://github.com/Arashomranpour/Verifier_MCP/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)

> An **MCP server** that gives any LLM the power to **check its own work**.
> Instead of trusting a model's arithmetic, regex, JSON or "the code prints X", the model
> can *call a tool and verify it*. Six verification tools over the
> [Model Context Protocol](https://modelcontextprotocol.io): symbolic math, sandboxed code
> execution, SQL checking, JSON-Schema validation, dimensional analysis, and regex testing.

<p align="center">
  <img src="https://raw.githubusercontent.com/Arashomranpour/Verifier_MCP/main/docs/images/playground.png" alt="VerifierMCP playground catching errors live" width="880">
</p>

Built with the official **MCP Python SDK** (FastMCP). Works in **Claude Desktop** and any
MCP client over **stdio**, or remotely over **streamable HTTP** (e.g. behind **Amazon Bedrock
AgentCore Gateway**).

## Install

| Where | How |
|-------|-----|
| **PyPI** | `pip install verifier-mcp` → run `verifier-mcp` ([pypi.org/project/verifier-mcp](https://pypi.org/project/verifier-mcp/)) |
| **uv (no install)** | `uvx verifier-mcp` |
| **Official MCP Registry** | listed as [`io.github.Arashomranpour/verifier-mcp`](https://registry.modelcontextprotocol.io/v0/servers?search=io.github.Arashomranpour/verifier-mcp), so registry-aware MCP clients can discover it |

---

## Why it matters

LLMs are confidently wrong about exactly the things that are *mechanically checkable*:
`(x+1)² = x²+1`, a regex that doesn't quite match, a SQL query with the wrong `JOIN`, JSON that violates its schema, a unit
slip, "this function returns 5050". VerifierMCP turns each of those into a tool call, so an
agent can **replace an assertion with a verified fact**.

## The tools

| Tool | Checks | Engine |
|------|--------|--------|
| `verify_math` | Is an equation an identity? Does a claimed result hold? | SymPy |
| `run_code` | What does this Python snippet *actually* output? | sandboxed subprocess |
| `validate_schema` | Does this JSON conform to its JSON Schema? | jsonschema (Draft 2020-12) |
| `check_units` | Is this quantity/equation dimensionally correct? | Pint |
| `test_regex` | Does this regex match/reject the right cases? | `re` |
| `verify_sql` | Is this SQL valid for my dialect? What does it return on sample data? Does it match the expected rows? | sqlglot + in-memory SQLite |

Each tool body lives in [`src/verifier_mcp/tools/`](src/verifier_mcp/tools/) as a pure
function, so it is unit-tested without the protocol and reused by the web playground.

---

## Quickstart

```bash
pip install verifier-mcp            # or: pip install "verifier-mcp[web]" for the playground

# Run the MCP server over stdio (what Claude Desktop launches)
verifier-mcp

# Or serve it over HTTP (MCP streamable transport on :8000/mcp)
verifier-mcp --http

# See it in action — the visual playground (needs the [web] extra)
uvicorn verifier_mcp.playground:app --port 8080   # http://localhost:8080
```

### Connect to Claude Desktop

Add to `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "verifier": {
      "command": "uvx",
      "args": ["verifier-mcp"]
    }
  }
}
```

Works on **Windows, macOS and Linux** (CI tests all three). On Windows, if `uvx` isn't installed,
`pip install verifier-mcp` and use `"command": "python", "args": ["-m", "verifier_mcp.server"]`
(with the full path to `python.exe` if needed).

Restart Claude Desktop and ask it something like *"Is (x+1)² equal to x²+1? Use the verifier."*
— it will call `verify_math` and come back with the checked answer.

---

## Self-checking agent demo (Groq + MCP)

[`examples/self_checking_agent.py`](examples/self_checking_agent.py) connects a **Groq** LLM to
this server over **real MCP** (via `langchain-mcp-adapters`), instructs it to *verify before
asserting*, and watches it catch its own mistake:

```bash
pip install -r requirements-demo.txt
export GROQ_API_KEY=gsk_...                       # real Groq agent
python examples/self_checking_agent.py

python examples/self_checking_agent.py --offline  # no key: scripted LLM, REAL MCP verification
```

```text
[offline] Question: Is (x+1)^2 equal to x^2 + 1? If not, what is the correct expansion?

  [Assistant] draft answer: "(x+1)^2 = x**2 + 1"
  → verify_math((x+1)**2, claimed_result=x**2 + 1)  [real MCP call]
    MCP result: verified=False  —  expression simplifies to (x + 1)**2, not x**2 + 1
  → verify_math((x+1)**2, claimed_result=x**2 + 2*x + 1)  [real MCP call]
    MCP result: verified=True

  [Assistant] Corrected: (x+1)^2 = x^2 + 2x + 1 — verified, not x^2 + 1.
```

---

## Deploy remotely (Amazon Bedrock AgentCore Gateway)

The HTTP transport (`--http`, container in [`Dockerfile`](Dockerfile)) exposes a standard MCP
endpoint at `/mcp`. Point **AgentCore Gateway** at it to turn these verifiers into tools any
Bedrock agent can call:

```bash
docker build -t verifier-mcp .
docker run -p 8000:8000 verifier-mcp          # MCP over HTTP at http://localhost:8000/mcp
```

---

## SQL verification

`verify_sql` checks syntax with [sqlglot](https://github.com/tobymao/sqlglot) for many dialects
(`sqlite`, `postgres`, `mysql`, `bigquery`, `snowflake`, `tsql`, `duckdb`, ...). It then transpiles
the query to SQLite and runs it, after your `setup_sql` (CREATE TABLE / INSERT), in a throwaway
in-memory database. `ATTACH`, extension loading and file-touching PRAGMAs are blocked and
execution is time-limited. Pass `expected_rows` to get `matches_expected` plus a diff of missing
and unexpected rows (order-insensitive unless `ordered=true`).

```json
{"query": "SELECT name FROM users WHERE name ILIKE 'a%'", "dialect": "postgres",
 "setup_sql": "CREATE TABLE users (id INT, name TEXT); INSERT INTO users VALUES (1,'Ana'),(2,'Bo');",
 "expected_rows": [["Ana"]]}
```

Execution is SQLite, so dialect-specific features that can't be transpiled are reported as
errors; syntax checking still covers the original dialect.

## The sandbox

`run_code` executes snippets in a fresh `python -I -S` subprocess with **no inherited
environment**, a **temp working dir**, and POSIX **resource limits** (CPU, memory, no forking,
no file writes) plus a wall-clock timeout. That is appropriate for a local dev tool. For
untrusted, multi-tenant use, run the whole server inside a container / gVisor / Firecracker —
the subprocess limits are defense-in-depth, not a complete jail. On **Windows** the
CPU/memory/fork limits are not applied (only the timeout), so prefer running it in a container there.

---

## Releasing

Bump the version in `pyproject.toml`, `src/verifier_mcp/__init__.py` and `server.json`, then
publish a GitHub release. [`publish.yml`](.github/workflows/publish.yml) builds the package,
publishes it to PyPI with Trusted Publishing (no tokens) and then to the Official MCP Registry
via GitHub OIDC.

## Tests

```bash
pip install -e ".[dev]"
pytest -q      # all pass — tool logic + MCP protocol registration/dispatch
```

## Tech stack

**Model Context Protocol** (FastMCP) · **SymPy** · **sqlglot** · **SQLite** · **jsonschema** · **Pint** · **FastAPI** ·
**Docker** · **GitHub Actions** · Amazon Bedrock AgentCore Gateway–ready

## License

MIT © Alex Omra
