Skip to main content
Complete API documentation for all @frontmcp/testing exports, types, and methods.

Test Function

test

The main test function with fixture injection.

test.use

Configure fixtures for a test file.

McpTestClient

The primary fixture for testing MCP servers.

Tools API

tools.list

List all available tools.
Returns: Array of tool definitions with name, description, and inputSchema.

tools.call

Call a tool with arguments.
Returns: ToolResult with methods:

Resources API

resources.list

List static resources.
Returns: Array of resources with uri, name, description, and mimeType.

resources.listTemplates

List resource templates.
Returns: Array of templates with uriTemplate, name, and description.

resources.read

Read a resource by URI.
Returns: ResourceContent with methods:

Prompts API

prompts.list

List available prompts.
Returns: Array of prompts with name, description, and arguments.

prompts.get

Get a prompt with arguments.
Returns: 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.
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

The auth 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

The server 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 after start()).

Supported Endpoints

Supported Grant Types

  • authorization_code - Standard OAuth 2.0 authorization code flow
  • refresh_token - Token refresh
  • anonymous - 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.
Returns the 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 after start()).

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.
Returns a token with sub: 'admin-001' (default) and scopes: ['admin:*', 'read', 'write', 'delete'].

createUserToken

Create a token with standard user privileges.
Returns a token with sub: 'user-001' (default) and scopes: ['read', 'write'] (default).

createAnonymousToken

Create an anonymous token.
Returns a token with sub: 'anon:{timestamp}' and scopes: ['anonymous'].

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

The mcp.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

The mcp.intercept API for intercepting requests and responses.

intercept.request

Intercept outgoing requests.
Returns: Function to remove the interceptor.

intercept.response

Intercept incoming responses.

intercept.delay

Add delay to all requests.
Returns: Function to remove the delay.

intercept.failMethod

Fail requests to a specific method.
Returns: Function to remove the failure.

HTTP Mock API

The httpMock 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

For role checks on individual messages, use plain Jest assertions on message.role. message.content is a discriminated union (TextContent | ImageContent | EmbeddedResource), so narrow it before reading .text:

JSON-RPC Matchers

UI Matchers (for testing tool UI responses)


Error Codes

Common MCP error codes for use in tests.

Type Exports

All types are exported for TypeScript usage.