io.github.hubertgajewski/playwright-report-mcp
Run Playwright tests and surface structured results for AI agents doing test failure analysis.
Ask AI about io.github.hubertgajewski/playwright-report-mcp
Powered by Claude Β· Grounded in docs
I know everything about io.github.hubertgajewski/playwright-report-mcp. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Playwright Report MCP
An MCP (Model Context Protocol) server for running Playwright tests and reading structured results, failed test details, and attachment content β designed for AI agents doing test failure analysis.
Table of contents
- What it is
- What it is NOT
- Why
- Quick start
- Tools
- Attachments
- Installation
- Configuration
- Requirements
- Troubleshooting
- Development
- Cutting a release
- Contributing
- Release
- License
What it is
Playwright Report MCP gives an AI agent structured, token-efficient access to Playwright test outcomes. It runs your test suite, reads the JSON reporter output, and surfaces exactly what the agent needs: which tests failed, what the errors were, and the content of relevant attachments.
What it is NOT
There are many Playwright MCP servers that control a browser β they navigate pages, click elements, fill forms, and take screenshots. Playwright Report MCP is not one of those.
| Browser automation MCPs | Playwright Report MCP | |
|---|---|---|
| Examples | microsoft/playwright-mcp, executeautomation/mcp-playwright | this project |
| Purpose | Let an AI agent drive a browser | Let an AI agent read test results |
| Runs tests | No | Yes |
| Returns pass/fail | No | Yes |
| Surfaces error messages | No | Yes |
| Reads attachment content | No | Yes |
Why
The problem with existing approaches
Default reporters (list / dot) β Playwright's default reporters print human-readable output to stdout. Compact, but lossy: no attachment paths, no retry breakdown, no structured data.
HTML reporter (report.html) β A self-contained SPA bundle (typically 2β50 MB). Not machine-readable as text and exceeds any LLM context window.
Reading results.json directly β Works, but a full JSON report for even a small test suite is 10,000β20,000 tokens. For a failing test, most of that is passing test metadata you don't need.
What Playwright Report MCP does instead
- Filters
results.jsonto only failed tests - Returns structured, typed JSON the agent can act on immediately
- Exposes individual attachments by name so the agent fetches only what it needs
- Works on results produced by anyone β CI pipeline, a human, or the agent itself
Token cost comparison (one failed test in a 20-test suite)
Approximate input token counts based on Claude tokenization (~3β4 characters per token for mixed JSON/text content).
| What you need | Without MCP β approach | Tokens (no MCP) | With MCP β tool calls | Tokens (MCP) | Savings |
|---|---|---|---|---|---|
| Error message only β live run | npx playwright test, read stdout (list/dot) | ~500β1,200 | run_tests + get_failed_tests | ~300β500 | ~2Γ |
| Error message only β existing results | Read full results.json | ~12,500β23,000 | get_failed_tests | ~300β500 | ~25β45Γ |
| + page state at failure | + read error-context file | ~15,000β26,000 | + get_test_attachment('error-context') | ~2,800β3,500 | ~4β7Γ |
| + custom text attachmentsΒΉ | + read attachment files | ~16,200β28,500 | + get_test_attachment Γ2 | ~3,300β5,500 | ~4β5Γ |
| + full page HTML snapshotΒ² | + read snapshot file | ~41,000β103,000 | + get_test_attachment | ~33,300β85,500 | ~1.2Γ |
ΒΉ Custom text attachments β e.g. AI diagnosis (~500β2,000 tokens) and console logs (~200β500 tokens) added via
testInfo.attach()in your own fixtures.Β² Full page HTML snapshot β a custom fixture that attaches the full rendered page HTML on failure. Large pages alone can reach 30,000β80,000 tokens and dominate cost regardless of whether MCP is used.
Key observations:
- For a live run, stdout (
list/dot) is compact but gives the agent no path to attachment content β dead end for deeper analysis - Reading
results.jsondirectly costs ~12,500β23,000 tokens even when only one test failed β most of it is passing test metadata the agent doesn't need - The biggest MCP gains are in the middle rows: getting error messages + page state from existing results at ~4β45Γ lower token cost
- Full page HTML snapshot dominates cost either way; skipping it in favour of
error-contextis the single largest optimisation available
CI failure analysis
The primary use case: your CI pipeline runs the tests, the agent picks up the results after the fact and diagnoses failures. get_failed_tests reads results.json regardless of who triggered the run. No re-run needed.
Quick start
1. Install via npx (recommended)
No clone or build step needed β npx downloads and runs the server automatically:
{
"mcpServers": {
"playwright-report-mcp": {
"command": "npx",
"args": ["-y", "playwright-report-mcp"],
"type": "stdio"
}
}
}
Or build from source:
git clone https://github.com/hubertgajewski/playwright-report-mcp.git
cd playwright-report-mcp
npm install && npm run build
2. Add the JSON reporter to your Playwright project
// playwright.config.ts
reporter: [
['json', { outputFile: 'test-results/results.json' }],
['html'], // keep any existing reporters
],
3. Register in .mcp.json
{
"mcpServers": {
"playwright-report-mcp": {
"command": "npx",
"args": ["-y", "playwright-report-mcp"],
"type": "stdio"
}
}
}
4. Ask your AI agent
Run the Playwright tests and tell me what failed.
Compatibility
Tested with Claude Code (CLI). Should work with any MCP-compatible client that supports stdio transport, including Claude Desktop, Cursor, Cline, Windsurf, and Continue.dev β but these have not been verified.
Tools
All four tools accept an optional workingDirectory parameter β see Multi-worktree support.
run_tests
Runs the Playwright test suite and returns structured pass/fail results.
| Input | Type | Description |
|---|---|---|
workingDirectory | string (optional) | Playwright project directory. Absolute or relative to the MCP server launch directory. Defaults to ".". Must be under PW_ALLOWED_DIRS β see Multi-worktree support. |
spec | string (optional) | Spec file path relative to the project directory, e.g. tests/login.spec.ts. Must stay within the project directory. |
browser | enum (optional) | Chromium, Firefox, Webkit, Mobile Chrome, Mobile Safari |
tag | string (optional) | Tag filter, e.g. @smoke |
timeout | integer (optional) | Timeout in milliseconds for the whole test run. Defaults to 300000 (5 min). Use a larger value for long suites or a smaller one to fail fast. When the run is killed by this timeout, the tool returns an explicit error rather than a generic non-zero exit. |
Returns: exit code, run stats, and a summary of all tests with status, duration, and error per project.
get_failed_tests
Returns failed tests from the last run with error messages and attachment paths. Does not re-run tests β reads the existing results.json.
| Input | Type | Description |
|---|---|---|
workingDirectory | string (optional) | See Multi-worktree support. Defaults to ".". |
Returns: failed test count, titles, file paths, per-project status, error messages, and attachment paths.
get_test_attachment
Reads the content of a named text attachment for a specific test from the last run.
| Input | Type | Description |
|---|---|---|
workingDirectory | string (optional) | See Multi-worktree support. Defaults to ".". |
testTitle | string | Exact test title as shown in the report |
attachmentName | string | Attachment name, e.g. error-context, ai-diagnosis, page-html |
Returns: the attachment content as text. Binary attachments and files over 1 MB are rejected with an error. Attachment paths recorded in results.json that escape workingDirectory (via .. or absolute paths pointing elsewhere) are refused.
list_tests
Lists all tests with their spec file and tags without running them.
| Input | Type | Description |
|---|---|---|
workingDirectory | string (optional) | See Multi-worktree support. Defaults to ".". |
tag | string (optional) | Filter by tag, e.g. @smoke |
Attachments
Playwright attaches files to failed tests automatically. get_test_attachment can read any text attachment by name.
| Attachment name | Source | Present in every project |
|---|---|---|
error-context | Playwright built-in β YAML accessibility tree snapshot at the point of failure | Yes |
screenshot | Playwright built-in β PNG screenshot (binary, not readable) | Yes |
video | Playwright built-in β WebM video (binary, not readable) | Yes |
| Custom attachments | Added via testInfo.attach() in your fixtures | Depends on project |
The error-context attachment is the most useful for projects without custom fixtures β it gives a semantic, structured view of the page at the moment of failure with no setup required.
Installation
Via npx (recommended) β use the npx config shown in Quick start. No local installation needed.
From source:
git clone https://github.com/hubertgajewski/playwright-report-mcp.git
cd playwright-report-mcp
npm install
npm run build
Configuration
Add to your .mcp.json at the root of your project:
{
"mcpServers": {
"playwright-report-mcp": {
"command": "npx",
"args": ["-y", "playwright-report-mcp"],
"type": "stdio"
}
}
}
Environment variables
| Variable | Default | Description |
|---|---|---|
PW_ALLOWED_DIRS | "." (authorizes only the launch dir) | path.delimiter-separated list of directories the workingDirectory parameter may point at. Entries may be absolute or relative (resolved once against launch cwd at startup). |
PW_RESULTS_FILE | <workingDirectory>/test-results/results.json | Absolute path to the JSON reporter output file. If set, overrides the per-call default for every call. |
Set PW_RESULTS_FILE if your playwright.config.ts writes the report to a non-default location. Leave it unset in multi-worktree setups so each workingDirectory gets its own test-results/results.json.
Multi-worktree support
run_tests, list_tests, get_failed_tests, and get_test_attachment all accept an optional workingDirectory parameter β absolute, or relative to the MCP server's launch directory. This lets a single long-lived MCP session drive tests across multiple git worktrees without restarting.
Because a Playwright config is a Node module that executes on playwright test startup, the server guards the parameter with an allowlist. Callers that point workingDirectory at a directory outside PW_ALLOWED_DIRS get a structured error and no child process is spawned.
Default (no worktrees). Leave PW_ALLOWED_DIRS unset. The allowlist becomes "." β only the launch directory β and the default workingDirectory (also ".") resolves to the launch directory. Zero configuration.
Sibling worktrees. Set PW_ALLOWED_DIRS=".." in your .mcp.json to authorize every sibling of the launch directory. Relative entries resolve against the launch cwd at startup, so the same .mcp.json works for every contributor without baking in absolute paths:
{
"mcpServers": {
"playwright-report-mcp": {
"command": "npx",
"args": ["-y", "playwright-report-mcp"],
"env": { "PW_ALLOWED_DIRS": ".." },
"type": "stdio"
}
}
}
Then point calls at any sibling worktree:
{
"name": "run_tests",
"arguments": { "workingDirectory": "../my-app-feat-auth" },
}
Multiple projects. Either launch the MCP client from each project and use the default allowlist, or set PW_ALLOWED_DIRS to the shared parent and pass workingDirectory per call. The allowlist check runs at a path-segment boundary, so an entry authorizing /src/my-app will not authorize /src/my-app-evil.
Breaking change (2.x β next): the
PW_DIRenv var has been removed. Either launch the MCP client from inside the Playwright project directory (zero-config, defaultworkingDirectory: "."works), or passworkingDirectoryper call and setPW_ALLOWED_DIRSaccordingly.
Requirements
- Node.js 22+
@playwright/test1.40 or later- JSON reporter configured in your Playwright project
Playwright's default reporters (list locally, dot on CI) write to stdout only β they produce no file that can be read after the run. Add the JSON reporter alongside whatever reporters you already use:
// playwright.config.ts
reporter: [
['json', { outputFile: 'test-results/results.json' }],
['html'], // keep any existing reporters
['list'],
],
Troubleshooting
No results.json found β run tests first
The JSON reporter is not configured or is writing to a different path. Verify your playwright.config.ts has ['json', { outputFile: 'test-results/results.json' }].
list_tests parsed 0 tests from non-empty output
The --list output format may have changed in your version of Playwright. Open an issue with your Playwright version and the raw stdout output.
Attachment "..." is binary and cannot be returned as text
screenshot and video attachments are binary files. Use get_failed_tests to get attachment paths and open them directly if needed.
Attachment "..." is too large to return inline
The attachment exceeds 1 MB. Read the file directly from the path returned by get_failed_tests.
Development
npm test # run tests once
npm run test:watch # watch mode
Tests use Vitest and cover the collectSpecs helper (unit) and all four MCP tools via InMemoryTransport (integration). No build step or Playwright installation required to run the test suite.
Cutting a release
Releases are produced by pushing a v* tag. .github/workflows/release.yml picks up the tag, verifies the tag matches all three version fields, runs npm ci + npm run build + npm test, creates a GitHub Release with auto-generated notes categorized per .github/release.yml (Features / Bug fixes / Documentation / Dependencies / Other changes), and publishes to npm. .github/workflows/publish-mcp.yml then chains off Release via workflow_run and publishes server.json to the MCP registry. Merging to main does not trigger a publish.
Version lives in three places and all three must match the tag before pushing it:
package.jsonβversionserver.jsonβ top-levelversionserver.jsonβpackages[0].version
Bump all three in one PR and merge to main before cutting the release. release.yml fails the run if the tag disagrees with any of these values.
Ritual:
# After the version-bump PR has merged to main:
git checkout main && git pull
git tag v1.0.5
git push origin v1.0.5
# β release.yml fires: verifies tag, builds, tests, creates GitHub Release, publishes to npm
# β publish-mcp.yml chains off Release and publishes server.json to the MCP registry
Flow:
- Open a bump PR that updates all three version fields. Merge it to
main. - Tag the bump commit
v<version>and push the tag. release.ymlverifies tag/version alignment, runsnpm ci, confirms the version is not already published on npm, runsnpm run build+npm test, creates the GitHub Release, then publishes to npm withnpm publish --access public --provenance.publish-mcp.yml(triggered byworkflow_runonRelease) re-verifies the version fields, confirms the version is not already on the MCP registry, and publishesserver.jsonto registry.modelcontextprotocol.io.
No repository secrets required. Both npm and the MCP registry authenticate via GitHub OIDC (npm trusted publishers). The trusted publisher for npm is configured on npmjs.com under the package's Settings β Publishing access β Trusted Publisher section β no NPM_TOKEN secret exists or is needed.
Recovery from a failed publish: npm refuses to republish an existing version and restricts unpublishing after 72 hours. If a publish fails for any reason, bump to the next patch version in a new PR and cut a new release β do not try to re-run the failed release.
Contributing
See CONTRIBUTING.md for bug reports, pull requests, development setup, and commit conventions.
License
MIT β Copyright (c) Hubert Gajewski
