Offline, LLM-free safety & conformance auditor for the MCP resources channel.
mirage passively replays a captured JSON-RPC session over the Model Context
Protocol resources capability — resources/list, resources/read,
resources/templates/list, resources/subscribe, and the
notifications/resources/updated / notifications/resources/list_changed
notifications — and grades whether the server weaponized the channel or drifted
out of contract. It ships a 35-rule catalog in six families, a severity-weighted
score + letter grade, and a CI exit-code gate. Pure Python standard library. No
network, no model calls, no live server.
The MCP security conversation in 2026 is dominated by tool poisoning and
rug-pulls — a trusted tool silently rewritten after the user approves it
(Invariant Labs, ReversingLabs, 40+ MCP CVEs this year). Every mitigation and
every prior entry in this series (overreach, contravene, trifecta,
prompter) points at the tools and prompts channels. But resources is
the third core MCP primitive and it has the same trust shape and a worse one:
resource content is entirely server-authored, is injected into the model's
context under a trusted URI's provenance, and — uniquely — is subscribable.
That subscription is a TOCTOU primitive: a client subscribes to a benign
resource, and the server can later fire resources/updated and serve different
content on the next read. The tool rug-pull's less-discussed twin is the
resource rug-pull, and nobody was checking for it. mirage is the smallest
thing that proves you can catch it — and the rest of the resource attack surface
(URI-template SSRF, mimeType spoofing, resource-content injection, audience
steering, the new ttlMs/cacheScope fields) — statically, from a passive trace,
with zero model calls.
| Family | Focus | Notable rules |
|---|---|---|
| CAP | capability & declaration legality | resources used without declaration (CAP01), subscribe/listChanged used unadvertised (CAP02/03), unsolicited updated (CAP04), duplicate/blank URIs (CAP05/06) |
| SCH | schema & structure legality | text/blob exclusivity (SCH01), bad base64 (SCH02), invalid mimeType (SCH04), illegal RFC 6570 template (SCH06), the new-in-RC ttlMs/cacheScope (SCH07/08) |
| SUB | subscription integrity | the resource rug-pull (SUB01, CRITICAL), phantom subscription (SUB02), update storm (SUB03), silent content drift (SUB04), post-approval shadow resource (SUB05) |
| URI | URI / template exfiltration & SSRF | template variable in the authority = SSRF (URI01, CRITICAL), dangerous scheme (URI02), cloud-metadata/private host (URI03), off-origin content (URI04), exfil-sink query param (URI05) |
| INJ | content injection & perception | prompt injection in resource content (INJ01, CRITICAL), metadata poisoning (INJ02), invisible Unicode (INJ03), homoglyph name shadowing (INJ04), mimeType spoof vs actual bytes (INJ05) |
| RES | resource abuse & result conformance | token bomb (RES01), under-reported size (RES02), audience-steered auto-inject (RES03), read-any / undeclared-URI read (RES04), pagination cursor loop/path-leak (RES05) |
The three CRITICAL rules are the flagship attack classes:
- SUB01 — resource rug-pull. The auditor reconstructs read history per URI.
If a subscribed resource is read benign, then an
updatednotification fires, then a later read of the same URI returns content that newly carries injection/exfil signatures, that TOCTOU swap is a CRITICAL. Approval was granted against content that no longer exists. - URI01 — template-steered SSRF/exfil. A
resources/templates/listuriTemplatethat interpolates a client-supplied variable into the URI authority (https://{subdomain}.evil.example/…) turns every read into an attacker-chosen outbound request. - INJ01 — resource-content poisoning. Server-authored resource text/blob bearing instruction-override / tool-coercion / exfil imperatives, injected into context under the resource's trusted provenance.
# audit a capture (human-readable report + CI gate on stderr)
python -m mirage captures/mirage_trojan.json
# machine-readable
python -m mirage --json captures/reference_clean.json
# CI: fail the build unless grade >= B and no finding >= HIGH (defaults)
python -m mirage captures/session.json ; echo "exit=$?"
# tune the gate
python -m mirage --gate A --fail-on MEDIUM captures/session.jsonExit codes: 0 gate passed · 2 gate failed (CI failure) · 3 capture could
not be loaded.
No dependencies to install for the tool itself. To run the tests you need
pytest (see below).
make test # run the suite
make run # audit both shipped captures
make captures # regenerate the two fixtures from build_captures.pyA capture is exactly what a passive proxy between client and server would log — a list of JSON-RPC messages, each tagged with a direction:
{
"origin": "https://docs.acme.example",
"trustedNames": ["deploy-config"],
"capabilities": { "resources": { "subscribe": true, "listChanged": true } },
"messages": [
{ "dir": "C->S", "id": 1, "method": "resources/list", "params": {} },
{ "dir": "S->C", "id": 1, "result": { "resources": [ ... ], "ttlMs": 60000 } },
{ "dir": "S->C", "method": "notifications/resources/updated",
"params": { "uri": "https://docs.acme.example/config" } }
]
}diris"C->S"(client→server) or"S->C". Requests carry anid+method+params; responses carry the matchingid+result/error; notifications carrymethod+paramswith noid.origin(optional) anchors off-origin detection (URI04).trustedNames(optional) seeds homoglyph-shadow detection (INJ04).capabilitiesmirrors the server'sinitializeresult so mirage can check a capability was advertised before it was used.
capture.json ──▶ load_capture ──▶ _Auditor.run() ──▶ AuditResult ──▶ report / CLI gate
(validate) │ replay messages in order
│ ├─ correlate responses to requests by id
│ ├─ track: declared caps, listed URIs+sizes,
│ │ templates, subscriptions, per-URI
│ │ read history (content + signatures)
│ ├─ per-message structural + content rules
│ └─ finalize: cross-message rules
│ (rug-pull, update storm)
▼
detectors.py (pure primitives:
injection markers, invisible/bidi/TAG Unicode,
homoglyph folding, base64, mime, binary magic,
host classification, RFC 6570 template legality)
catalog.py— the 35 rules as immutable records with severities/weights. The single source of truth for scoring; nothing else assigns points.detectors.py— deterministic, side-effect-free detection functions. Every one is unit-tested in isolation.auditor.py— the capture model, the id-correlating replay state machine, and rule evaluation. The state machine is what makes the rug-pull detectable: it keeps a per-URI timeline of read content rather than a single snapshot.report.py/__main__.py— text/JSON rendering and the CI gate.
- Live/dynamic auditor (drive a real server over stdio, à la
gauntlet#011). Rejected: the rug-pull is a timing attack that a fuzzer can't reliably provoke, resources are often side-effecting to read, and a passive design audits production traffic you already have. Higher CPU, more moving parts, needs a live target. - Passive trace replay with a per-URI timeline (chosen). Lower cost (single pass, O(messages)), fully deterministic and reproducible in CI, and — critically — it can compare the same resource across time, which is the only way to see a benign→malicious content swap. Trade-off: it can only see what the trace captured, so coverage depends on the client actually re-reading after an update. That is an acceptable and honest limit: mirage grades the evidence in front of it and never guesses.
Memory is O(distinct URIs × reads-per-URI) for the content history; for real captures that is trivial. The only unbounded input is resource content itself, which is exactly what RES01 (token bomb) is there to flag.
Clean reference capture:
$ python -m mirage captures/reference_clean.json
mirage — MCP resources-channel safety & conformance audit
==========================================================
Score: 100/100 Grade: A
Findings:
Session: 13 msgs, 2 resources, 1 templates, 1 subscriptions, 3 reads
No findings. Capture is conformant against the mirage catalog.
mirage: gate passed # exit 0
Trojan capture (abridged):
$ python -m mirage captures/mirage_trojan.json
Score: 0/100 Grade: F
Findings: CRITICAL 4, HIGH 12, MEDIUM 10, LOW 4
...
── SUB ─────────────────────────────
[CRITICAL] SUB01 resource rug-pull: subscribed content swapped benign -> malicious
at reads msg[13]->msg[16] https://docs.acme.example/config
subscribed resource content swapped benign -> injection
── URI ─────────────────────────────
[CRITICAL] URI01 template-steered exfiltration (client variable in authority)
at msg[3] template 'cdn-proxy'
evidence: https://{subdomain}.evil.example/collect/{path}
── INJ ─────────────────────────────
[CRITICAL] INJ01 prompt injection in resource content (resource poisoning)
at msg[5] read 'https://docs.acme.example/secret-inject'[0]
mirage: GATE FAILED — grade F < required B; worst finding CRITICAL >= HIGH # exit 2
The trojan fixture produces 30 findings across 29 rules and all six families, including 4 CRITICALs (SUB01 rug-pull, URI01 authority-templated SSRF, and two INJ01 resource-content injections — the static read and the rug-pulled read).
- Passive, evidence-bound. mirage grades the captured trace. If the client
never re-reads a subscribed resource after an
updated, the swap isn't in the evidence and mirage won't (and shouldn't) invent it. Capture the re-read to catch the rug-pull. - Heuristic detectors, tuned for precision. Injection-marker and invisible-Unicode detection are conservative signature sets, not a model. They will miss novel phrasings (false negatives) far more often than they misfire on clean docs (false positives). This is a linter, not a guarantee.
- Origin/trust hints are inputs. Off-origin (URI04) and homoglyph-shadow
(INJ04) detection use the optional
originandtrustedNamesfields; omit them and those two rules simply stay quiet. - Spec version. Field-level rules track the MCP 2026-07-28 release candidate
(notably
ttlMs/cacheScope). Core resource semantics are stable across recent spec revisions. - Scope. Resources only. Sibling channels are covered by earlier experiments
(prompts → #018
prompter, roots → #017cordon, sampling → #015, etc.).
mirage/
__init__.py public API (audit, load_capture, ...)
__main__.py CLI + CI gate
catalog.py the 35-rule catalog
detectors.py pure detection primitives
auditor.py capture model + replay state machine + rule evaluation
report.py text / JSON rendering
captures/
build_captures.py deterministic fixture generator
reference_clean.json conformant session (100 / A / 0 findings)
mirage_trojan.json malicious session (0 / F / 30 findings)
tests/ 76 tests: every rule, every detector, both fixtures, the CLI
MIT — see LICENSE.
Development Experiment 019 of the dev-experiments-365 series — one novel, runnable R&D prototype per day.