Testing MCP agents offline: the recording is the server
说明与用途
将一次真实的 MCP 会话记录为 JSONL 文件并将其作为服务器回放,使代理能够在离线环境中测试,无需凭证、速率限制或网络,同时保持客户端兼容性并对合同和安全性进行门控。
问题
MCP agent tests depend on a live MCP server with credentials, rate limits, and network, making tests fragile and hard to run offline.
结果
Using mcp-cassette, developers can record a single real MCP session and replay it indefinitely, eliminating credentials, rate limits, and network dependencies. Tests remain unchanged, contracts are gated, and safety checks lint for tool poisoning and prompt injection.
工作流
- 1. Record a real MCP session:
npx mcp-cassette record -o session.cassette.jsonl -- npx -y @modelcontextprotocol/server-github - 2. Replay the session:
npx mcp-cassette check --stdio "npx mcp-cassette replay session.cassette.jsonl" - 3. Integrate into tests (e.g., Vitest): point the MCP client to
tape.urlfrom the cassette - 4. Gate tool contracts with
mcp-cassette snapshot --check --stdio "node dist/my-server.js" - 5. Lint server surface and responses with
mcp-cassette check --stdio "node dist/my-server.js" --format sarif --sarif-location mcp-contract.snapshot.json > mcp-cassette.sarif - 6. Add CI step: use GitHub Action
ivermin1123/[email protected]withserver-command: node dist/my-server.js
证据
If your agent calls tools over the Model Context Protocol, its tests depend on something they do not control: a live MCP server, with its credentials, its rate limits and its network.
mcp-cassette records one real MCP session into a JSONL file, then serves that file as an MCP server.
The recorder sits between your client and the real server as a transparent proxy and writes every frame, in both directions, to an open JSONL cassette.
The replay speaks MCP over stdio or Streamable HTTP, so any client in any language connects to it unchanged.
A tool contract is an API. snapshot writes it to a file you commit, and snapshot --check fails CI when it breaks.
- 记录日期: 2026-10-11T09:41:04.361Z