@frontmcp/testing exports, types, and methods.
Test Function
test
The main test function with fixture injection.test.use
Configure fixtures for a test file.| 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 | AuthOptions | — | Authentication configuration |
logLevel | 'debug' | 'info' | 'warn' | 'error' | 'warn' | Server log level |
env | Record<string, string> | — | Environment variables |
startupTimeout | number | 30000 | Startup timeout in ms |
baseUrl | string | — | Connect to existing server |
McpTestClient
The primary fixture for testing MCP servers.Tools API
tools.list
List all available tools.name, description, and inputSchema.
tools.call
Call a tool with arguments.| Parameter | Type | Description |
|---|---|---|
name | string | Tool name |
args | Record<string, unknown> | Tool arguments |
ToolResult with methods:
Resources API
resources.list
List static resources.uri, name, description, and mimeType.
resources.listTemplates
List resource templates.uriTemplate, name, and description.
resources.read
Read a resource by URI.ResourceContent with methods:
Prompts API
prompts.list
List available prompts.name, description, and arguments.
prompts.get
Get a prompt with arguments.PromptResult with:
Session & Connection
isConnected
Check connection status.sessionId
Get the current session ID.serverInfo
Get server information.protocolVersion
Get the MCP protocol version.capabilities
Get server capabilities.hasCapability
Check for a specific capability.authenticate
Authenticate the client with a JWT token.disconnect
Disconnect from the server.Raw Protocol API
raw.request
Send a raw JSON-RPC request.raw.notify
Send a JSON-RPC notification (no response expected).raw.sendRaw
Send raw string data (for testing parse errors).Logging & Tracing
logs.all
Get all captured logs.logs.filter
Filter logs by level.logs.search
Search logs by text.logs.clear
Clear captured logs.trace.all
Get all request traces.trace.last
Get the last request trace.trace.clear
Clear request traces.Auth Fixture
Theauth fixture generates JWT tokens for authentication testing.
createToken
Create a valid JWT token.createExpiredToken
Create an expired token for testing expiration handling.createInvalidToken
Create a token with an invalid signature.users
Pre-built test user configurations.getJwks
Get the public JWKS for token verification.getIssuer
Get the token issuer.getAudience
Get the token audience.Server Fixture
Theserver fixture provides server control.
info
Server information.createClient
Create an additional MCP client.restart
Restart the server.getLogs
Get server-side logs.clearLogs
Clear server logs.MockOAuthServer
A fully-functional mock OAuth 2.0 / OpenID Connect server for testing authentication flows.Constructor
MockOAuthServerOptions
MockTestUser
Methods
start
Start the OAuth server.stop
Stop the OAuth server.setAutoApprove
Enable or disable auto-approval of authorization requests.setTestUser
Set the test user for authorized sessions.addValidRedirectUri
Add a valid redirect URI pattern.clearStoredTokens
Clear all stored authorization codes and refresh tokens.getTokenFactory
Get the token factory used by this server.Properties
info
Server information (available afterstart()).
Supported Endpoints
| Endpoint | Description |
|---|---|
/.well-known/openid-configuration | OpenID Connect discovery |
/.well-known/oauth-authorization-server | OAuth 2.0 metadata |
/.well-known/jwks.json | JSON Web Key Set |
/oauth/authorize | Authorization endpoint |
/oauth/token | Token endpoint |
/userinfo | UserInfo endpoint |
Supported Grant Types
authorization_code- Standard OAuth 2.0 authorization code flowrefresh_token- Token refreshanonymous- Issue anonymous tokens (for testing)
Example
MockCimdServer
Mock server for CIMD (Client ID Metadata Documents) testing. Serves client metadata documents at configurable paths, allowing testing of OAuth flows with dynamic client registration via CIMD.Constructor
MockCimdServerOptions
MockCimdClientOptions
Options for registering a mock CIMD client.Methods
start
Start the mock CIMD server.stop
Stop the mock CIMD server.registerClient
Register a client and return its client_id URL.client_id URL to use in OAuth flows (e.g., http://localhost:PORT/clients/test-client/metadata.json).
getClientId
Get the client_id URL for a previously registered client.removeClient
Remove a registered client.clear
Clear all registered clients and custom responses.registerInvalidDocument
Register an invalid document for error testing.registerFetchError
Register a custom error response for a path.Property
info
Server info (only available afterstart()).
Example
TestTokenFactory
Factory for creating JWT tokens for testing authentication.Constructor
TokenFactoryOptions
Methods
createTestToken
Create a token with custom claims.createAdminToken
Create a token with admin privileges.sub: 'test-admin' and scopes: ['*'].
createUserToken
Create a token with standard user privileges.sub: 'test-user' and scopes: ['read', 'write'].
createAnonymousToken
Create an anonymous token.sub: 'anonymous' and no scopes.
createExpiredToken
Create an already-expired token for testing expiration handling.createTokenWithInvalidSignature
Create a token with an invalid signature for testing signature verification.getPublicJwks
Get the public JWKS for token verification.getIssuer
Get the token issuer.getAudience
Get the token audience.Example
Mock Registry
Themcp.mock API for mocking MCP responses.
mock.add
Add a mock definition.mock.tool
Convenience method for mocking tool responses.mock.toolError
Mock a tool error.mock.resource
Mock a resource response.mock.clear
Clear all mocks.Request Interceptors
Themcp.intercept API for intercepting requests and responses.
intercept.request
Intercept outgoing requests.intercept.response
Intercept incoming responses.intercept.delay
Add delay to all requests.intercept.failMethod
Fail requests to a specific method.HTTP Mock API
ThehttpMock module for mocking external HTTP requests.
httpMock.interceptor
Create an HTTP interceptor.Interceptor Methods
get, post, put, delete
Create method-specific mocks.any
Match any HTTP method.mock
Full mock definition.allowPassthrough
Allow unmatched requests to reach the network.assertDone
Assert all one-time mocks were used.pending
Get unused mocks.restore
Restore original fetch function.MockHandle
Returned by mock methods.Response Helpers
httpResponse
Pre-built HTTP response creators.mockResponse
Pre-built MCP response creators.Custom Matchers
All custom Jest matchers added by@frontmcp/testing.
Tool Matchers
Result Matchers
Content Matchers
Resource Matchers
Prompt Matchers
JSON-RPC Matchers
Error Codes
Common MCP error codes for use in tests.| Code | Name | Description |
|---|---|---|
-32700 | Parse error | Invalid JSON |
-32600 | Invalid request | Invalid JSON-RPC structure |
-32601 | Method not found | Unknown method |
-32602 | Invalid params | Invalid parameters |
-32603 | Internal error | Server error |
-32001 | Unauthorized | Authentication required |
-32002 | Resource not found | Resource doesn’t exist |
-32800 | Request cancelled | Request was cancelled |