Skip to content

[BUG] patch-playwright-mcp misses mid-session plugin cache updates #98

Closed

Description

@gatezh

Summary

The patch-playwright-mcp script ships in the claude-code image to rewrite cached @playwright/mcp .mcp.json files so the MCP launches system chromium (/usr/bin/chromium) instead of the chrome channel (default /opt/google/chrome/chrome, which isn't installed in this image). It is correctly wired to postCreateCommand (via init-plugins.sh) and postStartCommand. However, that wiring only covers the boot-time state of the plugin cache.

When Claude Code's playwright plugin auto-updates during a session — extracting a fresh cache dir for the new version hash — the new .mcp.json is unpatched. The first MCP invocation in that session then fails with:

Error: async initializeServer: Chromium distribution 'chrome' is not found at /opt/google/chrome/chrome
Run "npx playwright install chrome"

The MCP server caches .mcp.json in memory at launch, so running patch-playwright-mcp mid-session only fixes the next session — it doesn't unblock the current one.

This is the structural follow-up the script's own comment foreshadows:

"Plugin auto-updates extract into fresh cache dirs (one per version hash), each with an unpatched .mcp.json. Patching only the first match (#64) left newer cache dirs broken until container rebuild."

The fix landed in #64/#85/#87/#91 made the script idempotent and loop over all matches, but it can only patch what exists at the moment it runs. There's no mid-session retrigger.

Reproduction

  1. Start a fresh devcontainer based on ghcr.io/gatezh/devcontainers/claude-code:latest.
  2. Open Claude Code; let the playwright plugin auto-update (or wait until any cache materialization that happens after postStart fires).
  3. In the same session, invoke any playwright MCP tool — e.g. mcp__plugin_playwright_playwright__browser_navigate to http://localhost:<port>/.
  4. Observe the chrome-path error above.
  5. Manually run /usr/local/bin/patch-playwright-mcp — it patches multiple cache dirs that postStart didn't reach. The current MCP session is still broken (config is cached in memory); a new session works.

Verification

Real session evidence:

# Container start (proxy: docker-init / first process)
$ stat -c '%y' /proc/1
2026-05-12 09:17:13

# Playwright plugin cache .mcp.json mtimes
$ stat -c '%y %n' ~/.claude/plugins/cache/claude-plugins-official/playwright/*/.mcp.json
2026-05-12 11:50:38 …/playwright/ac45fdae4b7a/.mcp.json
2026-05-12 11:50:38 …/playwright/45896c8f2fe6/.mcp.json
2026-05-12 11:50:38 …/playwright/84d2d12cd9d1/.mcp.json
2026-05-12 11:50:38 …/playwright/480a410cc0dd/.mcp.json
2026-05-12 11:50:38 …/playwright/b392f5189934/.mcp.json
2026-05-12 11:50:38 …/playwright/0742692199b4/.mcp.json
2026-05-12 11:50:38 …/playwright/00679aef889e/.mcp.json

All 7 mtimes match the manual patch run, not postStart at 09:17. Either postStart ran when the playwright cache dir was empty (dirs created later by plugin auto-update), or postStart ran but the cache was subsequently overwritten by a plugin auto-update. Same observable outcome: the patch script can only fix what exists at the moment it runs.

The .mcp.json content after manual patching (target state for all cache dirs):

{
  "playwright": {
    "command": "npx",
    "args": [
      "@playwright/mcp@latest",
      "--browser", "chromium",
      "--executable-path", "/usr/bin/chromium",
      "--no-sandbox",
      "--headless"
    ]
  }
}

Suggested fix

The patch script is idempotent and fast (~20ms for 7 dirs). The natural fix is to run it once per Claude Code session start, after plugin auto-update settles, before any MCP launches. Two viable options, in order of preference:

  1. Claude Code SessionStart hook (recommended). Register /usr/local/bin/patch-playwright-mcp as a SessionStart hook in the image-baked .claude/settings.json. Hooks fire on every session, so a freshly-auto-updated plugin cache gets patched before the user invokes a tool. Lowest blast radius; the existing postStartCommand entry can stay for defense-in-depth.

    Example shape (subject to Claude Code hook schema):

    {
      "hooks": {
        "SessionStart": [
          { "command": "/usr/local/bin/patch-playwright-mcp" }
        ]
      }
    }
  2. Wrap the MCP command in ~/.claude/settings.json (or the image-baked mcp_servers definition) so the playwright MCP launches as:

    bash -c '/usr/local/bin/patch-playwright-mcp >/dev/null && exec npx @playwright/mcp@latest …'
    

    Belt-and-suspenders: patches whatever Claude is about to read, every time. Marginally heavier on cold-start since the patch runs on every MCP boot.

Option 1 is the structurally cleaner answer because the patch only needs to happen once per session, not once per MCP launch.

Affected files in this repo (gatezh/devcontainers)

  • claude-code/scripts/patch-playwright-mcp (or wherever the script lives in the image build) — no change needed; the script itself is correct.
  • The image-baked .claude/settings.json — add the SessionStart hook entry.
  • claude-code/.devcontainer/*/devcontainer.json — the existing postStartCommand and init-plugins.sh wiring can stay for defense-in-depth.

Environment

  • Image: ghcr.io/gatezh/devcontainers/claude-code:latest (pull_policy: always)
  • OS: Debian GNU/Linux 13 (trixie)
  • chromium: 147.0.7727.137-1~deb13u1
  • PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium
  • @playwright/mcp cache dirs found at time of failure: 7, all unpatched until manual run

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions