The Playwright MCP connects to a headless Chrome running in a separate Docker container (chrome) via CDP. Configuration is in .mcp.json. Example:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--cdp-endpoint", "http://<CHROME_DOCKER_IP>:9222"]
}
}
}
- The app runs inside the
appcontainer, Chrome runs in thechromecontainer. - Do not use
localhostor theapphostname to navigate — Chrome cannot resolve them properly. - Chrome CDP rejects non-IP Host headers — Chromium hardcodes a check that the HTTP
Hostheader is an IP orlocalhost. There is no flag to disable this. Always use resolved IPs (not hostnames) in CDP endpoint URLs. - Resolve container IPs first with
getent hosts <container>, then use the IP:
getent hosts app # for navigation URLs
getent hosts chrome # for CDP endpoint in .mcp.json- Start the dev server:
pnpm run dev(run in background) - Wait for the server to be ready:
curl -s -o /dev/null -w "%{http_code}" http://localhost:4200 - Resolve the app IP:
getent hosts app - Navigate with Playwright:
browser_navigatetohttp://<resolved-ip>:4200 - Use
browser_snapshot(preferred over screenshots) to inspect the page