diff --git a/.codex/config.toml b/.codex/config.toml index 721334d6..cf37954d 100644 --- a/.codex/config.toml +++ b/.codex/config.toml @@ -23,8 +23,8 @@ log_file = "~/.codex/logs/codex.log" # Note: Codex uses 'mcp_servers' (underscore) not 'mcpServers' (camelCase) [mcp_servers.playwright] -command = "npx" -args = ["@playwright/mcp@latest"] +command = "patchright-playwright-mcp" +args = [] env = { FASTMCP_LOG_LEVEL = "ERROR" } # Additional MCP servers can be added here 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-playwright-mcp.sh b/mcp/patchright-playwright-mcp.sh new file mode 100755 index 00000000..38dd277b --- /dev/null +++ b/mcp/patchright-playwright-mcp.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Wrapper to launch Playwright MCP through Patchright by default. +# +# Behavior: +# - Default enables Patchright shim by setting NODE_PATH to the shim dir +# - Opt-out by setting USE_PATCHRIGHT=0 or USE_PATCHRIGHT=false +# - Optional debug: USE_PATCHRIGHT_DEBUG=1 prints shim activation to stderr +# - Override underlying command with PLAYWRIGHT_MCP_CMD if needed + +# Resolve repository-local paths dynamically (no hardcoded absolute paths) +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -P)" +SHIM_NODE_MODULES="$SCRIPT_DIR/patchright-shim/node_modules" + +USE_PATCHRIGHT="${USE_PATCHRIGHT:-1}" +if [[ "${USE_PATCHRIGHT}" != "0" && "${USE_PATCHRIGHT,,}" != "false" ]]; then + export NODE_PATH="${SHIM_NODE_MODULES}${NODE_PATH+:$NODE_PATH}" + export USE_PATCHRIGHT_DEBUG="${USE_PATCHRIGHT_DEBUG:-0}" +fi + +CMD="${PLAYWRIGHT_MCP_CMD:-npx}" + +if [[ "$CMD" == "npx" ]]; then + exec npx "@playwright/mcp@latest" "$@" +else + exec "$CMD" "$@" +fi 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..f4213d26 --- /dev/null +++ b/mcp/patchright-shim/node_modules/playwright/index.js @@ -0,0 +1,17 @@ +'use strict'; + +// Patchright shim for Playwright +// When NODE_PATH includes this directory, any require('playwright') +// will resolve to Patchright instead, enabling undetectable Chromium. + +if (process.env.USE_PATCHRIGHT_DEBUG === '1') { + try { + // eslint-disable-next-line no-console + console.error('[patchright-shim] Replacing require("playwright") with Patchright'); + } catch (_) { + // ignore if console unavailable in host + } +} + +module.exports = require('patchright'); + diff --git a/mcp/setup-all-mcp-servers.sh b/mcp/setup-all-mcp-servers.sh index f9460f14..ac14fc6e 100755 --- a/mcp/setup-all-mcp-servers.sh +++ b/mcp/setup-all-mcp-servers.sh @@ -58,6 +58,15 @@ done # Create servers directory if it doesn't exist mkdir -p "$MCP_DIR/servers" +# Ensure patchright-playwright-mcp is available on PATH for portability +WRAPPER_SRC="$MCP_DIR/patchright-playwright-mcp.sh" +DEST_DIR="${HOME}/.local/bin" +DEST_LINK="${DEST_DIR}/patchright-playwright-mcp" +mkdir -p "${DEST_DIR}" +if [ ! -e "${DEST_LINK}" ]; then + ln -s "${WRAPPER_SRC}" "${DEST_LINK}" || true +fi + # Summary echo -e "\n${GREEN}MCP Server Setup Summary:${NC}" echo "- Working directory: $REPO_ROOT" @@ -88,4 +97,4 @@ for binary in "${binaries[@]}"; do else echo -e " ${RED}✗ $binary${NC}" fi -done \ No newline at end of file +done