mcp-adversarial
Adversarial input harness for MCP servers. Spawn any MCP server as a subprocess, replay a set of fixtures against every tool it advertises, and assert it does not crash, leak control characters into output, or exfiltrate sentinel strings.
Install
pip install mcp-adversarial
Or for one-off runs:
pipx run mcp-adversarial run --server "your-server-cmd"
Quickstart
mcp-adversarial run --server "your-mcp-server"
Output:
ran 12 fixtures: 12 passed, 0 failed
[PASS] generic_injection_preamble (injection) -> review_plan
[PASS] generic_control_chars (sanitize) -> review_plan
...
Exit code is non-zero if any fixture fails. Designed to slot directly into CI.
How it works
- Spawn. The harness launches your server with
shlex.splitand wires stdin / stdout / stderr to PIPE. - Handshake. It drives the standard MCP JSON-RPC handshake:
initialize, thenotifications/initializedack, thentools/listto see what the server advertises. - Replay. For each fixture, it calls
tools/callwith the fixture's args. Fixtures can pin a specific tool name, or omit the tool to fan out across every advertised tool. Plan-shaped fixtures can stage temp files viasetup.write_files; the harness rewrites absolute paths in args to the staged location. - Assert. For each call the harness checks:
- No Python traceback appears on the server's stderr between calls.
- No disallowed control characters appear in tool output.
- No configured sentinel string appears in tool output.
A failure is annotated with the tool name and the specific reason.
Reports can be written to a JSON file via --report.
Fixtures
Two categories ship in the package by default.
generic/ are MCP-shaped payloads with no tool pinning, so the
harness fans them out across whatever tools the server has:
injection_preamble.json: known prompt-injection preambles (system:,Ignore previous, ChatML role tokens).control_chars.json: BEL / ESC / DEL / NUL embedded in strings.oversize_string.json: 8KB strings in common arg slots.path_traversal.json:..//..\\//etc/passwdpatterns.unicode_format.json: RTL override + zero-width characters.
terraform/ are Terraform-plan-shaped payloads scoped to
tf-review-mcp's tool surface. They exist because tf-review-mcp is
this package's first canary; other MCP servers can copy the pattern
without inheriting the schema.
Bring your own fixtures with --fixtures path/to/dir/. Each fixture
is one JSON file:
{
"id": "your-fixture-id",
"category": "injection",
"tool": "the_tool_name",
"args": {"plan_json_path": "/tmp/plan.json"},
"setup": {"write_files": {"/tmp/plan.json": "<content>"}}
}
Omit tool to fan out. setup.write_files is optional; absolute
path placeholders in args are rewritten to the staged location.
Public API
from mcp_adversarial import (
sanitize_for_model, # strip control chars, mark injection lines, truncate
sanitize_address, # validate a dotted resource address (raises on traversal)
sanitize_address_or_marker, # never-raise variant (returns "[invalid-address]")
)
from mcp_adversarial.runner import run_harness, MCPStdioClient
sanitize_for_model and the address helpers are usable independently
of the harness, e.g. inside your own server's serialization layer.
Tested against
tf-review-mcp is
the first canary. Its CI runs the full fixture set against the real
server on every commit (see
packages/tf-review-mcp/tests/test_adversarial_canary.py).
You can run the same suite against any other MCP server. PRs adding new canary integrations welcome.
Roadmap
- A JSON schema for fixture validation in editor / CI.
- More fixture categories: tool-name collision, oversize
tools/listresponses, malformed JSON-RPC envelopes. - A GitHub Action that runs the harness against a server command on every PR and posts the report.
- Optional fuzzing mode on top of the static fixtures.
License
MIT.
Release files for mcp-adversarial 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mcp_adversarial-0.1.0.tar.gz | 15.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_adversarial-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.5 kB
Release files / mcp_adversarial-0.1.0.tar.gz
| Download URL | mcp_adversarial-0.1.0.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5a4e3ee9e7fe1bba1892cced4854d6f35f28734f26f3bf77d1b57d5fe0b05dd
|
|
BLAKE2b-256 checksum How to use checksums |
4861c7bd6c06d13a3bc97aeb47de24201285b5d2639069071ff9758d875e9184
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 29, 2026.
Transparency logRelease files / mcp_adversarial-0.1.0-py3-none-any.whl
| Download URL | mcp_adversarial-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
796faa7635571dbbb36b18a30f58ea2df45168a425f8f3e629eadd9eda841eb6
|
|
BLAKE2b-256 checksum How to use checksums |
0184c5fc4e0e62b40e128cd64d0cbb6dcee36d5b6c8e50e008ed165989b70719
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 29, 2026.
Transparency log