fix(mcp): add retry logic for Playwright MCP browser sidecar startup#126
Merged
skulidropek merged 4 commits intoProverCoderAI:mainfrom Mar 12, 2026
Merged
Conversation
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>
This reverts commit ba2753d.
Contributor
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
Contributor
Author
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #123 — "Почему MCP сервер лежит с ошибкой?"
Root Cause
When Claude Code initializes MCP servers at startup, it runs the
docker-git-playwright-mcpwrapper command. This wrapper connects to the browser sidecar container via CDP (Chrome DevTools Protocol) athttp://dg-<repo>-browser:9223. If the browser container is not fully initialized yet, the curl command fails immediately (withset -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-mcpwrapper script:MCP_PLAYWRIGHT_RETRY_ATTEMPTS)MCP_PLAYWRIGHT_RETRY_DELAY)waiting for browser sidecar (attempt N/M)...)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 todocker-git-playwright-mcpwrapperpackages/app/src/docker-git/cli/usage.ts: Document new environment variablespackages/lib/tests/usecases/mcp-playwright.test.ts: Add test assertions for retry logicConfiguration
New environment variables (set via
.orch/env/project.envor docker-compose environment):MCP_PLAYWRIGHT_RETRY_ATTEMPTSMCP_PLAYWRIGHT_RETRY_DELAYTest plan
pnpm test)pnpm run check)--mcp-playwrightand verify MCP server connects after browser sidecar startupMathematical guarantees
Invariant
∀t ∈ [1..max_attempts]: retry(t) → eventually(cdp_ready) ∨ timeout_errorComplexity
O(max_attempts × timeout_per_attempt)= O(10 × 12s) = O(120s) worst caseThis PR was created automatically by the AI issue solver