Playwright MCP
# Playwright MCP
An MCP server that gives compatible clients structured control of a real Playwright browser for QA, scraping diagnostics, accessibility-minded inspection, and reproducible browser workflows.
## Architecture
Transport entrypoints are thin:
- `src/index.ts` starts MCP over stdio.
- `src/http.ts` starts MCP over Streamable HTTP.
- `src/server.ts` builds one `McpServer` and registers all tools.
Core services own browser state:
- `BrowserManager` serializes tool execution, launches browsers lazily, and manages contexts/pages.
- `TelemetryStore` captures console messages, page errors, failed requests, and recent network events.
- Tool modules register focused actions and depend only on the public browser/session APIs.
Tool groups:
- Browser/context/page lifecycle
- Navigation and waiting
- Interaction
- Inspection and screenshots
- Assertions
- Diagnostics, tracing, and storage
## Install
```bash
npm install
npm run install-browsers
npm run build
```
## Run
```bash
npm start
```
HTTP transport:
```bash
npm run start:http
```
Default HTTP endpoint: `http://127.0.0.1:8931/mcp`.
## Production Controls
Configuration is environment-driven:
- `PLAYWRIGHT_MCP_HTTP_TOKEN`: require `Authorization: Bearer <token>` for HTTP mode.
- `PLAYWRIGHT_MCP_HTTP_ALLOWED_ORIGINS`: comma-separated CORS allowlist.
- `PLAYWRIGHT_MCP_ALLOWED_ORIGINS`: comma-separated browser navigation allowlist.
- `PLAYWRIGHT_MCP_BLOCKED_ORIGINS`: comma-separated browser navigation blocklist.
- `PLAYWRIGHT_MCP_ALLOW_EVALUATE`: enable the dangerous `evaluate` tool. Default: `false`.
- `PLAYWRIGHT_MCP_ALLOW_DOWNLOADS`: enable download tools and accepting downloads. Default: `false`.
- `PLAYWRIGHT_MCP_ALLOW_UPLOADS`: enable upload tools. Default: `false`.
- `PLAYWRIGHT_MCP_ARTIFACT_DIR`: screenshots, traces, PDFs, downloads, and storage state directory. Default: `./artifacts`.
- `PLAYWRIGHT_MCP_MAX_CONTEXTS`: browser context cap. Default: `8`.
- `PLAYWRIGHT_MCP_MAX_PAGES`: page cap. Default: `32`.
- `PLAYWRIGHT_MCP_DEFAULT_TIMEOUT_MS`: default Playwright timeout. Default: `30000`.
- `PLAYWRIGHT_MCP_LOG_LEVEL`: `debug`, `info`, `warn`, or `error`.
HTTP mode should use `PLAYWRIGHT_MCP_HTTP_TOKEN` before binding to anything other than localhost.
## MCP client config
Examples are available in `examples/`:
- `claude_config.json`
- `cursor_mcp.json`
- `codex_config.toml`
- `cline_mcp_settings.json`
- `opencode_config.json`
## Development
```bash
npm run check
```
TDQS
Scored across 34 tools
Most tools have distinct purposes: lifecycle management (browser/context/page), interactions (click, fill, press), inspection (snapshot, element_info, telemetry), and artifact/network utilities. There is some potential overlap between snapshot, element_info, telemetry, evaluate, and assert, but the descriptions make the intended boundaries reasonably clear.
Everything uses snake_case, which is good, but conventions are mixed: noun_verb lifecycle names (browser_launch, page_new), bare action verbs (navigate, click), verb_noun actions (set_viewport, upload_files), and noun-only tools (pdf, storage_state). It remains readable, but an agent cannot fully predict the naming pattern.
34 tools is well above the comfortable range and feels heavy for a browser automation surface. While Playwright is feature-rich, several areas could be consolidated (e.g., storage_state/storage_state_save, trace_start/trace_stop, browser_launch versus implicit launch), making the set harder to navigate than necessary.
The surface covers the core browser automation lifecycle very broadly: launch/state/close, contexts, pages, navigation, interactions, waits, assertions, screenshots, PDFs, tracing, storage, uploads/downloads, and network mocking. Minor gaps remain around dialogs, iframes, drag-and-drop, forward history, and direct cookie/localStorage mutation, but evaluate can work around many of those.