From 7bbde8c42a6adcb3cd827543deae36e765ba88c9 Mon Sep 17 00:00:00 2001 From: Morgan Joyce Date: Tue, 2 Sep 2025 17:05:02 -0500 Subject: [PATCH] feat(mcp): default Patchright backend for Playwright MCP\n\n- Add shim so require('playwright') resolves to Patchright\n- Add wrapper 'patchright-playwright-mcp' to set NODE_PATH and run @playwright/mcp\n- Point mcp/mcp.json Playwright server to the wrapper\n- Provide setup script to install Patchright locally\n\nCloses #1263 --- mcp/mcp.json | 8 +++----- .../node_modules/playwright/index.js | 4 ++++ mcp/servers/patchright-playwright-mcp | 19 +++++++++++++++++++ mcp/setup-patchright-shim.sh | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 mcp/patchright-shim/node_modules/playwright/index.js create mode 100755 mcp/servers/patchright-playwright-mcp create mode 100755 mcp/setup-patchright-shim.sh diff --git a/mcp/mcp.json b/mcp/mcp.json index 42bea156..e7f26f54 100644 --- a/mcp/mcp.json +++ b/mcp/mcp.json @@ -1,13 +1,11 @@ { "mcpServers": { "playwright": { - "command": "npx", - "args": [ - "@playwright/mcp@latest" - ], + "command": "patchright-playwright-mcp", + "args": [], "env": { "FASTMCP_LOG_LEVEL": "ERROR" } } } -} \ No newline at end of file +} diff --git a/mcp/patchright-shim/node_modules/playwright/index.js b/mcp/patchright-shim/node_modules/playwright/index.js new file mode 100644 index 00000000..7e492c41 --- /dev/null +++ b/mcp/patchright-shim/node_modules/playwright/index.js @@ -0,0 +1,4 @@ +// Patchright shim for Playwright +// Resolves require('playwright') to Patchright at runtime. +module.exports = require('patchright'); + diff --git a/mcp/servers/patchright-playwright-mcp b/mcp/servers/patchright-playwright-mcp new file mode 100755 index 00000000..a56eafde --- /dev/null +++ b/mcp/servers/patchright-playwright-mcp @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Wrapper to run @playwright/mcp with Patchright as the default backend. +# Opt out by setting USE_PATCHRIGHT=0 or USE_PATCHRIGHT=false + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# mcp/servers -> repo root is ../.. +DOT_DEN="$(cd "$SCRIPT_DIR/../.." && pwd)" + +USE_PATCHRIGHT_VAL="${USE_PATCHRIGHT:-1}" +if [[ "$USE_PATCHRIGHT_VAL" != "0" && "$USE_PATCHRIGHT_VAL" != "false" ]]; then + # Prepend shim node_modules so require('playwright') resolves to Patchright + export NODE_PATH="${DOT_DEN}/mcp/patchright-shim/node_modules${NODE_PATH:+:$NODE_PATH}" +fi + +# Execute the community Playwright MCP server +exec npx @playwright/mcp@latest "$@" + diff --git a/mcp/setup-patchright-shim.sh b/mcp/setup-patchright-shim.sh new file mode 100755 index 00000000..21fba4f5 --- /dev/null +++ b/mcp/setup-patchright-shim.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Install Patchright into the local shim so Playwright resolves to Patchright + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SHIM_DIR="$SCRIPT_DIR/patchright-shim" + +mkdir -p "$SHIM_DIR" + +if [[ ! -f "$SHIM_DIR/package.json" ]]; then + (cd "$SHIM_DIR" && npm init -y >/dev/null 2>&1) +fi + +echo "Installing patchright into $SHIM_DIR ..." +(cd "$SHIM_DIR" && npm install patchright --silent) + +echo "Patchright shim ready. Optional: download Chromium once with:\n npx patchright install chromium" +