Writes Playwright tests for MCP servers using @gleanwork/mcp-server-tester. Tests call server tools directly via MST fixtures and assert on responses, schemas, errors, or snapshots without a client or model.
Ships in mcp-server-tester. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A test checks a server directly: it calls a tool with fixed arguments through MST's mcp fixture and asserts on the response with MST's matchers. Tests are fast and deterministic, so run each once, in CI.
A test has no client and no model, so it can't tell you whether a model would pick the tool. That is an eval: use the write-mcp-eval skill.
@gleanwork/mcp-server-tester and @playwright/test (npm install --save-dev @gleanwork/mcp-server-tester@rc @playwright/test).await mcp.listTools() in a test.playwright.config.ts for an mcpConfig (Step 1).npx mst generate --command "node server.js" --tool get_weather --args '{"city":"London"}' calls a tool and writes the call as a test (default tests/generated.spec.ts), with assertions suggested from the real response. Run it once per call, then edit the spec: it is a fast way to record what the server returns. npx @gleanwork/mcp-server-tester@rc init --command "node server.js" scaffolds a new project. Both run in an agent's shell when the flags give every answer (2.0.0-rc.0 and older fail there with Raw mode is not supported). For anything they don't cover, write playwright.config.ts (Step 1) and the specs (Step 2) yourself.
Each Playwright project's use.mcpConfig says how to reach the server:
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
reporter: [['list'], ['@gleanwork/mcp-server-tester/reporters/mcpReporter']],
projects: [
{
name: 'local',
use: {
mcpConfig: {
transport: 'stdio',
command: 'node',
args: ['./dist/server.js'],
env: { LOG_LEVEL: 'warn' },
},
},
},
{
name: 'staging',
use: {
mcpConfig: {
transport: 'http',
serverUrl: 'https://staging.example.com/mcp',
auth: { accessToken: process.env.MCP_ACCESS_TOKEN },
},
},
},
],
});
HTTP servers take serverUrl (not url) and optional headers. For auth:
| Need | auth setting |
|---|---|
| A token you already have | { accessToken: process.env.MCP_ACCESS_TOKEN } |
| CI, service account, no browser | { clientCredentials: { tokenEndpoint: 'https://auth.example.com/oauth/token' } } (reads MCP_CLIENT_ID and MCP_CLIENT_SECRET) |
| A user logs in once | npx mst login <server-url>: without a terminal it prints the sign-in URL for the user to open; the mcp fixture uses the stored login and refreshes it |
| A browser OAuth flow in global setup | { oauth: { serverUrl, scopes, authStatePath } } (see Authentication) |
The mcp fixture handles auth from mcpConfig, so tests don't change. mst token <server-url> --format gh prints a stored login as CI secrets.
mcpConfig.protocol picks the MCP protocol: 'legacy' (default), 'auto', or a revision such as '2026-07-28'. To run every test on both:
import { defineConfig } from '@playwright/test';
import { protocolMatrix } from '@gleanwork/mcp-server-tester';
const mcpConfig = {
transport: 'stdio' as const,
command: 'node',
args: ['./dist/server.js'],
};
export default defineConfig({
projects: protocolMatrix({ name: 'local', use: { mcpConfig } }, [
'legacy',
'2026-07-28',
]),
});
Import test and expect from the fixtures entry point. The expect from @playwright/test doesn't have MST's matchers.
import { test, expect } from '@gleanwork/mcp-server-tester/fixtures/mcp';
test.describe('search', () => {
test('returns results for a query', async ({ mcp }) => {
const result = await mcp.callTool('search', {
query: 'quarterly planning',
});
expect(result).not.toBeToolError();
expect(result).toContainToolText(['quarterly', 'planning']);
});
test('server lists the tool', async ({ mcp }) => {
const tools = await mcp.listTools();
expect(tools.map((tool) => tool.name)).toContain('search');
});
});
The mcp fixture:
| Member | Does |
|---|---|
callTool(name, args) | Calls a tool. Protocol errors (such as -32602 for an unknown tool) come back as error results, not rejections |
listTools() | Every tool the server lists |
request(method, params, schema) | Sends any MCP request and parses the result with a Zod schema |
listResources(), readResource(uri) | Resources |
skills | Agent Skills over MCP: supported(), list(), get(uri), read(uri) |
protocol | The requested and negotiated protocol: test.skip(mcp.protocol.era !== 'modern') |
getServerInfo() | The server's name and version |
client | The raw SDK Client from @modelcontextprotocol/client |
| Matcher | Passes when |
|---|---|
toMatchToolResponse(expected) | The response deep-equals expected |
toContainToolText(text, { caseSensitive? }) | The text contains every substring |
toMatchToolPattern(patterns) | The text matches every pattern (strings or RegExp) |
toMatchToolSchema(zodSchema) | The structured content or JSON text validates |
toMatchToolSnapshot(name, sanitizers?) | The response matches the saved snapshot. Async |
toBeToolError(expected?) | The response is an error; a string or list checks the message |
toHaveToolResponseSize({ minBytes?, maxBytes? }) | The text's UTF-8 size is within bounds |
toSatisfyToolPredicate(fn, description?) | fn(response, text) returns true or { pass: true }. Async |
toPassToolJudge(rubric, options?) | An LLM judge scores the response at or above passingThreshold. Async |
toHaveToolCalls and toHaveToolCallCount check a client's tool calls, not a tool response; they belong to evals.
test('weather for London', async ({ mcp }) => {
const result = await mcp.callTool('get_weather', { city: 'London' });
expect(result).toContainToolText('London');
expect(result).toMatchToolPattern([/temperature: -?\d+/, /humidity: \d+%/]);
});
test('unknown city is an error', async ({ mcp }) => {
const result = await mcp.callTool('get_weather', { city: 'Atlantis' });
expect(result).toBeToolError(['not found', 'unknown city']);
});
test('missing argument is an error', async ({ mcp }) => {
const result = await mcp.callTool('get_weather', {});
expect(result).toBeToolError();
});
getToolProtocolError(result) (from @gleanwork/mcp-server-tester) returns { code, message } when the error was a JSON-RPC protocol error, else null.
import { z } from 'zod';
const Weather = z.object({
city: z.string(),
temperature: z.number(),
conditions: z.string(),
});
test('weather has the documented shape', async ({ mcp }) => {
const result = await mcp.callTool('get_weather', { city: 'London' });
expect(result).toMatchToolSchema(Weather);
});
Snapshots fit deterministic output: help text, config, a mocked backend. Sanitize values that change.
test('config output is stable', async ({ mcp }) => {
const result = await mcp.callTool('get_config', {});
await expect(result).toMatchToolSnapshot('config', [
'uuid',
'iso-date',
{ remove: ['requestId', 'session.id'] },
{ pattern: /token_[a-z0-9]+/, replacement: '[TOKEN]' },
]);
});
Built-in sanitizers: uuid, iso-date, timestamp, jwt, objectId. Update snapshots on purpose with npx playwright test --update-snapshots, and review the diff.
test('search output is bounded', async ({ mcp }) => {
const result = await mcp.callTool('search', { query: 'common term' });
expect(result).toHaveToolResponseSize({ minBytes: 100, maxBytes: 50_000 });
});
test('search returns at least three results', async ({ mcp }) => {
const result = await mcp.callTool('search', { query: 'onboarding' });
await expect(result).toSatisfyToolPredicate((response, text) => {
const count = text.match(/^## /gm)?.length ?? 0;
return {
pass: count >= 3,
message: `expected 3 or more results, got ${count}`,
};
}, 'result count');
});
test('summary is faithful', async ({ mcp }) => {
const result = await mcp.callTool('summarize', { documentId: 'doc-42' });
await expect(result).toPassToolJudge('groundedness', {
passingThreshold: 0.8,
});
});
Judges need an API key (ANTHROPIC_API_KEY for the default anthropic judge, which also needs @anthropic-ai/sdk). Built-in rubrics: correctness, completeness, groundedness, instruction-following, conciseness; or pass your own text. Options: passingThreshold (default 0.7), reference, reps, provider, model, and judge for a plugin's judge ({ judge: 'acme/judge/completeness' }, with test.use({ mcpPlugins: [plugin] })). Judges cost a model call and vary between runs, so prefer exact matchers when they can say what you mean.
import { z } from 'zod';
import { runConformanceChecks } from '@gleanwork/mcp-server-tester';
test('server conforms to the protocol', async ({ mcp }, testInfo) => {
const result = await runConformanceChecks(
mcp,
{ requiredTools: ['search'] },
testInfo
);
expect(result.pass).toBe(true);
});
test('skills are listed', async ({ mcp }) => {
test.skip(!mcp.skills.supported(), 'server does not serve skills');
const skills = await mcp.skills.list();
expect(skills.length).toBeGreaterThan(0);
});
test('custom method', async ({ mcp }) => {
const result = await mcp.request(
'acme/status',
{},
z.object({ ok: z.boolean() })
);
expect(result.ok).toBe(true);
});
runConformanceChecks runs the checks for the negotiated protocol; failing "should" checks are warnings, and result.pass reflects the "must" checks. Pass testInfo to show the result in the report.
To keep many tool checks as data, read the file and make each entry a test():
import { test, expect } from '@gleanwork/mcp-server-tester/fixtures/mcp';
import checks from '../tool-checks.json' with { type: 'json' };
interface ToolCheck {
name: string;
tool: string;
args: Record<string, unknown>;
containsText?: string[];
isError?: boolean;
}
for (const check of checks as ToolCheck[]) {
test(check.name, async ({ mcp }) => {
const result = await mcp.callTool(check.tool, check.args);
if (check.isError) expect(result).toBeToolError();
else expect(result).not.toBeToolError();
if (check.containsText)
expect(result).toContainToolText(check.containsText);
});
}
This file is yours, not an MST dataset. MST datasets hold eval cases with an input; a 1.x dataset of toolName and args cases fails to load and becomes tests like these.
// tests/weather.spec.ts
import { test, expect } from '@gleanwork/mcp-server-tester/fixtures/mcp';
import { z } from 'zod';
const Weather = z.object({
city: z.string(),
temperature: z.number(),
conditions: z.string(),
});
test.describe('get_weather', () => {
test('returns weather for a known city', async ({ mcp }) => {
const result = await mcp.callTool('get_weather', { city: 'London' });
expect(result).not.toBeToolError();
expect(result).toMatchToolSchema(Weather);
expect(result).toContainToolText('London');
});
test('rejects an unknown city', async ({ mcp }) => {
const result = await mcp.callTool('get_weather', { city: 'Atlantis' });
expect(result).toBeToolError('not found');
});
test('requires a city', async ({ mcp }) => {
const result = await mcp.callTool('get_weather', {});
expect(result).toBeToolError();
});
test('help text is stable', async ({ mcp }) => {
const result = await mcp.callTool('get_weather_help', {});
await expect(result).toMatchToolSnapshot('weather-help');
});
});
Run with npx playwright test. MST's reporter takes { outputDir, name, autoOpen, quiet, resultStore, runMetadata, redactStoredResponses }, and writes a test run's eval results (runEvalDataset) as a run in <outputDir>/<name>/runs/<run-id>/: by default .mcp-test-results/playwright/runs/, one variant per project. Tests and conformance checks are in Playwright's own output: the list reporter prints them, and with ['html', { open: 'never' }] added to reporter, npx playwright show-report opens them. MST's reporter and npx mst open show evals only.
test and expect come from @gleanwork/mcp-server-tester/fixtures/mcpplaywright.config.ts has an mcpConfig; HTTP servers use serverUrl; no secrets in the fileawait on toMatchToolSnapshot, toSatisfyToolPredicate and toPassToolJudgewrite-mcp-evalnpx playwright test passesWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/mcp-server-tester:write-mcp-testfrom mcp-server-tester
npx claudepluginhub gleanwork/mcp-server-tester --plugin mcp-server-tester6 skills in this plugin
/calibrate-mcp-judgeDecide how far to trust an LLM judge in an MST eval by measuring it against your own labels. Covers choosing a judge that can be checked, collecting a run to label, labeling trials with mst label, measuring the judge with mst judges check, reading TPR, TNR, kappa and unknown, improving a judge without fitting it to the labels, and when a calibration goes stale. Use when asked whether a judge is accurate or can be trusted, to calibrate or validate a judge, to label trials, to check judge agreement, or when judge scores look wrong./mcp-tester-guideReference for @gleanwork/mcp-server-tester (MST) 2.0, the Playwright-based testing and evaluation framework for MCP servers, with the `mst` CLI. Covers which skill to use for a task, the vocabulary (test, eval, case, client, variant, trial, assertion, judge), entry points, server config and auth, clients, judges, plugin names, CLI commands, what 1.x names became, and common mistakes. Use when working on MCP server tests or evals, or reading or upgrading code that uses MST./optimize-mcp-tool-metadataImprove an MCP server's tool metadata (tool names, descriptions, input schema descriptions) with measured evidence, using `mst optimize` (start, evidence, try, finish), runToolOptimization from @gleanwork/mcp-server-tester/evals, or `mst run` with tool-metadata variants. Use when asked to improve tool descriptions, fix tools a model misses or over-uses, optimize tool discoverability, or compare description rewrites. Produces a recommendation with the exact metadata to apply; never edits the server or the dataset unless asked.Other plugins' skills for the same job