mcp-cassette
Record what the MCP servers your agent depends on actually said, then use that one recording two ways: a CI check that fails the day a server you don't own breaks or changes its tools, and an offline replay that lets you evaluate every agent change against the same tool data, with the exact step where a changed agent departs from the recording.
A cassette is the whole session between your agent and a real MCP server, kept as a readable JSON file you commit and review like code. mcp-cassette works at the transport level (newline-delimited JSON-RPC over stdio), treats messages semi-opaquely, and does not depend on the mcp SDK at runtime, so it works with any MCP client unmodified.
Full documentation: docs/guide/. The sections below summarize, and each ends with a pointer to its full chapter.
1. Install
Adding mcp-cassette to your own project, the normal case. It is a test-only tool, so it goes in the dev group:
uv add --dev mcp-cassette # or: pip install mcp-cassette
Standing in a clone of this repo, to run examples/ or the test suite:
uv sync # installs this checkout plus its dev group
Do not run uv add mcp-cassette inside the clone: uv rejects it as a self-dependency.
Python ≥ 3.12, on Linux, macOS and Windows. The core install depends only on anyio and pydantic. Run the CLI as uv run mcp-cassette ... (or activate the venv first); the listings below drop the prefix.
Full chapter: OP-01. Installation.
2. The upgrade tripwire
A server launched through uvx or npx is whatever version resolves that day. check re-launches it, reads its tool list, and compares it with the committed cassette. No agent, no model call, no test suite. In CI it is one step per server:
mcp-cassette check tests/cassettes/fetch.mcp.json -- uvx mcp-server-fetch
| Exit | Meaning |
|---|---|
0 |
unchanged |
5 |
a tool was added or removed, or its description or input schema changed; the diff is printed |
7 |
the server did not start; its last stderr lines are printed |
Write the first baseline with --record, review it, and commit it. To accept an intended server change, run --record again: it rewrites a baseline that holds only the handshake, and refuses to replace a full test session. --env KEY=dummy passes a placeholder key to a server that will not start without one. Runnable from a clone, against the bundled echo server:
mcp-cassette check examples/cassettes/tools.mcp.json -- python examples/echo_server.py # exit 0
mcp-cassette check examples/cassettes/tools-v2.mcp.json -- python examples/echo_server.py # exit 5
A red tripwire is not a failure to re-record away: read the diff, decide whether you accept the new tools, and only then commit the new baseline.
Full chapter: HT-09. Catch a server that changed under you.
3. Record once, replay offline
def test_agent_summarizes_repo(mcp_cassette):
cmd = mcp_cassette.server_command(["python", "tools/github_server.py"])
result = run_my_agent(mcp_servers={"github": cmd})
assert "summary" in result
The first run records the real session through a recording proxy; every run after replays it offline, so every prompt or model you try sees the same tool data. The fixture never monkeypatches your agent: it hands you a command list to plug into the agent's MCP server configuration. run_my_agent stands in for your agent; examples/test_echo.py is the same test with a minimal client in that slot.
The mode decides, once per run, whether that run records or replays. The recording unit is always the whole session, never one tool call.
| Mode | Cassette absent | Cassette present |
|---|---|---|
once (default) |
record | replay |
none |
fail: recording is forbidden | replay |
all |
record | re-record |
Precedence: MCP_CASSETTE_MODE (env), then the marker's mode=, then mcp_cassette_mode (ini), then once. Cassette paths come from the marker's cassette=, else mcp_cassette_dir (ini), else <rootpath>/tests/cassettes.
Full chapters: Getting started, HT-01. Record and replay a stdio server.
4. The divergence report
When a changed agent makes a call the recording has no answer for, replay stops at that step and shows the recorded call and the new one, as matching sees them:
mcp-cassette: replay diverged at step 2: tools/call: no recorded call matches
--- recorded
+++ new
@@ -1,6 +1,6 @@
{
"arguments": {
- "text": "hello cassette"
+ "text": "hello, changed prompt"
},
"name": "echo"
}
The run exits 3 and the fixture fails the test with the same block. Replay never falls through to the live server, because live data would make the comparison with the old agent unfair. Trace metadata in params._meta, where Langfuse and OpenTelemetry put a fresh id on every call, never decides a match. For an agent that recovers from a failed call, on_unmatched="error" on the marker (serve --on-unmatched error) answers the miss with an error and keeps serving; the run still exits 3.
Runnable from a clone: examples/test_divergence.py.
Full chapter: OP-05. Runbook: replay misses and failed recordings.
5. Failure on cue
One recorded cassette drives a whole resilience matrix, so "the agent degrades gracefully" becomes a test:
import mcp_cassette as mcc
@pytest.mark.parametrize("fault", [
mcc.Fault.timeout("tools/call", nth=1),
mcc.Fault.error("tools/call", code=-32000, message="rate limited"),
mcc.Fault.disconnect("tools/call"),
])
def test_agent_survives_tool_trouble(mcp_cassette, fault):
session = mcp_cassette.with_faults(fault)
cmd = session.server_command(["python", "tools/github_server.py"])
result = run_my_agent(mcp_servers={"github": cmd})
assert result.completed_with_degraded_tools
Fault types: delay, timeout, error, malformed, disconnect. Faults live in a separate FaultOverlay (or a serve --faults sidecar file); the recorded cassette is never changed. Faults are replay-only.
Full chapter: HT-04. Inject faults.
6. CI settings
- Record once, locally, against the real server. The default
oncemode does this when no cassette exists. - Commit the cassette. Review it like code: a changed tool description is a supply-chain event, not a fixture edit.
- CI only replays and checks. Set
MCP_CASSETTE_MODE=none, so a missing cassette is a red build instead of a live call with production credentials, andcheck --recordis refused.
Prove replay-only mode from a clone, with no server, network or credentials:
MCP_CASSETTE_MODE=none uv run pytest examples/ -q
Full chapter: OP-03. CI pipeline.
7. No secrets in the committed file
Cassettes are verbatim transcripts you commit, so redaction runs at capture time, on a copy, with defaults always on: values under keys matching *token*, *secret*, *password*, *apikey*, *api_key*, or authorization (with - and _ folded, so X-API-Key matches) are replaced with REDACTED before the file is written. Add your own rules with record --redact (key-glob or JSON pointer). Read every new cassette before its first commit anyway.
Full chapter: HT-07. Redact secrets.
8. Format stability
Every cassette carries a format_version, and a newer one than this release understands fails to load with a clear error rather than replaying wrongly. The format is unstable (0.x) until three outside repositories use it: a release may change it, and the changelog says how to move. Pin the version you record with.
9. Beyond Stage 1
These ship and are tested, but get no new features until a user needs them. Each has its guide page:
- Remote Streamable HTTP record and replay (
[http]extra,server_url): HT-02 - The
use_cassetteanduse_cassette_asynclibrary doors: HT-03 - Replay timing (
--pace recorded): HT-05 inspectanddiff: HT-06lintand pattern packs: HT-08, HT-11- Free-text PII redaction packs: HT-10
new_episodesmode, which appends misses from the live server: OP-02- Parallel runs and the single-writer claim: OP-06
- The packaged GitHub Action and pre-commit hooks: OP-03, OP-07
10. Built with Claude Code
mcp-cassette was built with the help of Claude Code under human direction and review.
It is an independent open-source project: not an Anthropic product, and not affiliated with or endorsed by Anthropic. "Model Context Protocol" and "Claude" are Anthropic's.
11. License
Apache-2.0 — see LICENSE.
Metadata
Release files for mcp-cassette 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcp_cassette-0.5.0.tar.gz | 394.4 kB | With provenance | Details for mcp_cassette-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcp_cassette-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for mcp_cassette-0.5.0-py3-none-any.whl |
Total release size: 530.0 kB
Release files / mcp_cassette-0.5.0.tar.gz
| Download URL | mcp_cassette-0.5.0.tar.gz |
|---|---|
| Size | 394.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
059dea79b346f7e2e3c80685a0fe7f27d477cf45e63425d8062c56895749b4f4
|
|
BLAKE2b-256 checksum How to use checksums |
229ac3ccff48d10059c79544f85e3060fbddf9888d4d9b5480e9b6c5cdbd2bb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / mcp_cassette-0.5.0-py3-none-any.whl
| Download URL | mcp_cassette-0.5.0-py3-none-any.whl |
|---|---|
| Size | 135.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7734a250b2ff852f385225faa4c35b51a727043aacb06d672bda114b520eea50
|
|
BLAKE2b-256 checksum How to use checksums |
dbcedebe95513c06f2d1d123e4bc40d2a3093c3fad67fc09a871beff739059fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for mcp-cassette 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mcp_cassette-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.