Adversarial input harness for MCP servers. Replay injection / oversize / traversal fixtures against any MCP server and assert it stays sane.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_adversarial-0.1.0.tar.gz.
File metadata
- Download URL: mcp_adversarial-0.1.0.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5a4e3ee9e7fe1bba1892cced4854d6f35f28734f26f3bf77d1b57d5fe0b05dd
|
|
| MD5 |
07a29de5b3b775d11f729fcd9f2adbf1
|
|
| BLAKE2b-256 |
4861c7bd6c06d13a3bc97aeb47de24201285b5d2639069071ff9758d875e9184
|
Provenance
The following attestation bundles were made for mcp_adversarial-0.1.0.tar.gz:
Publisher:
release-mcp-adversarial.yml on sanjeevkkansal/tf-review-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_adversarial-0.1.0.tar.gz -
Subject digest:
b5a4e3ee9e7fe1bba1892cced4854d6f35f28734f26f3bf77d1b57d5fe0b05dd - Sigstore transparency entry: 1664390347
- Sigstore integration time:
-
Permalink:
sanjeevkkansal/tf-review-mcp@a6db63d49789f0e9fb8f4cb2c38208f5c9c7c6b2 -
Branch / Tag:
refs/tags/mcp-adversarial-v0.1.0 - Owner: https://github.com/sanjeevkkansal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-mcp-adversarial.yml@a6db63d49789f0e9fb8f4cb2c38208f5c9c7c6b2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mcp_adversarial-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcp_adversarial-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
796faa7635571dbbb36b18a30f58ea2df45168a425f8f3e629eadd9eda841eb6
|
|
| MD5 |
574624d0a72e74b59785e0ac6d195190
|
|
| BLAKE2b-256 |
0184c5fc4e0e62b40e128cd64d0cbb6dcee36d5b6c8e50e008ed165989b70719
|
Provenance
The following attestation bundles were made for mcp_adversarial-0.1.0-py3-none-any.whl:
Publisher:
release-mcp-adversarial.yml on sanjeevkkansal/tf-review-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_adversarial-0.1.0-py3-none-any.whl -
Subject digest:
796faa7635571dbbb36b18a30f58ea2df45168a425f8f3e629eadd9eda841eb6 - Sigstore transparency entry: 1664390459
- Sigstore integration time:
-
Permalink:
sanjeevkkansal/tf-review-mcp@a6db63d49789f0e9fb8f4cb2c38208f5c9c7c6b2 -
Branch / Tag:
refs/tags/mcp-adversarial-v0.1.0 - Owner: https://github.com/sanjeevkkansal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-mcp-adversarial.yml@a6db63d49789f0e9fb8f4cb2c38208f5c9c7c6b2 -
Trigger Event:
push
-
Statement type: