@frontmcp/testing

中文文档
1.12.2发布于 2026/11/15Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 7176

End-to-end testing for FrontMCP servers: Jest fixtures with a connected MCP client, MCP matchers, JWT and OAuth mocks, and HTTP mocking

原始使用文档
文档目录13 节
  1. Install
  2. Usage
  3. Jest presets
  4. Fixtures
  5. Matchers
  6. Configuration
  7. Notifications
  8. Protocol versions
  9. Other exports
  10. Docs
  11. Related packages
  12. Contributing
  13. License

@frontmcp/testing

End-to-end tests for FrontMCP servers. It starts your server, gives each test mcp, an MCP client connected to it, and adds matchers like toBeSuccessful() and toContainTool() to expect. Tests run under Jest, with frontmcp test or your own Jest configuration. It also has the pieces to build tests of your own: a JSON Web Token (JWT) factory, mock OAuth and API servers, HTTP mocking and request interceptors.

npm License

Install

npm install -D @frontmcp/testing jest tsx

Requires Node.js 24 or later, and @frontmcp/sdk in the project (a peer dependency, as is @frontmcp/lazy-zod, which comes with the SDK). jest (29 or 30) runs the tests, and @jest/globals, which comes with it, provides expect; both are optional peers so that the token factory and mock servers work outside Jest. The library starts your server with tsx. @swc/jest, which compiles the tests, is installed with the package.

Usage

// e2e/tickets.e2e.spec.ts
import { expect, test } from '@frontmcp/testing';

test.use({ server: './src/main.ts' });

test('server exposes tools', async ({ mcp }) => {
  const tools = await mcp.tools.list();
  expect(tools).toContainTool('search_tickets');
});

test('tool execution works', async ({ mcp }) => {
  const result = await mcp.tools.call('search_tickets', { query: 'log' });
  expect(result).toBeSuccessful();
  expect(result.json()).toEqual({ tickets: [{ id: 'T-1', title: 'Cannot log in' }] });
});
npx frontmcp test

frontmcp test (from the frontmcp CLI) runs src/**/*.spec.ts, __tests__/**/*.spec.ts and e2e/**/*.e2e.spec.ts with a Jest configuration it generates. With a jest.config.* of your own, start from one of the Jest presets. The server starts when the first test that needs it runs, and tests with the same test.use() options share it.

Jest presets

PresetUse it for
preset: '@frontmcp/testing'The configuration frontmcp test generates: unit and e2e specs, a 60-second timeout, and the matchers registered through @frontmcp/testing/setup
preset: '@frontmcp/testing/jest-preset-unit'Unit tests, in a CommonJS project too: Jest's default 5-second timeout, no setup file, and every *.spec.ts(x) except *.e2e.spec, *.perf.spec and *.pw.spec files. Add @frontmcp/testing/setup to setupFilesAfterEnv to use the matchers

Both compile TypeScript and TSX with @swc/jest, and both compile jose, @noble/hashes and @noble/ciphers, ESM-only packages the SDK loads, which Jest's CommonJS runtime otherwise fails on with SyntaxError: Unexpected token 'export'. To compile your TypeScript with ts-jest, set a transform for .ts only, so the preset still compiles those packages:

// jest.config.js
module.exports = {
  preset: '@frontmcp/testing/jest-preset-unit',
  transform: { '^.+\\.tsx?$': 'ts-jest' },
};

testMatch and transformIgnorePatterns of your own replace the preset's lists, so copy its entries into yours.

Fixtures

FixtureDescription
mcpA client connected to the server, new for each test: tools, resources, prompts, raw requests, notifications and logs
serverThe running server: info (baseUrl, port, pid), createClient(), createClientBuilder(), restart(), getLogs(), clearLogs()
authMakes JWTs: createToken(), createExpiredToken(), createInvalidToken(), users (admin, user, readOnly), getJwks(), getIssuer(), getAudience()

test.beforeEach() and test.afterEach() receive the same fixtures when their callback takes a parameter.

Matchers

Tools: toContainTool, toBeSuccessful, toBeError, toHaveTextContent, toHaveImageContent, toHaveResourceContent, toPassOutputSchemaWhole

Resources: toContainResource, toContainResourceTemplate, toHaveMimeType

Prompts: toContainPrompt, toHaveMessages

Protocol: toBeValidJsonRpc, toHaveResult, toHaveError, toHaveErrorCode

Tool UI: toHaveRenderedHtml, toContainHtmlElement, toContainBoundValue, toBeXssSafe, toHaveWidgetMetadata, toHaveCssClass, toNotContainRawContent, toHaveProperHtmlStructure

Use them through the expect this package exports, which is Jest's expect with these matchers typed. frontmcp test and the @frontmcp/testing preset register them, through @frontmcp/testing/setup, which you can add to setupFilesAfterEnv yourself.

Configuration

import { test } from '@frontmcp/testing';

test.use({
  server: './src/main.ts', // the entry file, run with tsx
  port: 3003, // default: a free port
  transport: 'streamable-http', // or 'sse'
  entryPath: '/mcp', // if the server sets http.entryPath
  publicMode: true, // send no Authorization header, for auth: { mode: 'public' }
  logLevel: 'debug', // the server's own log level
  protocolVersion: '2026-07-28', // default: '2025-06-18'
  mcpLogLevel: 'info', // the log messages the clients ask for; default: 'debug', false for none
  env: { API_KEY: 'test' },
  startupTimeout: 30_000,
});

Call test.use() at the top of a file to configure every test in it, or inside test.describe() to configure that block, which then gets a server of its own. baseUrl tests a server that's already running instead of starting one.

Notifications

A tool's progress and log messages reach mcp.notifications by the time mcp.tools.call() returns, from a FrontMCP server that sends them on the call's own response (1.11.3 and later). The client asks for every log message unless mcpLogLevel says otherwise, and each progress update keeps its message.

Protocol versions

The client speaks MCP 2025-06-18 by default, and any revision up to 2025-11-25 opens a session with initialize. With protocolVersion: '2026-07-28' it's stateless: it connects with server/discover, sends each request with its _meta and mirrored headers (MCP-Protocol-Version, Mcp-Method, Mcp-Name, Mcp-Param-*), answers a tool's this.elicit() through input_required with your mcp.onElicitation() handler, and listens for changes with subscriptions/listen. mcp.discover() sends server/discover from a client on any version.

Other exports

ExportUse it to
McpTestClient, TestServerStart a server and connect a client yourself, without the fixtures
TestTokenFactory, MockOAuthServer, MockCimdServerSign tokens, stand in for an OAuth provider, and serve client ID metadata documents
MockAPIServer, httpMock, httpResponseAnswer the HTTP calls your tools make
mockResponse, interceptorsMock or change MCP requests on the mcp client
perfTest, LeakDetector, MetricsCollectorMeasure memory and time, and find leaks

Docs

Contributing

Source: libs/testing. Issues and pull requests are welcome; see CONTRIBUTING.md.

License

Apache-2.0. See LICENSE.

版本与发布记录

@frontmcp/testing 共发布 116 个版本,首次发布于 2025/12/12;过去 12 个月发布了 116 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.12.2latest2026/11/151 天前
1.12.12026/11/132 天前
1.12.02026/11/114 天前
1.12.0-rc.1rc2026/11/114 天前
1.11.32026/11/106 天前
1.11.22026/11/096 天前

其他发布通道:beta → 1.1.2-beta.1,rc → 1.12.0-rc.1。

关于 @frontmcp/testing 的常见问题

@frontmcp/testing 是什么?

End-to-end testing for FrontMCP servers: Jest fixtures with a connected MCP client, MCP matchers, JWT and OAuth mocks, and HTTP mocking

如何安装 @frontmcp/testing?

在项目目录运行 npm install @frontmcp/testing,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@frontmcp/sdk(1.12.2)、@frontmcp/lazy-zod(1.12.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@frontmcp/testing 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@frontmcp/testing 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@frontmcp/testing 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@frontmcp/testing 可以商用吗?

@frontmcp/testing 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@frontmcp/testing 的下载量有多少?

根据 npm 官方下载统计,@frontmcp/testing 在 2026/10/16 – 2026/11/14 这 30 天内被下载 7,176 次,日均约 239 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frontmcp/testing 还在维护吗?

最新版本 1.12.2 发布于 2026/11/15(1 天前);至今共发布 116 个版本,其中过去 12 个月发布了 116 个;首次发布于 2025/12/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。