mcp-testbench -- the MCP server testing toolkit

MCP conformance and contract testing for Model Context Protocol servers: schema snapshots, breaking-change detection, tool-call replay, lint, and a pytest plugin.

Install: pip install mcp-testbench  |  PyPI: pypi.org/project/mcp-testbench

What is mcp-testbench?

mcp-testbench is a testing, validation and CI tool for MCP (Model Context Protocol) servers. It snapshots a server's tools, prompts and resources, detects breaking changes against that snapshot, lints the schema, and replays recorded tool calls -- the full MCP server testing workflow in one package with zero runtime dependencies (stdlib only, no dependency on the official mcp package). It works over stdio, Streamable HTTP and legacy SSE, and treats the server as a black box, so it tests servers written in any language or framework -- including FastMCP and the official MCP SDK.

Quickstart

# 1. record the contract; commit the snapshot file
mcp-testbench snapshot -o mcp-snapshot.json -- python my_server.py

# 2. CI gate: exit 1 when a change breaks existing callers
mcp-testbench check mcp-snapshot.json -- python my_server.py

# 3. lint the schema (tools + prompts + resources)
mcp-testbench lint -- python my_server.py

# 4. replay recorded tool calls (JSONL); exit 1 if any call fails
mcp-testbench replay calls.jsonl -- python my_server.py

Guides

pytest plugin

The pytest plugin loads automatically after install. Point it at your server and assert on the schema, the snapshot, and live tool calls:

def test_no_breaking_changes(mcp_schema, mcp_snapshot):
    mcp_snapshot(mcp_schema, "mcp-snapshot.json")  # writes on first run

def test_call(mcp_client):
    result = mcp_client.call_tool("echo", {"text": "hi"})
    assert result["content"][0]["text"] == "hi"