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" +