Skip to content

fix(mcp): add retry logic for Playwright MCP browser sidecar startup#126

Merged
skulidropek merged 4 commits intoProverCoderAI:mainfrom
konard:issue-123-a5ba76ddd9e9
Mar 12, 2026
Merged

fix(mcp): add retry logic for Playwright MCP browser sidecar startup#126
skulidropek merged 4 commits intoProverCoderAI:mainfrom
konard:issue-123-a5ba76ddd9e9

Conversation

@konard
Copy link
Copy Markdown
Contributor

@konard konard commented Mar 12, 2026

Summary

Fixes #123 — "Почему MCP сервер лежит с ошибкой?"

Root Cause

When Claude Code initializes MCP servers at startup, it runs the docker-git-playwright-mcp wrapper command. This wrapper connects to the browser sidecar container via CDP (Chrome DevTools Protocol) at http://dg-<repo>-browser:9223. If the browser container is not fully initialized yet, the curl command fails immediately (with set -euo pipefail), and the MCP server shows as "failed" in Claude Code's server management screen.

Solution

Add a configurable retry mechanism to the docker-git-playwright-mcp wrapper script:

  • 10 retry attempts by default (configurable via MCP_PLAYWRIGHT_RETRY_ATTEMPTS)
  • 2 second delay between attempts (configurable via MCP_PLAYWRIGHT_RETRY_DELAY)
  • Progress logging to stderr for debugging (waiting for browser sidecar (attempt N/M)...)
  • Clear error message if all retries are exhausted

This gives the browser sidecar up to ~20 seconds to become available, which should be sufficient for most startup scenarios.

Changes

  • packages/lib/src/core/templates/dockerfile.ts: Add retry loop to docker-git-playwright-mcp wrapper
  • packages/app/src/docker-git/cli/usage.ts: Document new environment variables
  • packages/lib/tests/usecases/mcp-playwright.test.ts: Add test assertions for retry logic

Configuration

New environment variables (set via .orch/env/project.env or docker-compose environment):

Variable Default Description
MCP_PLAYWRIGHT_RETRY_ATTEMPTS 10 Number of retry attempts
MCP_PLAYWRIGHT_RETRY_DELAY 2 Delay in seconds between attempts

Test plan

  • All existing tests pass (pnpm test)
  • Type checking passes (pnpm run check)
  • New test verifies retry logic is present in generated Dockerfile
  • Manual test: Start docker-git project with --mcp-playwright and verify MCP server connects after browser sidecar startup

Mathematical guarantees

Invariant

  • ∀t ∈ [1..max_attempts]: retry(t) → eventually(cdp_ready) ∨ timeout_error

Complexity

  • Time: O(max_attempts × timeout_per_attempt) = O(10 × 12s) = O(120s) worst case
  • Space: O(1) — no additional memory allocation in retry loop

This PR was created automatically by the AI issue solver

konard and others added 2 commits March 12, 2026 11:38
Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: ProverCoderAI#123
Add retry mechanism to docker-git-playwright-mcp wrapper to handle
browser sidecar startup delays. When Claude Code initializes the
MCP server, the browser container may not be ready yet, causing
the server to fail with connection errors.

- Add configurable retry attempts (MCP_PLAYWRIGHT_RETRY_ATTEMPTS, default: 10)
- Add configurable retry delay (MCP_PLAYWRIGHT_RETRY_DELAY, default: 2s)
- Extract CDP fetch into a function for cleaner retry loop
- Log retry progress to stderr for debugging
- Update usage documentation with new environment variables
- Add tests verifying retry logic in Dockerfile template

Fixes ProverCoderAI#123

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] Почему MCP сервер лежит с ошибкой? fix(mcp): add retry logic for Playwright MCP browser sidecar startup Mar 12, 2026
@konard konard marked this pull request as ready for review March 12, 2026 11:45
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 12, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $4.481058
  • Calculated by Anthropic: $2.784324 USD
  • Difference: $-1.696734 (-37.86%)
    📎 Log file uploaded as Gist (1455KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 12, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@skulidropek skulidropek merged commit daeff40 into ProverCoderAI:main Mar 12, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Почему MCP сервер лежит с ошибкой?

2 participants