Skip to content

About

Chaos engineering for MCP agents: inject faults into a healthy server, then score how the agent copes - no model, no API key.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Development Experiment 002 — mcp-chaos

Chaos engineering for MCP agents: inject faults into a healthy server, then score how the agent copes — with no model, no API key, and no instrumentation of the agent.


Thesis

Every MCP test harness in the wild points an agent at a server that works. But ToolFailBench (July 2026) measured frontier tool-calling models against 218 runtime tool-failure scenarios and found none exceeded 11.47% accuracy — and that the dominant failure mode is not picking the wrong tool. It is never verifying the result that came back. A parallel finding from Adaline Labs (May 2026) shows agents call tools unnecessarily in nearly half of queries. Meanwhile the MCP server ecosystem has grown past 9,000 servers, and not one lightweight tool lets a builder ask: when my dependency degrades, does my agent notice?

The insight that makes this cheap to answer: you do not need a model to grade the agent. Retry, backoff, argument adaptation, giving up, and silently swallowing a corrupted result are all visible on the wire. mcp-chaos is a stdio proxy that sits between an MCP client and its server, injects deterministic faults into tools/call, records every frame, and scores the client's observable behaviour. It is the smallest thing that proves the idea, because it reproduces ToolFailBench's central result using four hand-written policies and zero inference.

Quickstart

Python 3.11+. Zero runtime dependencies.

python -m mcp_chaos demo          # the whole argument, in one command (~10s)

Point a real agent at a real server:

# instead of:  my-mcp-server
# run:
python -m mcp_chaos proxy --config examples/chaos.json \
                          --transcript run.jsonl \
                          -- my-mcp-server --its --own --flags

python -m mcp_chaos score run.jsonl               # human-readable report
python -m mcp_chaos score run.jsonl --json        # machine-readable
python -m mcp_chaos score run.jsonl --fail-under 70   # exit 1 in CI

make demo, make test, and make run do the same thing.

Sample run

Verbatim output of python -m mcp_chaos demo (full transcript in sample_run.txt):

  agent policy comparison  (same server, same faults, same seed)
  --------------------------------------------------------------------
  policy            score  grade   recovery   non-silence   adaptivity
  --------------------------------------------------------------------
  naive               6.7      F         0%            0%          n/a
  blind_retry        52.0      F        80%           50%           0%
  backoff_retry      62.0      D        80%           50%           0%
  verify_recover    100.0      A       100%          100%         100%

Read the middle two rows. blind_retry and backoff_retry both recover from 80% of the injected faults — they retry diligently on every error they can see. Both score 50% on non-silence, because search_docs returned {"content": []}, which is valid JSON, carries no error flag, and looks exactly like success. They walked straight past it:

  tool            injected    observed    agent response
  fetch_weather   error       error       gave up
  search_docs     empty       empty       SILENTLY ACCEPTED
  summarize       malformed   malformed   SILENTLY ACCEPTED
  list_files      hang        no_response gave up

Retrying is not resilience. Only verify_recover, which checks the content of what came back, earns an A. That is ToolFailBench's finding, reproduced locally in ten seconds.

How it works

   agent client  <--stdio-->  mcp-chaos proxy  <--stdio-->  real MCP server
                                     |
                                     +--> run.jsonl (every frame, annotated)
                                                |
                                                +--> scorer --> report / JSON / CI gate

The proxy is transparent to initialize, tools/list, and notifications — only tools/call is ever tampered with, so the client cannot tell it is not talking to the server directly.

Faults

kind what the client sees why it is interesting
error JSON-RPC error response the loud failure everyone handles
tool_error result with isError: true quieter; many clients only check the error field
empty result with content: [] looks like success; catchable only by verification
malformed a truncated, unparseable line tests the client's parser, not its logic
slow the real answer, late latency, not a correctness fault — scored separately
hang nothing, ever tests timeouts

Rules match tool names by glob. only_first_n: 2 makes a fault transient, which is what separates "the agent must give up" from "the agent must retry":

{ "seed": 20260709, "rules": [
    { "tool": "fetch_weather", "kind": "error", "only_first_n": 2, "message": "upstream 503" },
    { "tool": "search_docs",   "kind": "empty", "only_first_n": 2 },
    { "tool": "list_files",    "kind": "slow",  "delay_ms": 250 }
]}

Selection is a pure function of (seed, tool, attempt_index, rule_index). Same seed, same run — and adding a rule never reshuffles the draws of the existing ones.

Metrics

metric weight question
recovery 0.40 did a later call to the same tool eventually succeed?
non_silence 0.30 did the agent notice degraded results at all?
adaptivity 0.15 when it retried, did it change anything?
backoff 0.10 did it space its retries out?
efficiency 0.05 did it repeat work that had already succeeded?

backoff is measured from the moment the client learned a call had failed (its response landed) to the moment it tried again — not between successive requests. Measuring request-to- request would fold in the server round-trip, so a slow tool would masquerade as a patient client and ordinary latency jitter would make the score non-reproducible. It cost one debugging session to find that out; test_backoff_measures_client_wait_not_server_latency keeps it found.

A metric with an empty denominator is dropped and its weight redistributed across the rest, so a run that never exercised backoff is not punished for it. naive above shows n/a for adaptivity: it never retried, so there was nothing to adapt.

Architecture note

Three threads and a priority queue. A client pump reads stdin, decides per tools/call whether to fault, and either forwards the frame, answers it itself, or drops it. A server pump reads the child's stdout. Both funnel into a single DelayedWriter that owns the output stream and releases each line at its deadline — that is what makes slow possible without garbling lines or head-of-line blocking the replies queued behind it.

Responses are deliberately not in arrival order. slow is reordering; a proxy that preserved arrival order could not implement latency injection at all without stalling every later reply. JSON-RPC permits out-of-order responses and MCP clients must correlate by id, so this is a designed property, not an accident. tests/test_proxy.py::test_slow_lets_later_replies_overtake_it pins it down.

The approach not taken

The obvious design is an LLM-in-the-loop harness: run a real agent against the faults, then have a judge model grade the recovery. Rejected on three counts. It needs a paid API and secrets, which this experiment does not have. It is nondeterministic, so a resilience score could never be a CI gate. And most damningly, it conflates the model with the harness — exactly the confound that "Coding Benchmarks Are Misaligned with Agentic SE" (June 2026) argues makes agent benchmarks uninformative.

A third option, monkey-patching the MCP SDK in-process, would give richer signal (you could see the agent's reasoning, not just its calls) but binds the tool to one SDK in one language.

The protocol-level proxy wins because MCP's stdio transport is a stable, narrow, language- agnostic seam. The price is real and worth naming: the proxy sees behaviour, not intent. It can tell you the agent changed its arguments before retrying. It cannot tell you whether the change was wise.

Cost: O(1) memory per in-flight request; the transcript is O(frames) on disk. Scoring is O(n²) in the number of tool calls (each fault episode scans forward for the next call to the same tool), which is irrelevant at the thousands-of-calls scale a single agent session produces.

Assumptions & limitations

  • stdio transport only. The Streamable HTTP transport is not wrapped. The fault model would carry over unchanged; the plumbing would not.
  • adaptivity is a behavioural proxy. It measures whether retry arguments differed, not whether they differed sensibly. An agent that appends a random nonce scores 100%.
  • Malformed lines carry no id, so they are attributed to the oldest request still awaiting a reply. That is exact for a single-in-flight client (the overwhelmingly common case) and approximate for a pipelining one.
  • empty is treated as degraded. For a search tool with genuinely no results, "empty" is a correct answer, and an agent that retries it is wasting calls. The scorer cannot distinguish the two; that judgement belongs in your choice of which tools to fault.
  • silent_accept requires a subsequent call. If the faulted call is the last thing the agent does, it never "carried on with bad data", so it is scored as giving up rather than as silent acceptance.
  • backoff needs ≥ 3 attempts of one tool to have two waits to compare, and only counts waits ≥ 20 ms as deliberate — below that, the jitter of a hot retry loop reads as intentional spacing. A tool with a hang in its sequence is unscorable for backoff: the client was never told the call failed, so there is no moment to measure the wait from.
  • The four demo policies are hand-written caricatures, not real agents. They exist to prove the scorer separates good behaviour from bad without a model in the loop. Pointing the proxy at a real agent is one flag.
  • The mock server is healthy by construction. Every failure in the sample run was injected.

Layout

mcp_chaos/     models · faults · proxy · recorder · score · report · console · cli · demo
examples/      mock_server.py · policies.py · chaos.json · chaos-harsh.json
tests/         73 tests: unit (faults, scoring, rendering) + integration (real subprocesses) + e2e

Tests drive real subprocesses rather than in-memory fakes, because pipe buffering, line framing and shutdown ordering are precisely what break a stdio proxy — and a fake would not catch any of them.

make test    # 73 passed

License

MIT. See LICENSE.

About

Chaos engineering for MCP agents: inject faults into a healthy server, then score how the agent copes - no model, no API key.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages