Testing patterns and requirements for FastMCP
src/
directory structure, creating a predictable mapping between code and tests. When you’re working on src/fastmcp/server/auth.py
, you’ll find its tests in tests/server/test_auth.py
. In rare cases tests are split further - for example, the OpenAPI tests are so comprehensive they’re split across multiple files.
inline-snapshot
for testing complex data structures. On first run with empty snapshot()
, pytest will auto-populate the expected value. To update snapshots after intentional changes, run pytest --inline-snapshot=fix
. This is particularly useful for testing JSON schemas and API responses.
run_server_in_process
utility to spawn a server in a separate process for testing:
run_server_in_process
utility handles server lifecycle, port allocation, and cleanup automatically. This pattern is essential for testing transport-specific behavior like timeouts, headers, and authentication. Note that FastMCP often uses the client_process
marker to isolate tests that spawn processes, as they can create contention in CI.
just docs
command launches a local Mintlify server that renders your documentation exactly as users will see it: