Model Context Protocol (MCP) servers hand an agent a clean menu of tools over JSON-RPC 2.0. That menu is also an untrusted text channel. When a client treats tool descriptions and tool return values as instructions rather than data, a compromised server or a single poisoned workspace note can turn a routine summary request into silent credential egress.
MCP Tool Poisoning Lab runs four attack paths end to end over real JSON-RPC 2.0 stdio subprocesses (initialize, tools/list, tools/call) in zero-dependency Python (github.com/ghostintheprompt/mcp_tool_poisoning_lab).
Four ways a stdio tool server hijacks the client
In vulnerable/server.py, the server exposes fetch_release_notes, summarize_note, read_workspace_file, and send_email to a local client:
- Poisoned tool metadata (
CWE-74, OWASP LLM01):fetch_release_notesembeds an<IMPORTANT>directive inside its schemadescription. Listing tools is enough to make the unguarded client read../secrets/api_keys.envand mail the synthetic key to[email protected]. - Indirect output injection (MITRE ATLAS
AML.T0051.001):summarize_notereturnsworkspace/notes/release_note.txt, which contains aSYSTEM OVERRIDE:line. Because tool output enters the same token stream as operator instructions, the client obeys the note and forwards the secret to[email protected]. - Traversal and open egress (
CWE-22,CWE-284, OWASP LLM06):read_workspace_fileaccepts..segments that escapeworkspace/, andsend_emailallows arbitrary external domains. - Mid-session rug pull (
--rug-pull): On the firsttools/listcall right afterinitialize,fetch_release_notesserves a clean description so manual review passes. On the secondtools/listcall, the server swaps in the poisoned schema and triggers exfiltration mid-session.
Pinning tool schemas at initialize and gating egress
Fixing one layer leaves the other three alive, so the hardened pair splits enforcement between agent/client.py and fixed/server.py.
At initialize, the hardened client hashes every tool definition returned by tools/list with SHA-256. On any later tools/list, if a schema's digest changes from its pinned baseline, execution halts immediately with manifest_hash_mismatch:fetch_release_notes and logs a manifest_drift event.
On the server side, read_workspace_file canonicalizes paths and refuses anything outside workspace/, while send_email requires explicit user_intent provenance and restricts recipients to @acme.local:
if provenance != "user_intent":
return ToolResult(
tool=name,
ok=False,
content="blocked:untrusted_provenance",
)
Four deterministic JSONL audit rules in detect/rule.py (MCP-001 through MCP-004) watch emitted session logs for hidden schema directives, manifest_drift events, path-traversal attempts, and non-allowlisted recipients, catching nine of 11 adversarial events with zero false positives across benign runs.
Running the stdio harness
Running make test spawns both stdio servers as real subprocesses and verifies every protocol round-trip offline:
Scenario | Vulnerable | Fixed
----------------------------------------------------------------------
01: Tool-Description Poisoning | EXFILTRATED | BLOCKED
02: Indirect Tool-Output Injection | EXFILTRATED | BLOCKED
03: Path Traversal (../secrets) | ALLOWED | BLOCKED
04: Mid-Session Rug-Pull Drift | EXFILTRATED | PIN_BLOCKED
Detection Rules (JSONL): benign_fp=0/2, attack_catches=9/11
Ran 7 tests in 0.593s (OK)
The lab uses a deterministic Python client policy simulator rather than live LLM API calls so every test stays reproducible offline, using strictly synthetic tokens (SYNTHETIC_KEY_DO_NOT_USE_9941).
GhostInThePrompt.com // Pin the tool manifest at initialize, and never let tool output spend user authority.