Labsco
vola-trebla logo

playwright-trace-decoder-mcp

โ˜… 1

from vola-trebla

MCP server for unpacking and analyzing Playwright trace.zip archives

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

๐ŸŽญ playwright-trace-decoder-mcp

npm downloads

An MCP server that unpacks and structures Playwright trace.zip archives so AI agents can perform root-cause analysis on CI failures โ€” without drowning in raw JSON or blowing up the context window.

๐Ÿค” The Problem

When a Playwright test fails in CI, you get a trace.zip. It's a binary blob. LLMs can't read it natively, and dumping the raw contents exceeds the context window. Engineers end up copying log snippets into ChatGPT manually like it's 2022.

This MCP server solves that: 16 focused tools that expose exactly the signal an agent needs to diagnose a failure, with pagination and ARIA compression to keep token costs low.

๐Ÿธ E2E Failure Investigation Example

Here is a quick look at how an AI agent uses the new tools in v0.3.0 to instantly find and inspect a failure:

  1. Locate the exact source code bug via map_locator_to_source:

    // Request arguments
    { "trace_path": "/path/to/trace.zip" }
    
    // Response payload
    {
      "action_type": "Click locator('#super-toad-not-found')",
      "locator": "#super-toad-not-found",
      "error": "TimeoutError: locator.click: Timeout 5000ms exceeded.",
      "step_title": "Click locator('#super-toad-not-found')",
      "stack": [
        {
          "file": "/Users/albertdev/Projects/ideas/sample-playwright-project/tests/google-pom.spec.ts",
          "line": 18,
          "column": 17
        }
      ],
      "source_location": {
        "file": "/Users/albertdev/Projects/ideas/sample-playwright-project/tests/google-pom.spec.ts",
        "line": 18,
        "column": 17
      }
    }

    No more guessing! The agent knows exactly which file, line, and column caused the timeout.

  2. Extract critical visual frames around the failure via extract_critical_frames:

    // Request arguments
    { "trace_path": "/path/to/trace.zip", "limit": 1 }
    
    // Response payload
    [
      {
        "timestamp": 1779137404287,
        "mime_type": "image/jpeg",
        "step_title": "Clicking #super-toad-not-found element",
        "data": "/9j/4AAQSkZJRgABAQAAAQABAAD/..." // Base64 JPEG
      }
    ]

    Allows the agent to visual-verify page state immediately before/after failure without pulling massive image lists.

  3. Trim the trace to save CI storage / transfer costs via trim_trace_archive:

    // Request arguments
    { "trace_path": "/path/to/trace.zip" }
    
    // Response payload
    {
      "original_size_bytes": 2449682,
      "trimmed_size_bytes": 511698,
      "compression_ratio_percent": 79,
      "trimmed_trace_path": "/path/to/trace.trimmed.zip"
    }

    Shrinks large traces by deleting screenshots outside the critical failure window. Saved 79% of disk space!

๐Ÿ› ๏ธ Tools

Tools are grouped by how an agent should sequence them when diagnosing a failure.

Inspection โ€” read trace data

ToolArgumentsWhat it returns
get_test_metadatatrace_pathBrowser, platform, viewport, test title, wall-clock start time
get_trace_summarytrace_pathFailing action + top-level error + total action count
get_action_timelinetrace_path, limit, offsetPaginated list of all actions with API names, locators, and timings
get_filtered_network_logstrace_path, limit, offsetOnly 4xx/5xx responses โ€” static assets (CSS, JS, fonts, images) stripped
get_console_errorstrace_path, limit, offsetJS exceptions and warnings from the browser console
get_element_state_at_failuretrace_pathFailing locator, error message, and raw before/after metadata
extract_trace_metadata_stricttrace_pathFormat version, retry session breakdown, HAR payload mode (embed/attach/omit)

All list-returning tools support limit (1โ€“500, default 50) and offset pagination with a has_more flag.

trace_path accepts either an absolute local path or an HTTPS URL โ€” the server downloads the file automatically and caches it for the session.

DOM / UI analysis

ToolArgumentsWhat it returns
get_aria_accessibility_treetrace_path, action_index?ARIA accessibility tree as compact YAML (~90% fewer tokens than raw HTML). Defaults to the snapshot at the failed action.
get_dom_mutation_deltatrace_path, action_indexSet-diff of ARIA lines before vs after a specific action โ€” added/removed elements only, not two full DOM dumps
get_screenshot_at_failuretrace_path, screenshot_index?Base64 JPEG screenshot closest to the moment of failure. Use when ARIA tree is empty (captcha, blank page). screenshot_index lets you walk the full visual timeline.
analyze_race_conditionstrace_pathNetwork requests that were in-flight when an interaction or assertion fired
correlate_dom_and_networktrace_pathFor each action where a fetch completed and the DOM mutated within ยฑ100ms: triggering URL, response status, body snippet, and exact nodes added/removed
extract_critical_framestrace_path, lookback_ms?, lookforward_ms?, limit?Extracts key screencast screenshots (base64) from a temporal window around failure, resolved with step titles

Root-cause analysis

ToolArgumentsWhat it returns
get_causal_chain_for_failuretrace_path, lookback_ms?Chronological chain of preceding actions, network errors, and console errors leading to the failure (default window: 5 s)
generate_error_signaturetrace_pathStable 12-char SHA-1 hash of the normalized error โ€” use to group duplicate failures across parallel CI runs
compare_tracespassing_trace_path, failing_trace_pathLCS-aligned action sequence between a passing and failing run: structural divergence, timing anomalies (>500 ms), unmatched actions, network delta
map_locator_to_sourcetrace_path, action_index?Maps a failing browser interaction (or specific action index) to the exact line of test code via runner execution stack

Performance analysis

ToolArgumentsWhat it returns
detect_performance_anomaliestrace_path, slow_action_threshold_ms?, frame_drop_threshold_ms?Ranked list of slow actions and frame drops with suspected_cause (main thread blocked / network saturation / navigation timeout). Also reports p50/p95 action duration and a memory leak flag.
trim_trace_archivetrace_path, divergence_only?Shrinks trace zip by deleting screenshots outside critical failure window (t_fail - 5s to t_fail + 1s). Returns trimmed path & size delta.

๐Ÿ’ฌ Suggested agent workflow

get_trace_summary              โ† what failed?
get_causal_chain_for_failure   โ† what led up to it?
get_aria_accessibility_tree    โ† what did the page look like?
get_screenshot_at_failure      โ† ARIA empty? get the actual screenshot
get_dom_mutation_delta         โ† what changed right before the failure?
analyze_race_conditions        โ† was a network request still pending?
correlate_dom_and_network      โ† which fetch caused which DOM change?
compare_traces                 โ† flaky? compare to a passing run
detect_performance_anomalies   โ† timeout but no JS error? check for Long Tasks

๐Ÿ—๏ธ Architecture

trace.zip
  โ”œโ”€โ”€ *.trace          โ†’ JSONL: before/after action pairs, console events, frame snapshots
  โ”œโ”€โ”€ *.network        โ†’ JSONL: HAR resource-snapshot entries
  โ””โ”€โ”€ resources/
      โ”œโ”€โ”€ page@*.jpeg  โ†’ screenshots taken during the run
      โ””โ”€โ”€ ...          โ†’ fonts, stylesheets, other captured resources

The parser streams each file line-by-line (no full-buffer split) and caches results in-process with an LRU (max 50 entries), keyed by path + mtime. Re-reading the same unmodified trace costs zero I/O.

Frame snapshots store the DOM as nested arrays (["TAG", {attrs}, ...children]). The ARIA translator walks this tree and outputs compact YAML, reducing token cost by ~90% vs raw HTML.

๐Ÿ—๏ธ Stack

  • @modelcontextprotocol/sdk โ€” MCP server runtime
  • adm-zip โ€” zip extraction
  • zod v4 โ€” input schema validation
  • TypeScript, ESLint, Prettier, Husky, GitHub Actions CI

๐Ÿ“‹ Scripts

npm run build        # compile TypeScript โ†’ dist/
npm run lint         # ESLint
npm run format       # Prettier --write
npm run format:check # Prettier check (used in CI)

๐Ÿ“„ License

MIT