Skip to content

Bake patch-playwright-mcp.sh into the image so consumer projects don't carry a copy #87

Closed

Description

@gatezh

Summary

#85 introduced patch-playwright-mcp.sh and made Playwright MCP usable in this image. As implemented, the script lives in claude-code/.devcontainer/, and consumer projects copy it verbatim into their own .devcontainer/. They then wire it into postCreateCommand (via init-plugins.sh) and postStartCommand.

That works, but it leaves a per-project copy of a script that has zero project-specific configuration. Every time the upstream script changes — different chromium flags, a new MCP CLI convention, a bug fix in the patch loop — every consumer project has to manually mirror the change. The daily image rebuild + pull_policy: always already exists as the upstream-update channel for everything else; this script should ride it too.

This image already does exactly that for rtk and ralphex: both are built (or downloaded) in parallel build stages and COPY-ed to /usr/local/bin/. The pattern is established. We just extend it to the patch script.

Why this matters

For a consumer project today, the per-project surface area for #85 is:

  1. .devcontainer/patch-playwright-mcp.sh — verbatim copy of the upstream file.
  2. .devcontainer/init-plugins.sh — calls the script via bash "$(dirname "$0")/patch-playwright-mcp.sh".
  3. .devcontainer/devcontainer.json postStartCommand — calls the script via bash /workspace/.devcontainer/patch-playwright-mcp.sh.
  4. (The sandbox variant under .devcontainer/claude-sandbox/devcontainer.json repeats Create GitHub Action for multiplatform builds #3.)

Items 2–4 each have to invoke the script (and that doesn't go away). Item 1 is the part that doesn't need to be per-project. Removing it cuts one file from every consumer's .devcontainer/ and removes the only thing in that surface area that has to be kept in sync with upstream by hand.

Proposed change

Three small diffs.

1. claude-code/.devcontainer/Dockerfile

In the FROM ... AS base stage (so both default and sandbox targets inherit), add right after the existing system-package install — alongside the existing COPY --from=rtk-download / COPY --from=ralphex-download lines or just before them, doesn't matter:

COPY .devcontainer/patch-playwright-mcp.sh /usr/local/bin/patch-playwright-mcp
RUN chmod 0755 /usr/local/bin/patch-playwright-mcp

Placing it in base rather than per-target is the right call: both targets already install chromium per #85, so both need the patch script. The script's own early-exit (if [ ! -x /usr/bin/chromium ]; then exit 0; fi) means it stays safe in any future image variant that omits chromium — calling it is always free.

2. claude-code/.devcontainer/init-plugins.sh

Replace the current invocation:

bash "$(dirname "$0")/patch-playwright-mcp.sh"

with the image path:

/usr/local/bin/patch-playwright-mcp

The script-relative path resolution ($(dirname "$0")) stops being needed: the script's location is now image-stable, not relative to init-plugins.sh.

3. claude-code/.devcontainer/patch-playwright-mcp.sh

Keep the file in the source tree unchanged. The Dockerfile COPY reads from there, so this remains the build-time source of truth. Nothing else needs to change.

4. claude-code/README.md — consumer setup guidance

The "Essential Setup for Consumer Projects" section currently lists patch-playwright-mcp.sh as one of the files projects copy from this template. Drop that line. Update the lifecycle commands snippet:

"postCreateCommand": "bash .devcontainer/init-plugins.sh",
"postStartCommand": "/usr/local/bin/patch-playwright-mcp",
"updateContentCommand": "mise install && bun install && sudo find /workspace -type d -name node_modules -exec chown -R node:node {} \\;"

Add a short note explaining why init-plugins.sh stays per-project but patch-playwright-mcp doesn't: init-plugins.sh carries project-specific marketplace and plugin lists; the patch script carries no project-specific config. That's the boundary — project-specific config stays per-project; universal logic moves into the image.

Trade-offs / alternatives I considered

Verification plan

  1. Build both targets:
    docker build --target default -t claude-code:default .
    docker build --target sandbox -t claude-code:sandbox .
  2. In each, confirm the script lands at the expected path and is executable:
    docker run --rm claude-code:default ls -la /usr/local/bin/patch-playwright-mcp
    docker run --rm claude-code:sandbox ls -la /usr/local/bin/patch-playwright-mcp
  3. In each, confirm the script runs and exits cleanly when there's no ~/.claude/plugins/cache to patch (the no-op path):
    docker run --rm claude-code:default /usr/local/bin/patch-playwright-mcp
    Expected: exit code 0, no output (the find finds nothing).
  4. In a consumer project with .devcontainer/patch-playwright-mcp.sh deleted, init-plugins.sh updated to call /usr/local/bin/patch-playwright-mcp, and both devcontainer.json files updated to invoke the same path from postStartCommand: rebuild the devcontainer, then confirm the cached .mcp.json files under ~/.claude/plugins/cache/claude-plugins-official/playwright/*/ are patched with the upstream args ("command": "npx", args including --browser chromium --executable-path /usr/bin/chromium --no-sandbox --headless).
  5. Restart Claude Code and confirm mcp__plugin_playwright_playwright__browser_navigate to about:blank succeeds.

Migration impact for consumer projects

Once this lands, consumer projects pulling the new image need the following one-time changes:

  • Delete .devcontainer/patch-playwright-mcp.sh.
  • In .devcontainer/init-plugins.sh, change the playwright block from bash "$(dirname "$0")/patch-playwright-mcp.sh" to /usr/local/bin/patch-playwright-mcp.
  • In every devcontainer.json postStartCommand that calls the script, change bash /workspace/.devcontainer/patch-playwright-mcp.sh to /usr/local/bin/patch-playwright-mcp. (A project with both default and sandbox variants needs the change in both.)

After that one-time migration, future upstream changes to the patch logic (chromium flag tweaks, MCP arg adjustments, bug fixes in the loop) flow automatically on the next docker compose pull. No manual mirror, no per-project sync.

Why now

This closes the loop #85 opened. #85 was scoped to "make Playwright MCP work at all"; this issue is the small refinement that takes per-project surface area from "one file + invocations" down to just "invocations". Same shape as rtk and ralphex already have. A four-line Dockerfile diff and a one-line init-plugins.sh diff.

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