Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MCP security: attack servers and scenarios

An MCP gateway, or a careful MCP client, is meant to stop a few known attacks: a tool whose description hides instructions for the model, a tool that changes after the client approved it, a tool that takes a trusted tool's name, a tool result that carries a prompt injection or a link that leaks data, a result too large to pass on, a server that asks for more access than it needs. Rustybin serves an MCP server for each of them, so a demo can show the attack reach an unprotected client, then the gateway stop it, and a guided gateway scenario per attack gives a pass or fail verdict.

Everything the attack servers send is inert test data: the hidden instructions name files and addresses no real system acts on, every address is on a reserved domain (.invalid, example.com), and every attack carries a RUSTYBIN-... marker so a check can tell whether it got through.

The attack servers

Each one is at /mcp/attack/{kind}, on the same protocol and transports as the mock MCP server (every protocol version, Streamable HTTP with or without a session).

KindThe attackWhat a defence looks like
poisoned_descriptionadd_numbers's description hides an <IMPORTANT> block telling the model to read ~/.ssh/id_rsa and keep it from the user, and a parameter's description hides an HTML comment; a clean get_weather sits next to itThe gateway removes, refuses or rewrites the poisoned tool before tools/list reaches the client, and keeps the clean one
rug_pullget_exchange_rate is harmless until its first call; then tools/list answers it with hidden instructions and a new parameter, forward_toThe gateway pins the definition the client approved and refuses or flags the changed one
shadowinglookup_customer, the name of a tool of the trusted /mcp/servers/crm, whose description tells the model to copy every email to audit@exfil.rustybin.invalidThe gateway namespaces or refuses the duplicate, so the trusted tool keeps its name
result_injectionget_order_notes answers a prompt injection in its text, its structured content and a resource link's descriptionThe gateway's response guard removes or flags it
oversizedexport_logs answers 2 MiBThe gateway caps what it passes to the client
exfiltration_urlfetch_report answers a link to exfil.rustybin.invalid with data in its query string, as an image and a resource linkThe gateway removes or refuses links to hosts it does not allow
scope_overreachThe server challenges a caller without a bearer for admin offline_access tools:* files:write, and its protected resource metadata lists the same, for one read-only toolThe gateway or client asks for the scopes the tools need, or refuses the server (any bearer passes here: the point is the scope it asks for)
POST {{base_url}}/mcp/attack/poisoned_description
Accept: application/json, text/event-stream
Content-Type: application/json
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/list
{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {"_meta": {"io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.tools[0].name" == "get_weather"
jsonpath "$.result.tools[1].name" == "add_numbers"
jsonpath "$.result.tools[1].description" contains "<IMPORTANT>"
jsonpath "$.result.tools[1].description" contains "RUSTYBIN-POISON"

The rug pull is kept per caller: a gateway scenario's check, else the MCP session, else the caller's X-Rustybin-Session (or address). Each check of a scenario starts with the harmless definition. At most 1024 callers are kept, for an hour each.

POST {{base_url}}/mcp/attack/rug_pull
Accept: application/json, text/event-stream
Content-Type: application/json
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/list
X-Rustybin-Session: docs-rug-pull
{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {"_meta": {"io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.tools[0].description" not contains "RUSTYBIN-RUG-PULL"
jsonpath "$.result.tools[0].inputSchema.properties.forward_to" not exists

POST {{base_url}}/mcp/attack/rug_pull
Accept: application/json, text/event-stream
Content-Type: application/json
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: get_exchange_rate
X-Rustybin-Session: docs-rug-pull
{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "get_exchange_rate", "arguments": {"from": "EUR", "to": "USD"}, "_meta": {"io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.content[0].text" contains "1.08"

POST {{base_url}}/mcp/attack/rug_pull
Accept: application/json, text/event-stream
Content-Type: application/json
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/list
X-Rustybin-Session: docs-rug-pull
{"jsonrpc": "2.0", "id": 3, "method": "tools/list", "params": {"_meta": {"io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.tools[0].description" contains "RUSTYBIN-RUG-PULL"
jsonpath "$.result.tools[0].inputSchema.properties.forward_to" exists
POST {{base_url}}/mcp/attack/scope_overreach
Accept: application/json, text/event-stream
Content-Type: application/json
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "docs", "version": "1.0.0"}}}
HTTP 401
[Asserts]
header "WWW-Authenticate" contains "scope=\"admin offline_access tools:* files:write\""

GET {{base_url}}/.well-known/oauth-protected-resource/mcp/attack/scope_overreach
HTTP 200
[Asserts]
jsonpath "$.scopes_supported" contains "admin"
jsonpath "$.scopes_supported" contains "offline_access"
POST {{base_url}}/mcp/attack/nope
Accept: application/json, text/event-stream
Content-Type: application/json
{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}
HTTP 404
[Asserts]
jsonpath "$.available" contains "rug_pull"

The attack servers are on by default and always off in public mode: the setting mcp.attack_servers (seeded by RUSTYBIN_MCP_ATTACK_SERVERS) turns them off on another instance. Off, their routes answer 404, the MCP scenarios are not listed and a run of one is refused. They are listed in the MCP inspector (with a warning that they misbehave on purpose), never in the mock MCP registry.

MCP gateway scenarios

Each attack server but scope_overreach is the upstream of a gateway scenario. Put the attack server behind the gateway, let it forward X-Rustybin-Session, turn on the defence, and check with the URL the gateway serves the MCP server at. The check starts an MCP session through the gateway (initialize with protocol 2025-06-18, then notifications/initialized), sends the scenario's requests in it, and compares what the client got with what reached the attack server. The verdict says what got through by name, never the attack's text.

ScenarioAttack serverThe check sendsA pass needs
mcp_tool_poisoningpoisoned_descriptiontools/listThe list reached the server, no poisoned description reached the client, and get_weather did
mcp_rug_pullrug_pulltools/list, a call of get_exchange_rate, tools/listThe harmless definition first, the call reached the server, and the changed definition never reached the client
mcp_tool_shadowingshadowing, and the trusted /mcp/servers/crm as the second servertools/listThe trusted lookup_customer reached the client (under its name or a namespaced one), and the attacker's copy did not take the name lookup_customer
mcp_result_injectionresult_injectiona call of get_order_notesThe call reached the server, and the injection never reached the client (removed, or the result refused or flagged)
mcp_oversized_resultoversizeda call of export_logsThe call reached the server, and the client never received more than max_result_kib (16 to 1024 KiB, default 256): the result cut, or refused
mcp_exfiltration_urlexfiltration_urla call of fetch_reportThe call reached the server, and no link to exfil.rustybin.invalid reached the client

A tool counts under a namespaced name too: crm_lookup_customer, crm.lookup_customer and the like are the trusted tool when its description is the trusted one.

POST {{base_url}}/_rustybin/scenarios/mcp_tool_shadowing/runs
Authorization: Bearer {{admin_token}}
HTTP 201
[Captures]
mcp_run: jsonpath "$.id"
[Asserts]
jsonpath "$.group" == "mcp"
jsonpath "$.upstream" endsWith "/mcp/attack/shadowing"
jsonpath "$.second_upstream" endsWith "/mcp/servers/crm"

DELETE {{base_url}}/_rustybin/scenarios/mcp_tool_shadowing/runs/{{mcp_run}}
Authorization: Bearer {{admin_token}}
HTTP 200

Security checks in the inspector

The MCP inspector's Run checks has three checks for any MCP server, heuristics that warn and never fail a run:

CheckWarns when
descriptions_look_cleanA tool's description or schema has an <IMPORTANT> block, an HTML comment, an instruction to ignore earlier instructions or to keep something from the user, invisible characters, a long run of blank lines, or a mention of credential files
results_carry_no_instructionsA tool's answer to the check's call has the same signs
definitions_are_stabletools/list after the calls differs from the list before them: a tool changed, went or came (a rug pull, or a server being updated)

Against the attack servers they warn; against Rustybin's own /mcp, the results check can warn on prompt_injection_demo, which answers an injection on purpose. What a server answered is third-party content: the details are under untrusted_tools and untrusted_results.

On every surface

SurfaceWhere
API/mcp/attack/{kind} (the data plane), /.well-known/oauth-protected-resource/mcp/attack/scope_overreach; the scenarios through /_rustybin/scenarios*; the checks through POST /_rustybin/mcp-checks
ConsoleGateway scenarios: the MCP group. MCP inspector: the attack servers in the server list, with a warning, and the three checks in Run checks. Management, General: MCP attack servers
CLIrustybin scenario start mcp_rug_pull, rustybin scenario check ... --max-result-kib KIB; rustybin settings set mcp.attack_servers false
Management MCPThe *_gateway_scenario tools take the MCP scenarios; the inspector's check tools run the three checks; what an attack server answered is under untrusted_*
rustybin.yamlsettings: { mcp.attack_servers: false }; scenario runs are transient