Test MCP Tools
The current Python SDK can connect a Client directly to an MCPServer object, giving you fast tests without ports or subprocesses.
import pytest
from mcp.client import Client
from server import mcp
@pytest.mark.anyio
async def test_lookup():
async with Client(mcp) as client:
result = await client.call_tool("lookup", {"id":"A-1"})
assert result is not NoneTest more than the happy path
- Required/missing fields.
- Boundary values and enums.
- Unauthorized caller.
- Downstream timeout.
- Not-found behavior.
- Structured output contract.
- Idempotency for mutations.
Snapshot schemas selectively
Schema snapshots can catch accidental breaking changes, but make them readable and reviewable rather than snapshotting entire noisy protocol responses.