Skip to content

About

courier — offline, LLM-free adversarial auditor for MCP Multi-Round-Trip Requests (SEP-2322). Drives an MRT stdio server as a malicious client courier and grades whether it protects requestState (integrity, confidentiality, user-binding, replay). Ships a conformant reference server + a buggy one with 6 ground-truth defects.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Development Experiment 012 — courier

An offline, LLM-free, black-box adversarial auditor for MCP Multi-Round-Trip Requests (SEP-2322). courier drives an MRT stdio server through real round-trips while behaving as the malicious client courier the spec warns about — tampering with requestState, decoding it, replaying it, and crossing principals — and grades whether the server upholds its state-custody duties. It prints a scored report and returns a CI exit code. Pure Python standard library.

Thesis. MCP's 2026-07-28 release candidate deprecates server-initiated sampling/elicitation and replaces them with Multi Round-Trip Requests (SEP-2322): a server that needs more input mid-call returns an InputRequiredResult carrying an opaque requestState, and the client echoes it back on retry. That moves the server's continuation state through the client — a classic client-side-state trust boundary (ViewState, signed cookies, the OAuth state param), brand new in MCP. The spec says servers MUST always validate that state and MUST bind user-specific state to the caller, but only SHOULD encrypt it and explicitly permits plaintext. That gap is where real servers will bleed. courier is the smallest thing that proves it: it becomes the malicious courier and checks whether the server survives.

Why now

The MRT mechanism is landing across four SDK betas with the stable spec on 2026-07-28. The official modelcontextprotocol/conformance suite tests protocol shape; the Python SDK ships correct defaults. Neither one attacks a server as a hostile courier — and the spec's own Security Implications section says that is exactly the adversary to defend against:

"Because requestState passes through the client, malicious or compromised clients could attempt to modify it to alter server behavior, bypass authorization checks, or corrupt server logic." — SEP-2322

Install & run

Requires Python 3.11+. No third-party runtime dependencies.

# Audit the bundled conformant reference server (scores 100/A):
python -m courier --demo reference

# Audit the bundled buggy server (fails the gate, exit code 1):
python -m courier --demo buggy

# Audit ANY MRT stdio server — everything after `--` is the launch command:
python -m courier -- python my_server.py
python -m courier --json --min-score 90 -- node server.js

# One-command paths:
make run          # == python -m courier --demo reference
make demo-buggy

Run the tests (only dev dependency is pytest):

python -m pip install pytest
python -m pytest          # 30 tests

Sample run

Conformant reference server:

========================================================================
  courier — MCP Multi-Round-Trip (SEP-2322) state-custody audit
========================================================================
  target : python servers/reference_server.py

  PASS   round-trip-baseline     honest flow completed in 3 hop(s)
  PASS   tamper-integrity        server rejected tampered requestState
  n/a    state-tamper-exploit    state is sealed; targeted tamper not possible (blind tamper covered separately)
  PASS   user-binding            server rejected another user's in-flight state
  PASS   response-validation     server rejected / re-prompted on a schema-invalid answer
  PASS   state-confidentiality   state is opaque to the client (encoding=base64+bytes, entropy=6.69)
  PASS   replay-idempotency      replayed finalisation was rejected
  PASS   state-growth            state size stayed bounded (max 220B, x1.08)
------------------------------------------------------------------------
  score  : 100/100   grade A   (gate >= 80: PASS)
========================================================================

Buggy server (six ground-truth defects, including a confirmed money-moving exploit):

========================================================================
  courier — MCP Multi-Round-Trip (SEP-2322) state-custody audit
========================================================================
  target : python servers/buggy_server.py

  PASS   round-trip-baseline     honest flow completed in 3 hop(s)
  FAIL   tamper-integrity        server ACCEPTED tampered requestState and advanced the flow [HIGH]
  FAIL   state-tamper-exploit    EXPLOIT: edited 'amount' 100 -> 987654321; server executed the attacker's value [CRITICAL]
           - forced amount=987654321 (was 100); observed in result
  FAIL   user-binding            server accepted user 'alice' state under caller 'mallory' (cross-user hijack) [HIGH]
  FAIL   response-validation     server accepted a schema-invalid inputResponses value and advanced [MEDIUM]
  FAIL   state-confidentiality   client-readable state leaks 3 sensitive value(s) [HIGH]
           - leak: secret-bearing-key at $.mfa_secret (mfa_…4b)
           - leak: high-entropy-token at $.mfa_secret (mfa_…4b)
           - leak: email-address at $.operator_email (paym…al)
  FAIL   replay-idempotency      replay re-executed the side effect (exec 1 -> 2) [MEDIUM]
           - executions: 1 -> 2
  FAIL   state-growth            state grew 306B -> 535B across hops (x1.75) [WARN]
           - hop sizes: [306, 535] bytes
------------------------------------------------------------------------
  score  : 0/100   grade F   (gate >= 80: FAIL)
  NOTE   : a CRITICAL exploit was confirmed — grade capped at F.
========================================================================

The probe catalog

Each probe behaves as a hostile courier and enforces one SEP-2322 clause.

Probe Enforces (SEP-2322) Attack FAIL means
round-trip-baseline ephemeral MRT workflow honest 3-hop flow server can't even complete a legitimate MRT flow (BLOCKER)
tamper-integrity "servers MUST always validate that state" mutate requestState, resend server trusted tampered state and advanced
state-tamper-exploit Security Implications: state must not alter behaviour decode plaintext state, edit a money field, resend forged amount actually executed (CRITICAL)
user-binding "MUST cryptographically bind … and MUST verify … the currently authenticated user" replay user A's state as user B one user drove another's in-flight payment
response-validation "SHOULD validate … inputResponses" send schema-invalid answer content server consumed a malformed answer and advanced
state-confidentiality "SHOULD encrypt … for confidentiality"; opaque to client decode + secret/PII/entropy scan state is client-readable (HIGH if it leaks a secret)
replay-idempotency stateless finalisation hazard (best practice) replay the finalising call side effect fired twice (double-charge)
state-growth client must carry state every hop measure size across hops state grows unbounded (bandwidth/DoS/cost)

Scoring: start at 100, subtract a per-severity penalty for each FAIL (CRITICAL −45, HIGH −25, MEDIUM −12, LOW −5, WARN −3), clamp to 0–100. Any confirmed CRITICAL caps the grade at F. The CI gate is green only when the score clears --min-score (default 80) and nothing critical fired.

Architecture

                    tools/call  ─────────────►  ┌───────────────────┐
  ┌───────────────┐  (adversarial params)       │  target MRT server │
  │    courier    │                              │  (any language)    │
  │               │  ◄─── InputRequiredResult ───│  over stdio        │
  │  probes.py    │       { inputRequests,       └───────────────────┘
  │  heuristics.py│         requestState }
  │  protocol.py  │
  │  audit.py     │   fresh subprocess per probe (stateless-friendly isolation)
  │  report.py    │
  └───────────────┘   → scored report + CI exit code
  • protocol.py — a newline-delimited JSON-RPC stdio client plus an MRT auto-driver. Given a starting tools/call, it walks every InputRequiredResult, synthesises schema-valid inputResponses from each requestedSchema, echoes requestState, and records each hop. This is what makes courier work against any MRT server, not just the bundled demos.
  • heuristics.py — LLM-free requestState analysis: base64/JWT/JSON decoding, Shannon entropy, deterministic secret/PII signatures, and numeric tamper-target selection. Everything is a regex/entropy/structure rule.
  • probes.py — the eight adversarial probes above. Each opens a fresh server subprocess so no probe leaks state into another — mirroring the stateless model MRT is designed for.
  • audit.py / report.py / model.py — orchestration, scoring, and text/JSON rendering.
  • servers/ — a conformant reference_server.py and a buggy_server.py with six isolated ground-truth defects; both are runnable standalone MRT servers and double as the test fixtures.

Two approaches considered

  1. Static analysis of server source (the path most of this experiment series takes). Rejected. requestState handling is a runtime property — whether a MAC is actually checked, whether a replayed nonce is actually rejected — and it spans languages. A static tool would be language-locked and would miss the behaviour that matters. It also couldn't demonstrate an exploit, only guess at one.
  2. Dynamic black-box adversarial auditing over stdio (chosen). courier speaks the wire protocol and observes real responses, so it is language-agnostic and can prove a finding (e.g. the tamper-exploit probe shows the forged amount in the executed payment). Trade-off: it needs a runnable server and can only reach reachable flows. Given MRT is inherently a runtime state-handling contract, that trade is clearly worth it — and it matches gauntlet (exp 011), the series' other dynamic tool.

Cost profile. One subprocess per probe (~8 launches) plus a handful of JSON lines each; a full audit finishes in a few seconds. Memory is trivial (newline-framed messages, no buffering of streams). No network, no model, no secrets — it runs anywhere Python does, offline.

Assumptions & limitations

  • Principal convention. SEP-2322 binds state to the authenticated user but leaves auth transport-specific. For stdio, courier carries the principal in params._meta["courier.dev/principal"]; the bundled servers read it there. To audit a real server whose auth lives elsewhere (e.g. an HTTP Authorization header), adapt protocol.PRINCIPAL_META_KEY / the transport. The user-binding probe is meaningful only for user-scoped state; for anonymous flows it is expected to be a non-finding.
  • The reference cipher is a demonstration. The reference server seals state with an HMAC-SHA256 keystream + HMAC-SHA256 tag (encrypt-then-MAC) so the demo stays pure-stdlib. Production servers should use a vetted AEAD such as AES-GCM — which is what the official Python SDK does by default.
  • Reachability. courier drives the flows a server actually exposes via elicitation. It synthesises schema-valid answers for common JSON-Schema subsets (object/string/number/boolean/enum/const); exotic schemas may need a hand-provided --arguments seed or a richer synthesiser.
  • replay-idempotency and state-growth are best-practice checks. SEP-2322 does not strictly mandate idempotent finalisation or bounded state, but both are real hazards for stateless servers (no session to dedupe against; the client pays to carry state every hop). They are weighted low and labelled as such.
  • Not a substitute for shape conformance. courier is the adversarial / security lens; pair it with the official modelcontextprotocol/conformance suite for full protocol-shape coverage.
  • Single tool per run. The demo targets one tool (authorize_payment); point --tool / --arguments at whichever MRT tool you want to audit.

Layout

courier/            the auditor (protocol, heuristics, probes, audit, report, cli)
servers/            reference_server.py (conformant) + buggy_server.py (6 defects)
tests/              30 pytest tests (heuristics, protocol, both servers, CLI)
pyproject.toml      metadata + pytest config (pythonpath, testpaths)
Makefile            run / demo-buggy / audit-json / test

License

MIT — see LICENSE.

About

courier — offline, LLM-free adversarial auditor for MCP Multi-Round-Trip Requests (SEP-2322). Drives an MRT stdio server as a malicious client courier and grades whether it protects requestState (integrity, confidentiality, user-binding, replay). Ships a conformant reference server + a buggy one with 6 ground-truth defects.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages