@frontmcp/testing uses a fixture-based testing approach inspired by Playwright. Fixtures are pre-configured objects automatically injected into your test functions, eliminating boilerplate setup code.
Available Fixtures
| Fixture | Type | Description |
|---|---|---|
mcp | McpTestClient | Auto-connected MCP client for making requests |
auth | AuthFixture | Token factory for authentication testing |
server | ServerFixture | Server control and multi-client creation |
Configuring Fixtures
Usetest.use() to configure fixtures for your test file:
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
server | string | — | Path to server entry file (required) |
port | number | Auto | Port to run server on |
transport | 'sse' | 'streamable-http' | 'streamable-http' | Transport protocol |
auth | object | — | Auth configuration |
logLevel | 'debug' | 'info' | 'warn' | 'error' | 'warn' | Server log level |
env | Record<string, string> | — | Environment variables |
startupTimeout | number | 30000 | Server startup timeout in ms |
baseUrl | string | — | Connect to existing server instead of starting one |
MCP Client Fixture
Themcp fixture is your primary interface for testing MCP servers.
Tools API
Resources API
Prompts API
Session & Server Info
Raw Protocol Access
Logging & Debugging
Auth Fixture
Theauth fixture creates JWT tokens for testing authentication flows.
Creating Tokens
Pre-built Test Users
Testing Edge Cases
JWKS Access
Server Fixture
Theserver fixture provides server control and multi-client support.
Server Information
Creating Additional Clients
Server Logs
Restart Server
Fixture Lifecycle
Understanding when fixtures are created and destroyed:The server is shared across all tests in a file for performance. Starting a server is expensive (100-500ms), so sharing it dramatically improves test speed.
Best Practices
Do:- Use
test.use()once at the top of each test file - Clear logs and traces between tests if needed
- Disconnect additional clients created via
server.createClient() - Use
port: 0for automatic port selection in CI
- Modify shared server state without cleanup
- Create many clients without disconnecting them
- Rely on test execution order
- Use hardcoded ports in parallel test runs