verifier-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.
- verifier_mcp-0.1.0/.env.example +4 -0
- verifier_mcp-0.1.0/.github/workflows/ci.yml +26 -0
- verifier_mcp-0.1.0/.github/workflows/publish.yml +59 -0
- verifier_mcp-0.1.0/.gitignore +17 -0
- verifier_mcp-0.1.0/Dockerfile +13 -0
- verifier_mcp-0.1.0/LICENSE +21 -0
- verifier_mcp-0.1.0/PKG-INFO +185 -0
- verifier_mcp-0.1.0/README.md +144 -0
- verifier_mcp-0.1.0/docs/images/playground.png +0 -0
- verifier_mcp-0.1.0/examples/self_checking_agent.py +106 -0
- verifier_mcp-0.1.0/pyproject.toml +62 -0
- verifier_mcp-0.1.0/pytest.ini +4 -0
- verifier_mcp-0.1.0/requirements-demo.txt +5 -0
- verifier_mcp-0.1.0/requirements.txt +6 -0
- verifier_mcp-0.1.0/server.json +21 -0
- verifier_mcp-0.1.0/src/verifier_mcp/__init__.py +3 -0
- verifier_mcp-0.1.0/src/verifier_mcp/playground.py +85 -0
- verifier_mcp-0.1.0/src/verifier_mcp/server.py +77 -0
- verifier_mcp-0.1.0/src/verifier_mcp/tools/__init__.py +16 -0
- verifier_mcp-0.1.0/src/verifier_mcp/tools/code_tools.py +71 -0
- verifier_mcp-0.1.0/src/verifier_mcp/tools/math_tools.py +197 -0
- verifier_mcp-0.1.0/src/verifier_mcp/tools/regex_tools.py +44 -0
- verifier_mcp-0.1.0/src/verifier_mcp/tools/schema_tools.py +41 -0
- verifier_mcp-0.1.0/src/verifier_mcp/tools/units_tools.py +60 -0
- verifier_mcp-0.1.0/src/verifier_mcp/web/index.html +150 -0
- verifier_mcp-0.1.0/tests/test_server.py +28 -0
- verifier_mcp-0.1.0/tests/test_tools.py +118 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: ${{ matrix.python-version }}
|
|
20
|
+
- run: |
|
|
21
|
+
python -m pip install --upgrade pip
|
|
22
|
+
pip install -e ".[dev]"
|
|
23
|
+
- name: Lint
|
|
24
|
+
run: ruff check src tests
|
|
25
|
+
- name: Test
|
|
26
|
+
run: pytest -q
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
name: Publish to PyPI and MCP Registry
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
|
+
with:
|
|
15
|
+
python-version: "3.12"
|
|
16
|
+
- run: python -m pip install --upgrade build twine
|
|
17
|
+
- run: python -m build
|
|
18
|
+
- run: python -m twine check dist/*
|
|
19
|
+
- uses: actions/upload-artifact@v4
|
|
20
|
+
with:
|
|
21
|
+
name: dist
|
|
22
|
+
path: dist/
|
|
23
|
+
|
|
24
|
+
publish:
|
|
25
|
+
needs: build
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
environment:
|
|
28
|
+
name: pypi
|
|
29
|
+
url: https://pypi.org/project/verifier-mcp/
|
|
30
|
+
permissions:
|
|
31
|
+
id-token: write # PyPI Trusted Publishing (no API token needed)
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/download-artifact@v4
|
|
34
|
+
with:
|
|
35
|
+
name: dist
|
|
36
|
+
path: dist/
|
|
37
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
38
|
+
|
|
39
|
+
mcp-registry:
|
|
40
|
+
needs: publish
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
permissions:
|
|
43
|
+
id-token: write # GitHub OIDC login to the MCP Registry
|
|
44
|
+
contents: read
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@v4
|
|
47
|
+
- name: Wait for PyPI to serve the new version
|
|
48
|
+
run: |
|
|
49
|
+
V=$(jq -r .version server.json)
|
|
50
|
+
for i in $(seq 1 30); do
|
|
51
|
+
curl -fsS "https://pypi.org/pypi/verifier-mcp/$V/json" >/dev/null && exit 0
|
|
52
|
+
sleep 10
|
|
53
|
+
done
|
|
54
|
+
echo "verifier-mcp $V not on PyPI yet" && exit 1
|
|
55
|
+
- name: Install mcp-publisher
|
|
56
|
+
run: |
|
|
57
|
+
curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher
|
|
58
|
+
- run: ./mcp-publisher login github-oidc
|
|
59
|
+
- run: ./mcp-publisher publish
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# VerifierMCP — HTTP transport (for remote clients / Amazon Bedrock AgentCore Gateway).
|
|
2
|
+
FROM python:3.12-slim
|
|
3
|
+
|
|
4
|
+
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 PIP_NO_CACHE_DIR=1
|
|
5
|
+
WORKDIR /app
|
|
6
|
+
|
|
7
|
+
COPY pyproject.toml README.md LICENSE ./
|
|
8
|
+
COPY src/ ./src/
|
|
9
|
+
RUN pip install --no-cache-dir .
|
|
10
|
+
|
|
11
|
+
EXPOSE 8000
|
|
12
|
+
# Streamable HTTP MCP endpoint on :8000/mcp
|
|
13
|
+
CMD ["verifier-mcp", "--http", "--host", "0.0.0.0", "--port", "8000"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arash Omranpour
|
|
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,185 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: verifier-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An MCP server that lets any LLM check its own work: symbolic math, sandboxed code, JSON-Schema, units and regex verification.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Arashomranpour/Verifier_MCP
|
|
6
|
+
Project-URL: Repository, https://github.com/Arashomranpour/Verifier_MCP
|
|
7
|
+
Project-URL: Issues, https://github.com/Arashomranpour/Verifier_MCP/issues
|
|
8
|
+
Author: Arash Omranpour
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,jsonschema,llm,mcp,model-context-protocol,sympy,verification
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
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: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Software Development :: Testing
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: jsonschema>=4.20
|
|
24
|
+
Requires-Dist: mcp<2,>=1.9
|
|
25
|
+
Requires-Dist: pint>=0.23
|
|
26
|
+
Requires-Dist: sympy>=1.12
|
|
27
|
+
Provides-Extra: demo
|
|
28
|
+
Requires-Dist: langchain-groq>=0.2; extra == 'demo'
|
|
29
|
+
Requires-Dist: langchain-mcp-adapters>=0.1; extra == 'demo'
|
|
30
|
+
Requires-Dist: langgraph>=0.2; extra == 'demo'
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: fastapi>=0.110; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
35
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
36
|
+
Requires-Dist: uvicorn>=0.29; extra == 'dev'
|
|
37
|
+
Provides-Extra: web
|
|
38
|
+
Requires-Dist: fastapi>=0.110; extra == 'web'
|
|
39
|
+
Requires-Dist: uvicorn>=0.29; extra == 'web'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# VerifierMCP
|
|
43
|
+
|
|
44
|
+
<!-- mcp-name: io.github.Arashomranpour/verifier-mcp -->
|
|
45
|
+
|
|
46
|
+
> An **MCP server** that gives any LLM the power to **check its own work**.
|
|
47
|
+
> Instead of trusting a model's arithmetic, regex, JSON or "the code prints X", the model
|
|
48
|
+
> can *call a tool and verify it*. Five verification tools over the
|
|
49
|
+
> [Model Context Protocol](https://modelcontextprotocol.io): symbolic math, sandboxed code
|
|
50
|
+
> execution, JSON-Schema validation, dimensional analysis, and regex testing.
|
|
51
|
+
|
|
52
|
+
<p align="center">
|
|
53
|
+
<img src="https://raw.githubusercontent.com/Arashomranpour/Verifier_MCP/main/docs/images/playground.png" alt="VerifierMCP playground catching errors live" width="880">
|
|
54
|
+
</p>
|
|
55
|
+
|
|
56
|
+
Built with the official **MCP Python SDK** (FastMCP). Works in **Claude Desktop** and any
|
|
57
|
+
MCP client over **stdio**, or remotely over **streamable HTTP** (e.g. behind **Amazon Bedrock
|
|
58
|
+
AgentCore Gateway**).
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Why it matters
|
|
63
|
+
|
|
64
|
+
LLMs are confidently wrong about exactly the things that are *mechanically checkable*:
|
|
65
|
+
`(x+1)² = x²+1`, a regex that doesn't quite match, JSON that violates its schema, a unit
|
|
66
|
+
slip, "this function returns 5050". VerifierMCP turns each of those into a tool call, so an
|
|
67
|
+
agent can **replace an assertion with a verified fact**.
|
|
68
|
+
|
|
69
|
+
## The tools
|
|
70
|
+
|
|
71
|
+
| Tool | Checks | Engine |
|
|
72
|
+
|------|--------|--------|
|
|
73
|
+
| `verify_math` | Is an equation an identity? Does a claimed result hold? | SymPy |
|
|
74
|
+
| `run_code` | What does this Python snippet *actually* output? | sandboxed subprocess |
|
|
75
|
+
| `validate_schema` | Does this JSON conform to its JSON Schema? | jsonschema (Draft 2020-12) |
|
|
76
|
+
| `check_units` | Is this quantity/equation dimensionally correct? | Pint |
|
|
77
|
+
| `test_regex` | Does this regex match/reject the right cases? | `re` |
|
|
78
|
+
|
|
79
|
+
Each tool body lives in [`src/verifier_mcp/tools/`](src/verifier_mcp/tools/) as a pure
|
|
80
|
+
function, so it is unit-tested without the protocol and reused by the web playground.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Quickstart
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install verifier-mcp # or: pip install "verifier-mcp[web]" for the playground
|
|
88
|
+
|
|
89
|
+
# Run the MCP server over stdio (what Claude Desktop launches)
|
|
90
|
+
verifier-mcp
|
|
91
|
+
|
|
92
|
+
# Or serve it over HTTP (MCP streamable transport on :8000/mcp)
|
|
93
|
+
verifier-mcp --http
|
|
94
|
+
|
|
95
|
+
# See it in action — the visual playground (needs the [web] extra)
|
|
96
|
+
uvicorn verifier_mcp.playground:app --port 8080 # http://localhost:8080
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Connect to Claude Desktop
|
|
100
|
+
|
|
101
|
+
Add to `claude_desktop_config.json`:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"mcpServers": {
|
|
106
|
+
"verifier": {
|
|
107
|
+
"command": "uvx",
|
|
108
|
+
"args": ["verifier-mcp"]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Restart Claude Desktop and ask it something like *"Is (x+1)² equal to x²+1? Use the verifier."*
|
|
115
|
+
— it will call `verify_math` and come back with the checked answer.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Self-checking agent demo (Groq + MCP)
|
|
120
|
+
|
|
121
|
+
[`examples/self_checking_agent.py`](examples/self_checking_agent.py) connects a **Groq** LLM to
|
|
122
|
+
this server over **real MCP** (via `langchain-mcp-adapters`), instructs it to *verify before
|
|
123
|
+
asserting*, and watches it catch its own mistake:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
pip install -r requirements-demo.txt
|
|
127
|
+
export GROQ_API_KEY=gsk_... # real Groq agent
|
|
128
|
+
python examples/self_checking_agent.py
|
|
129
|
+
|
|
130
|
+
python examples/self_checking_agent.py --offline # no key: scripted LLM, REAL MCP verification
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```text
|
|
134
|
+
[offline] Question: Is (x+1)^2 equal to x^2 + 1? If not, what is the correct expansion?
|
|
135
|
+
|
|
136
|
+
[Assistant] draft answer: "(x+1)^2 = x**2 + 1"
|
|
137
|
+
→ verify_math((x+1)**2, claimed_result=x**2 + 1) [real MCP call]
|
|
138
|
+
MCP result: verified=False — expression simplifies to (x + 1)**2, not x**2 + 1
|
|
139
|
+
→ verify_math((x+1)**2, claimed_result=x**2 + 2*x + 1) [real MCP call]
|
|
140
|
+
MCP result: verified=True
|
|
141
|
+
|
|
142
|
+
[Assistant] Corrected: (x+1)^2 = x^2 + 2x + 1 — verified, not x^2 + 1.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Deploy remotely (Amazon Bedrock AgentCore Gateway)
|
|
148
|
+
|
|
149
|
+
The HTTP transport (`--http`, container in [`Dockerfile`](Dockerfile)) exposes a standard MCP
|
|
150
|
+
endpoint at `/mcp`. Point **AgentCore Gateway** at it to turn these verifiers into tools any
|
|
151
|
+
Bedrock agent can call:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
docker build -t verifier-mcp .
|
|
155
|
+
docker run -p 8000:8000 verifier-mcp # MCP over HTTP at http://localhost:8000/mcp
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## The sandbox
|
|
161
|
+
|
|
162
|
+
`run_code` executes snippets in a fresh `python -I -S` subprocess with **no inherited
|
|
163
|
+
environment**, a **temp working dir**, and POSIX **resource limits** (CPU, memory, no forking,
|
|
164
|
+
no file writes) plus a wall-clock timeout. That is appropriate for a local dev tool. For
|
|
165
|
+
untrusted, multi-tenant use, run the whole server inside a container / gVisor / Firecracker —
|
|
166
|
+
the subprocess limits are defense-in-depth, not a complete jail. On **Windows** the
|
|
167
|
+
CPU/memory/fork limits are not applied (only the timeout), so prefer running it in a container there.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Tests
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
pip install -e ".[dev]"
|
|
175
|
+
pytest -q # all pass — tool logic + MCP protocol registration/dispatch
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Tech stack
|
|
179
|
+
|
|
180
|
+
**Model Context Protocol** (FastMCP) · **SymPy** · **jsonschema** · **Pint** · **FastAPI** ·
|
|
181
|
+
**Docker** · **GitHub Actions** · Amazon Bedrock AgentCore Gateway–ready
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT © Arash Omranpour
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# VerifierMCP
|
|
2
|
+
|
|
3
|
+
<!-- mcp-name: io.github.Arashomranpour/verifier-mcp -->
|
|
4
|
+
|
|
5
|
+
> An **MCP server** that gives any LLM the power to **check its own work**.
|
|
6
|
+
> Instead of trusting a model's arithmetic, regex, JSON or "the code prints X", the model
|
|
7
|
+
> can *call a tool and verify it*. Five verification tools over the
|
|
8
|
+
> [Model Context Protocol](https://modelcontextprotocol.io): symbolic math, sandboxed code
|
|
9
|
+
> execution, JSON-Schema validation, dimensional analysis, and regex testing.
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<img src="https://raw.githubusercontent.com/Arashomranpour/Verifier_MCP/main/docs/images/playground.png" alt="VerifierMCP playground catching errors live" width="880">
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
Built with the official **MCP Python SDK** (FastMCP). Works in **Claude Desktop** and any
|
|
16
|
+
MCP client over **stdio**, or remotely over **streamable HTTP** (e.g. behind **Amazon Bedrock
|
|
17
|
+
AgentCore Gateway**).
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Why it matters
|
|
22
|
+
|
|
23
|
+
LLMs are confidently wrong about exactly the things that are *mechanically checkable*:
|
|
24
|
+
`(x+1)² = x²+1`, a regex that doesn't quite match, JSON that violates its schema, a unit
|
|
25
|
+
slip, "this function returns 5050". VerifierMCP turns each of those into a tool call, so an
|
|
26
|
+
agent can **replace an assertion with a verified fact**.
|
|
27
|
+
|
|
28
|
+
## The tools
|
|
29
|
+
|
|
30
|
+
| Tool | Checks | Engine |
|
|
31
|
+
|------|--------|--------|
|
|
32
|
+
| `verify_math` | Is an equation an identity? Does a claimed result hold? | SymPy |
|
|
33
|
+
| `run_code` | What does this Python snippet *actually* output? | sandboxed subprocess |
|
|
34
|
+
| `validate_schema` | Does this JSON conform to its JSON Schema? | jsonschema (Draft 2020-12) |
|
|
35
|
+
| `check_units` | Is this quantity/equation dimensionally correct? | Pint |
|
|
36
|
+
| `test_regex` | Does this regex match/reject the right cases? | `re` |
|
|
37
|
+
|
|
38
|
+
Each tool body lives in [`src/verifier_mcp/tools/`](src/verifier_mcp/tools/) as a pure
|
|
39
|
+
function, so it is unit-tested without the protocol and reused by the web playground.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Quickstart
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install verifier-mcp # or: pip install "verifier-mcp[web]" for the playground
|
|
47
|
+
|
|
48
|
+
# Run the MCP server over stdio (what Claude Desktop launches)
|
|
49
|
+
verifier-mcp
|
|
50
|
+
|
|
51
|
+
# Or serve it over HTTP (MCP streamable transport on :8000/mcp)
|
|
52
|
+
verifier-mcp --http
|
|
53
|
+
|
|
54
|
+
# See it in action — the visual playground (needs the [web] extra)
|
|
55
|
+
uvicorn verifier_mcp.playground:app --port 8080 # http://localhost:8080
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Connect to Claude Desktop
|
|
59
|
+
|
|
60
|
+
Add to `claude_desktop_config.json`:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"mcpServers": {
|
|
65
|
+
"verifier": {
|
|
66
|
+
"command": "uvx",
|
|
67
|
+
"args": ["verifier-mcp"]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Restart Claude Desktop and ask it something like *"Is (x+1)² equal to x²+1? Use the verifier."*
|
|
74
|
+
— it will call `verify_math` and come back with the checked answer.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Self-checking agent demo (Groq + MCP)
|
|
79
|
+
|
|
80
|
+
[`examples/self_checking_agent.py`](examples/self_checking_agent.py) connects a **Groq** LLM to
|
|
81
|
+
this server over **real MCP** (via `langchain-mcp-adapters`), instructs it to *verify before
|
|
82
|
+
asserting*, and watches it catch its own mistake:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install -r requirements-demo.txt
|
|
86
|
+
export GROQ_API_KEY=gsk_... # real Groq agent
|
|
87
|
+
python examples/self_checking_agent.py
|
|
88
|
+
|
|
89
|
+
python examples/self_checking_agent.py --offline # no key: scripted LLM, REAL MCP verification
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
[offline] Question: Is (x+1)^2 equal to x^2 + 1? If not, what is the correct expansion?
|
|
94
|
+
|
|
95
|
+
[Assistant] draft answer: "(x+1)^2 = x**2 + 1"
|
|
96
|
+
→ verify_math((x+1)**2, claimed_result=x**2 + 1) [real MCP call]
|
|
97
|
+
MCP result: verified=False — expression simplifies to (x + 1)**2, not x**2 + 1
|
|
98
|
+
→ verify_math((x+1)**2, claimed_result=x**2 + 2*x + 1) [real MCP call]
|
|
99
|
+
MCP result: verified=True
|
|
100
|
+
|
|
101
|
+
[Assistant] Corrected: (x+1)^2 = x^2 + 2x + 1 — verified, not x^2 + 1.
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Deploy remotely (Amazon Bedrock AgentCore Gateway)
|
|
107
|
+
|
|
108
|
+
The HTTP transport (`--http`, container in [`Dockerfile`](Dockerfile)) exposes a standard MCP
|
|
109
|
+
endpoint at `/mcp`. Point **AgentCore Gateway** at it to turn these verifiers into tools any
|
|
110
|
+
Bedrock agent can call:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
docker build -t verifier-mcp .
|
|
114
|
+
docker run -p 8000:8000 verifier-mcp # MCP over HTTP at http://localhost:8000/mcp
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## The sandbox
|
|
120
|
+
|
|
121
|
+
`run_code` executes snippets in a fresh `python -I -S` subprocess with **no inherited
|
|
122
|
+
environment**, a **temp working dir**, and POSIX **resource limits** (CPU, memory, no forking,
|
|
123
|
+
no file writes) plus a wall-clock timeout. That is appropriate for a local dev tool. For
|
|
124
|
+
untrusted, multi-tenant use, run the whole server inside a container / gVisor / Firecracker —
|
|
125
|
+
the subprocess limits are defense-in-depth, not a complete jail. On **Windows** the
|
|
126
|
+
CPU/memory/fork limits are not applied (only the timeout), so prefer running it in a container there.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Tests
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
pip install -e ".[dev]"
|
|
134
|
+
pytest -q # all pass — tool logic + MCP protocol registration/dispatch
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Tech stack
|
|
138
|
+
|
|
139
|
+
**Model Context Protocol** (FastMCP) · **SymPy** · **jsonschema** · **Pint** · **FastAPI** ·
|
|
140
|
+
**Docker** · **GitHub Actions** · Amazon Bedrock AgentCore Gateway–ready
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT © Arash Omranpour
|
|
Binary file
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""A self-checking agent: Groq LLM + VerifierMCP tools, connected over real MCP.
|
|
2
|
+
|
|
3
|
+
The agent is told to *verify before asserting*. It loads the VerifierMCP server's tools
|
|
4
|
+
through the Model Context Protocol (langchain-mcp-adapters), binds them to a Groq model,
|
|
5
|
+
and solves a problem — calling verify_math / run_code to check itself instead of trusting
|
|
6
|
+
its own arithmetic.
|
|
7
|
+
|
|
8
|
+
export GROQ_API_KEY=gsk_... # real LLM
|
|
9
|
+
python examples/self_checking_agent.py
|
|
10
|
+
|
|
11
|
+
python examples/self_checking_agent.py --offline # no key: scripted reasoning,
|
|
12
|
+
# but the verification is REAL MCP
|
|
13
|
+
|
|
14
|
+
Run from the repo root.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import asyncio
|
|
21
|
+
import os
|
|
22
|
+
import sys
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
from langchain_mcp_adapters.client import MultiServerMCPClient
|
|
26
|
+
|
|
27
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
28
|
+
SRC = str(ROOT / "src")
|
|
29
|
+
|
|
30
|
+
QUESTION = "Is (x+1)^2 equal to x^2 + 1? If not, what is the correct expansion?"
|
|
31
|
+
|
|
32
|
+
SYSTEM = (
|
|
33
|
+
"You are a careful assistant with verification tools. You must NOT state a mathematical "
|
|
34
|
+
"result without first calling verify_math to check it. Use the tools, then answer."
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _client() -> MultiServerMCPClient:
|
|
39
|
+
return MultiServerMCPClient({
|
|
40
|
+
"verifier": {
|
|
41
|
+
"command": sys.executable,
|
|
42
|
+
"args": ["-m", "verifier_mcp.server"],
|
|
43
|
+
"transport": "stdio",
|
|
44
|
+
"env": {"PYTHONPATH": SRC},
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
async def run_with_groq() -> None:
|
|
50
|
+
from langchain_groq import ChatGroq
|
|
51
|
+
from langgraph.prebuilt import create_react_agent
|
|
52
|
+
|
|
53
|
+
tools = await _client().get_tools()
|
|
54
|
+
model = ChatGroq(model=os.getenv("GROQ_MODEL", "llama-3.3-70b-versatile"), temperature=0)
|
|
55
|
+
agent = create_react_agent(model, tools, prompt=SYSTEM)
|
|
56
|
+
|
|
57
|
+
print(f"\n[Groq] Question: {QUESTION}\n")
|
|
58
|
+
result = await agent.ainvoke({"messages": [("user", QUESTION)]})
|
|
59
|
+
for m in result["messages"]:
|
|
60
|
+
role = m.__class__.__name__.replace("Message", "")
|
|
61
|
+
if getattr(m, "tool_calls", None):
|
|
62
|
+
for tc in m.tool_calls:
|
|
63
|
+
print(f" → tool call: {tc['name']}({tc['args']})")
|
|
64
|
+
elif m.content:
|
|
65
|
+
print(f" [{role}] {m.content}")
|
|
66
|
+
print()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
async def run_offline() -> None:
|
|
70
|
+
"""No API key: a scripted 'LLM' makes a wrong claim, then the REAL MCP tool corrects it."""
|
|
71
|
+
tools = {t.name: t for t in await _client().get_tools()}
|
|
72
|
+
verify = tools["verify_math"]
|
|
73
|
+
|
|
74
|
+
print(f"\n[offline] Question: {QUESTION}\n")
|
|
75
|
+
claim = "x**2 + 1"
|
|
76
|
+
import json
|
|
77
|
+
|
|
78
|
+
def _payload(res) -> dict:
|
|
79
|
+
return json.loads(res[0]["text"] if isinstance(res, list) else str(res))
|
|
80
|
+
|
|
81
|
+
print(f' [Assistant] draft answer: "(x+1)^2 = {claim}"')
|
|
82
|
+
print(" → verify_math((x+1)**2, claimed_result=x**2 + 1) [real MCP call]")
|
|
83
|
+
res = _payload(await verify.ainvoke({"expression": "(x+1)**2", "claimed_result": claim}))
|
|
84
|
+
print(f" MCP result: verified={res['verified']} — {res['detail']}")
|
|
85
|
+
|
|
86
|
+
# The verifier said False, so the agent corrects itself.
|
|
87
|
+
print(" → verify_math((x+1)**2, claimed_result=x**2 + 2*x + 1) [real MCP call]")
|
|
88
|
+
correct = _payload(await verify.ainvoke({"expression": "(x+1)**2", "claimed_result": "x**2 + 2*x + 1"}))
|
|
89
|
+
print(f" MCP result: verified={correct['verified']}")
|
|
90
|
+
print('\n [Assistant] Corrected: (x+1)^2 = x^2 + 2x + 1 — verified, not x^2 + 1.\n')
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def main() -> None:
|
|
94
|
+
ap = argparse.ArgumentParser()
|
|
95
|
+
ap.add_argument("--offline", action="store_true", help="run without a Groq key (real MCP, scripted LLM)")
|
|
96
|
+
args = ap.parse_args()
|
|
97
|
+
if args.offline or not os.getenv("GROQ_API_KEY"):
|
|
98
|
+
if not args.offline:
|
|
99
|
+
print("GROQ_API_KEY not set — running --offline (verification is still real MCP).")
|
|
100
|
+
asyncio.run(run_offline())
|
|
101
|
+
else:
|
|
102
|
+
asyncio.run(run_with_groq())
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
if __name__ == "__main__":
|
|
106
|
+
main()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "verifier-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "An MCP server that lets any LLM check its own work: symbolic math, sandboxed code, JSON-Schema, units and regex verification."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Arash Omranpour" }]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
24
|
+
"Topic :: Software Development :: Testing",
|
|
25
|
+
]
|
|
26
|
+
keywords = ["mcp", "model-context-protocol", "llm", "verification", "agents", "sympy", "jsonschema"]
|
|
27
|
+
|
|
28
|
+
dependencies = [
|
|
29
|
+
"mcp>=1.9,<2",
|
|
30
|
+
"sympy>=1.12",
|
|
31
|
+
"jsonschema>=4.20",
|
|
32
|
+
"pint>=0.23",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/Arashomranpour/Verifier_MCP"
|
|
37
|
+
Repository = "https://github.com/Arashomranpour/Verifier_MCP"
|
|
38
|
+
Issues = "https://github.com/Arashomranpour/Verifier_MCP/issues"
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
web = ["fastapi>=0.110", "uvicorn>=0.29"]
|
|
42
|
+
demo = ["langchain-mcp-adapters>=0.1", "langgraph>=0.2", "langchain-groq>=0.2"]
|
|
43
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.23", "ruff>=0.5", "fastapi>=0.110", "uvicorn>=0.29"]
|
|
44
|
+
|
|
45
|
+
[project.scripts]
|
|
46
|
+
verifier-mcp = "verifier_mcp.server:main"
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.wheel]
|
|
49
|
+
packages = ["src/verifier_mcp"]
|
|
50
|
+
|
|
51
|
+
[tool.pytest.ini_options]
|
|
52
|
+
pythonpath = ["src"]
|
|
53
|
+
asyncio_mode = "auto"
|
|
54
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
line-length = 110
|
|
58
|
+
target-version = "py310"
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint]
|
|
61
|
+
# re.I/re.M aliases are intentional and readable here.
|
|
62
|
+
ignore = ["FURB167", "TRY004"]
|