@@ -105,8 +105,39 @@ if [[ -z "$CDP_ENDPOINT" ]]; then
105105 CDP_ENDPOINT="http://__SERVICE_NAME__-browser:9223"
106106fi
107107
108+ # CHANGE: add retry logic for browser sidecar startup wait
109+ # WHY: the browser container may take time to initialize, causing MCP server to fail on first attempt
110+ # QUOTE(issue-123): "Почему MCP сервер лежит с ошибкой?"
111+ # REF: issue-123
112+ # SOURCE: n/a
113+ # FORMAT THEOREM: forall t in [1..max_attempts]: retry(t) -> eventually(cdp_ready) OR timeout_error
114+ # PURITY: SHELL
115+ # INVARIANT: script exits only after cdp_ready OR all retries exhausted
116+ # COMPLEXITY: O(max_attempts * timeout_per_attempt)
117+ MCP_PLAYWRIGHT_RETRY_ATTEMPTS="\${MCP_PLAYWRIGHT_RETRY_ATTEMPTS:-10}"
118+ MCP_PLAYWRIGHT_RETRY_DELAY="\${MCP_PLAYWRIGHT_RETRY_DELAY:-2}"
119+
120+ fetch_cdp_version() {
121+ curl -sSf --connect-timeout 3 --max-time 10 -H 'Host: 127.0.0.1:9222' "\${CDP_ENDPOINT%/}/json/version" 2>/dev/null
122+ }
123+
124+ JSON=""
125+ for attempt in $(seq 1 "$MCP_PLAYWRIGHT_RETRY_ATTEMPTS"); do
126+ if JSON="$(fetch_cdp_version)"; then
127+ break
128+ fi
129+ if [[ "$attempt" -lt "$MCP_PLAYWRIGHT_RETRY_ATTEMPTS" ]]; then
130+ echo "docker-git-playwright-mcp: waiting for browser sidecar (attempt $attempt/$MCP_PLAYWRIGHT_RETRY_ATTEMPTS)..." >&2
131+ sleep "$MCP_PLAYWRIGHT_RETRY_DELAY"
132+ fi
133+ done
134+
135+ if [[ -z "$JSON" ]]; then
136+ echo "docker-git-playwright-mcp: failed to connect to CDP endpoint $CDP_ENDPOINT after $MCP_PLAYWRIGHT_RETRY_ATTEMPTS attempts" >&2
137+ exit 1
138+ fi
139+
108140# kechangdev/browser-vnc binds Chromium CDP on 127.0.0.1:9222; it also host-checks HTTP requests.
109- JSON="$(curl -sSf --connect-timeout 3 --max-time 10 -H 'Host: 127.0.0.1:9222' "\${CDP_ENDPOINT%/}/json/version")"
110141WS_URL="$(printf "%s" "$JSON" | node -e 'const fs=require("fs"); const j=JSON.parse(fs.readFileSync(0,"utf8")); process.stdout.write(j.webSocketDebuggerUrl || "")')"
111142if [[ -z "$WS_URL" ]]; then
112143 echo "docker-git-playwright-mcp: webSocketDebuggerUrl missing" >&2
0 commit comments