Install: pip install mcp-testbench |
PyPI: pypi.org/project/mcp-testbench
Two kinds of FastMCP tests
FastMCP ships an excellent in-memory Client: import your
server object, call tools in-process, assert on results. It is the fastest
way to unit-test tool logic. Its limit is its strength -- it only works
in-process, only for FastMCP servers, and it tests what your functions
return, not the schema contract an external agent will see after your
server is packaged, proxied or served over HTTP.
mcp-testbench is the complementary layer: it starts your FastMCP server as a subprocess or connects to it over HTTP and tests it as a black box -- exactly the surface your callers depend on.
stdio
# server.py ends with: mcp.run() (stdio is FastMCP's default)
mcp-testbench snapshot -o mcp-snapshot.json -- python server.py
mcp-testbench lint -- python server.py
mcp-testbench check mcp-snapshot.json -- python server.py
HTTP
# server.py: mcp.run(transport="http", port=8000)
mcp-testbench inspect --url http://localhost:8000/mcp
mcp-testbench check mcp-snapshot.json --url http://localhost:8000/mcp
In pytest, alongside the in-memory client
import sys, pytest
@pytest.fixture
def mcp_server_command():
return [sys.executable, "server.py"]
def test_no_breaking_changes(mcp_schema, mcp_snapshot):
mcp_snapshot(mcp_schema, "mcp-snapshot.json")
def test_schema_lints_clean(mcp_lint):
assert mcp_lint() == []
Keep the in-memory tests for logic; add mcp-testbench for the contract: snapshots, breaking-change gates, lint (including tool-poisoning patterns in descriptions), and replay of recorded calls. In CI the same checks run against the packaged server, not the source tree -- which is where contract surprises actually ship from.