
Playwright Report Mcp
io.github.hubertgajewski由 GitHub 账号 hubertgajewski 发布v3.4.0更新于 Oct 24, 2026
Run Playwright tests and surface structured results for AI agents doing test failure analysis.
概览
运行 Playwright 测试,并向 AI 助手提供结构化的通过/失败结果、失败信息与文本附件,用于测试失败分析。
- 可以做什么
- 运行 Playwright 测试套件(可指定 spec、浏览器、标签、超时、worker、重试、trace 与快照选项),可后台启动并按 run ID 轮询进度和退出状态。从上次的结果文件读取失败测试的错误信息与附件路径,无需重新运行。按测试名称读取指定文本附件,例如内置的 error-context 快照,并拒绝二进制或超大文件。在不运行测试的情况下列出所有测试及其 spec 文件和标签。
- 适用场景
- 适合让助手诊断 Playwright 测试失败,尤其是 CI 运行之后,无需重新执行测试或把完整结果文件载入上下文。也适合多 worktree 场景,由同一会话跨多个目录驱动测试。若希望助手操作浏览器、点击或截图,则不适用。
- 运行要求
- 需要 Node.js 22 或更高版本,以及本地 Playwright 项目,其中 @playwright/test 为 1.40 以上并配置了 JSON reporter(results.json)。可通过 npx 安装或从源码构建;可选环境变量 PW_ALLOWED_DIRS、PW_ALLOWED_ENV 和 PW_RESULTS_FILE 分别控制目录范围、环境变量覆盖和报告路径。未声明账号或认证;以 stdio 在桌面本地运行。
安装
在 SourceWeft 中
- 打开 控制台中的 Playwright Report Mcp,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
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.
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).
¹ 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:
Or build from source:
2. Add the JSON reporter to your Playwright project
3. Register in .mcp.json
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.
The stdio server supports both MCP protocol eras from one entrypoint:
- Modern: protocol revision
2026-07-28, selected by clients using version negotiation (for example,versionNegotiation: { mode: "auto" }). - Legacy: supported 2025-era revisions, selected by clients that use the traditional
initializehandshake. This remains the default behavior in the MCP client SDK.
The opening exchange pins one era for the connection lifetime. A client that pins an unsupported revision receives an explicit negotiation error; the server does not silently switch it to another era.
Tools
The project-scoped tools accept an optional workingDirectory parameter — see Multi-worktree support. get_run_status can use either a runId from run_tests with wait: false, or a workingDirectory lookup for the latest tracked run.
run_tests
Runs the Playwright test suite and returns structured pass/fail results.
Returns: exit code, run stats, and a summary of all tests with status, duration, and error per project.
When wait is false, returns immediately with runId, process metadata, compact numeric progress, and current results.json status. Poll get_run_status with that runId until state is completed, failed, or timedOut. The server parses Playwright progress markers such as [528/662] from stdout and discards raw stdout/stderr text so repeated polling stays token-efficient. The server allows one active tracked run per working directory, caps active tracked runs globally, and keeps a bounded history of recent terminal runs, so very old runId values can expire.
get_run_status
Returns the current status for a non-blocking run started by run_tests with wait: false.
If both fields are omitted, workingDirectory defaults to ".". If no run is tracked for the resolved directory, the tool returns state: "idle" plus results.json metadata and last parsed stats when readable. It does not process-scan for external npx playwright test commands that were not started through this MCP server.
Returns: run state, tracking flag, pid, timestamps, elapsed duration, timeout, command metadata (executable, args, cwd), optional envKeys (override names only — never values), progress: { current, total }, exit code, signal, spawn/timeout error when present, results.json path/existence/mtime/size/freshness, and parsed report stats when the report was updated after the run started. When progress has not appeared yet, current and total are null; when a terminal run has readable final stats, progress is set to the derived completed total.
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.
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.
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.
Attachments
Playwright attaches files to failed tests automatically. get_test_attachment can read any text attachment by name.
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:
Configuration
Add to your .mcp.json at the root of your project:
Environment variables
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. get_run_status also accepts workingDirectory when runId is omitted; when runId is supplied, any supplied workingDirectory must resolve to that run's recorded 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:
Then point calls at any sibling worktree:
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.
Environment overrides
run_tests and list_tests accept an optional env map that is merged onto the MCP process environment before spawning Playwright. The child therefore sees operator-allowlisted overrides on top of launch env and the parent process. Playwright configs that load dotenv without overriding existing variables keep the tool-supplied value.
The env argument is off until the operator sets PW_ALLOWED_ENV in .mcp.json. That is the same containment model as PW_ALLOWED_DIRS: the human expands what the model may do; the model cannot widen it.
A hard denylist always wins over the allowlist (comparison is case-insensitive):
- prefixes
NODE_,LD_,DYLD_,NPM_CONFIG_(the child is launched withnpx, which reads npm config from the environment) PATH,HOME,DOTENV_CONFIG_PATH- proxy variables
HTTP_PROXY,HTTPS_PROXY,ALL_PROXY,NO_PROXY,FTP_PROXY - any name matching
PASSWORD,SECRET,TOKEN,API_KEY,ACCESS_KEY,CREDENTIAL,PRIVATE_KEY,AUTH_SOCK, orAUTH_CONFIG
Keys must be POSIX names (^[A-Z_][A-Z0-9_]*$). Values cannot contain a NUL and are capped at 256 characters, with at most 16 entries per call. The value of ENV is further restricted to ^[A-Za-z0-9._-]+$ so it cannot be used as a POSIX shell startup-file path (ENV=/tmp/evil.sh is rejected).
Secrets (basic auth, passwords, API keys) stay in the project .env or in MCP launch env. They are never tool arguments. get_run_status may list override names as envKeys and never echoes override values. There is no envFile tool argument.
Target environment name (ENV=staging):
Other project switches (TEST_ENV or BASE_URL):
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:
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
Runtime code lives under src/ and compiles to dist/. Tests use Vitest with focused unit coverage for helpers plus MCP tool integration coverage via InMemoryTransport. No build step or Playwright installation required to run the regular 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:
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
来源:README.md,提交 1325f31
工具
0版本历史
2- v3.4.0最新Sep 25, 2026
- v3.3.0Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分