Skip to main content
@frontmcp/testing is the official testing library for FrontMCP, providing a complete toolkit for end-to-end testing of MCP servers. Test your tools, resources, prompts, authentication, plugins, and the full MCP protocol.

Fixture-Based

Playwright-inspired fixtures inject ready-to-use test clients

Full Protocol

Test tools, resources, prompts, and raw JSON-RPC

Offline Testing

Mock HTTP calls for fully offline test suites

Installation

@frontmcp/testing requires @frontmcp/sdk as a peer dependency and uses Jest as the test runner.

Quick Start

1. Configure Jest

The frontmcp test command auto-generates the correct Jest/SWC config. No manual jest.e2e.config.ts needed. By default the injected config discovers:
  • Colocated unit specs: src/**/*.spec.ts and src/**/*.spec.tsx
  • __tests__/**/*.spec.ts(x)
  • E2E specs: e2e/**/*.e2e.ts(x) and e2e/**/*.e2e.spec.ts(x)
Both .ts and .tsx files are transformed via SWC with the automatic JSX runtime, so React component tests work without extra setup.
Bring your own config. If a jest.config.{ts,js,mjs,cjs,json} exists in your project root, frontmcp test delegates to it instead of injecting the default config. You can also drop a jest.config.ts to customise transforms, projects, setup files, or coverage paths while still running via frontmcp test.

2. Write Your First Test

Use the .spec.ts(x) extension for unit tests colocated with your source code, and .e2e.spec.ts(x) for E2E tests under an e2e/ directory:
server.e2e.spec.ts

3. Run Tests

The library automatically:
  • Starts your FrontMCP server on the specified port
  • Connects an MCP client using Streamable-HTTP transport
  • Runs your tests with injected fixtures
  • Cleans up after all tests complete

Key Features

Fixture System

Tests receive pre-configured fixtures via dependency injection:

Custom Jest Matchers

MCP-specific matchers for cleaner assertions:

HTTP Mocking

Mock external HTTP calls for offline testing.
Important: httpMock intercepts HTTP in the test process only, NOT in the MCP server subprocess. Do not use httpMock to intercept server-to-API calls — those happen in the child process. Use httpMock for verifying client-to-server request shapes or mocking external APIs called from the test itself.

MCP Request Interception

Mock or modify MCP protocol requests:

Test Configuration

Configure tests using test.use():
Use port: 0 to automatically select an available port. This prevents conflicts when running multiple test suites in parallel.

Demo E2E reference suites

The repository ships scenario-focused Nx projects under apps/e2e/**. Each server mirrors a real deployment surface (auth modes, caching, CodeCall, OpenAPI ingestion, notifications) and already includes Jest suites wired to @frontmcp/testing.
Source layout: server code lives in apps/e2e/<project>/src, with matching tests in apps/e2e/<project>/e2e. Copy a project into your workspace or point TestServer at it during CI runs.
  • demo-e2e-public – minimal Notes + Tasks server that enforces public auth defaults and anonymous scopes.
  • demo-e2e-codecall – CRM sample that groups eight CRUD tools behind the CodeCall plugin and the new crm.store.ts.
  • demo-e2e-openapi – OpenAPI adapter smoke tests with built-in HTTP mocking examples.
  • demo-e2e-cache – Cache plugin playground for validating cache hits/misses plus execution tracking resources.
apps/e2e/demo-e2e-public/e2e/public-auth.e2e.spec.ts
Pair apps/e2e/demo-e2e-openapi/e2e/openapi.e2e.spec.ts with httpMock.interceptor() to keep tests offline: stub Beeceptor endpoints, allow passthrough for the OpenAPI spec, then call interceptor.restore() in finally.

Next Steps

Test Fixtures

Deep dive into the fixture system and available APIs

Custom Matchers

Full reference for all MCP-specific Jest matchers

Auth Testing

Test authentication flows with token generation

HTTP Mocking

Mock external API calls for offline testing