playwright-multi-mcp
# playwright-multi-mcp
A **multi-browser automation, web auditing, and DevTools Model Context Protocol (MCP) server** built natively on Playwright and CDP.
`playwright-multi-mcp` lets AI agents launch, isolate, and **concurrently control multiple independent browser sessions** (separate browser processes/contexts, cookies, `localStorage`, proxies, viewports, browser engines, and optional persistent `userDataDir` profiles) while combining full-page interaction, performance & accessibility auditing, trace profiling, device/network emulation, and deep CSS & network inspection in a single unified `browser_*` toolset.
---
## Features
- **True Multi-Browser Session Management**:
- `browser_session_create`: Launch isolated `chromium`, `firefox`, or `webkit` instances with custom `sessionId`, `label`, `userDataDir`, `proxy`, `viewport`, `userAgent`, `locale`, `timezoneId`, `storageState`, `headless`/`headed`, and `initialUrl`.
- `browser_session_list`: Inspect all active sessions, engines, labels, tabs, and URLs.
- `browser_session_switch`: Change the default active session.
- `browser_session_close`: Close a specific session, the active session, or `all: true`.
- `browser_session_storage_state`: Export cookies & `localStorage` from a session (or save to disk) to inspect or clone auth state into another session.
- **Hybrid Session Targeting**:
- Every `browser_*` tool accepts an optional `sessionId`.
- Pass `sessionId` to operate on a specific browser directly (even concurrently across multiple sessions!).
- Omit `sessionId` to target the currently active session—or auto-launch a default session if none exist yet.
- **Structured Accessibility Snapshots (`[ref=eN]`)**:
- Uses Playwright accessibility snapshots with deterministic element refs (`e1`, `e2`, ...) so LLMs reason over structured UI trees instead of heavy pixel coordinates.
- **Full Core Toolset**:
- Navigation: `browser_navigate`, `browser_navigate_back`
- Interaction: `browser_click`, `browser_type`, `browser_fill_form`, `browser_select_option`, `browser_hover`, `browser_drag`, `browser_press_key`, `browser_file_upload`, `browser_handle_dialog`
- Inspection: `browser_snapshot`, `browser_take_screenshot`, `browser_console_messages`, `browser_network_requests`, `browser_network_details`, `browser_wait_for`, `browser_evaluate`, `browser_run_code`, `browser_css_styles`
- Tabs & Window: `browser_tabs`, `browser_resize`, `browser_close`
- **Web Auditing & Core Web Vitals**:
- `browser_audit`: Run Performance, Accessibility, Best Practices, and SEO audits (`mobile` / `desktop`, `navigation` / `snapshot`, optional Slow 4G + 4x CPU throttling) with Core Web Vitals, optimization opportunities, and failing DOM node selectors.
- `browser_performance_score`: Streamlined performance score (0–1), FCP, LCP, TBT, CLS, TTFB, and actionable optimization diagnostics.
- **DevTools Tracing, Emulation & Runtime Profiling**:
- `browser_trace_start` / `browser_trace_stop`: Record Chromium DevTools performance traces (`.json` / `.json.gz`), compute Core Web Vitals, Long Tasks, TBT, and main-thread breakdown.
- `browser_trace_insight`: Drill into `WebVitals`, `LongTasks`, `MainThreadBreakdown`, `LayoutShifts`, or `CdpMetrics` from the latest trace.
- `browser_performance_metrics`: Live JS heap usage, DOM node count, layout/style recalc counts, and paint timings without reloading.
- `browser_emulate`: Emulate network throttling (`Offline`, `Slow 3G`, `Fast 3G`, `Slow 4G`, `Fast 4G`), CPU slowdown, device viewport, user-agent, geolocation, media features (`colorScheme`, `reducedMotion`, `forcedColors`, `contrast`), and extra HTTP headers.
- **Dual Transports**:
- **Stdio** (default, for Claude Desktop, Cursor, Windsurf, Antigravity, VS Code)
- **Streamable HTTP** (`--port 8931`, with `/mcp` and `/health` endpoints)
---
## Installation
```bash
npm install -g playwright-multi-mcp
npx playwright install chromium
```
Or run directly without global installation using `npx -y playwright-multi-mcp` (ensure Playwright Chromium is installed via `npx playwright install chromium`).
*(Optional: run `npx playwright install firefox webkit` if you plan to launch Firefox or WebKit sessions.)*
---
## MCP Client Configuration
### Stdio (Claude Desktop / Cursor / Windsurf / Antigravity)
```json
{
"mcpServers": {
"playwright-multi": {
"command": "npx",
"args": [
"-y",
"playwright-multi-mcp"
]
}
}
}
```
Pass `--headed` in `args` if you want to watch multiple browser windows side-by-side:
```json
{
"mcpServers": {
"playwright-multi": {
"command": "npx",
"args": [
"-y",
"playwright-multi-mcp",
"--headed"
]
}
}
}
```
### Streamable HTTP Mode
```bash
npx -y playwright-multi-mcp --port 8931 --host 127.0.0.1
```
Connect your MCP client to `http://127.0.0.1:8931/mcp`.
---
## CLI Options
| Flag | Description | Default |
|---|---|---|
| `--browser <chromium\|firefox\|webkit>` | Default browser engine | `chromium` |
| `--channel <name>` | Browser channel (e.g. `chrome`, `msedge`) | unset |
| `--headed` | Show visible browser windows | `false` |
| `--headless` | Run browsers headlessly | `true` |
| `--viewport-size <WxH>` | Default viewport dimensions | `1280x720` |
| `--port <port>` | Start Streamable HTTP server on port | stdio |
| `--host <host>` | HTTP bind host | `127.0.0.1` |
| `--auth-token <token>` | Bearer token for HTTP transport (or `MCP_AUTH_TOKEN`) | unset |
| `--allowed-origins <list>` | Comma-separated allowed `Origin` headers for HTTP | same host/loopback |
| `--allowed-roots <dirs>` | Comma-separated allowed directories for file reads/writes | `cwd` + `tmpdir` |
| `--allow-any-path` | Disable path root confinement | `false` |
| `--allow-file-urls` | Allow `file://` URL navigation | `false` |
| `--block-private-networks` | Block RFC1918/loopback targets via DNS & route checks | `false` (stdio), `true` (non-loopback HTTP) |
| `--allow-run-code` | Enable `browser_run_code` in HTTP mode | `true` (stdio), `false` (HTTP) |
| `--disable-run-code` | Disable `browser_run_code` in all modes | `false` |
| `--max-sessions <n>` | Maximum concurrent browser sessions | `10` |
| `--max-tabs <n>` | Maximum open tabs per session | `20` |
| `--no-auto-snapshot` | Disable automatic snapshots after actions | `false` |
| `--snapshot-max-chars <n>` | Truncate snapshots above N characters | unlimited |
Set `LOG_FORMAT=json` and `LOG_LEVEL=debug|info|warn|error` to configure structured logging on `stderr`.
---
## Example Multi-Browser Agent Workflow
1. Create two isolated sessions:
- `browser_session_create({ sessionId: "admin", label: "Admin portal", initialUrl: "https://app.example.com/login" })`
- `browser_session_create({ sessionId: "buyer", label: "Buyer storefront", initialUrl: "https://app.example.com/shop", setActive: false })`
2. Target each session explicitly without losing state or cookies:
- `browser_type({ sessionId: "admin", ref: "e4", text: "admin@example.com" })`
- `browser_click({ sessionId: "buyer", ref: "e12" })`
3. Inspect all open sessions at any time:
- `browser_session_list()`
4. Clean up when finished:
- `browser_session_close({ all: true })`
---
## Development & Tests
```bash
npm run typecheck
npm run build
npm run test:build
```
TDQS
Scored across 35 tools
Core interaction tools (click, type, hover, drag, select_option) are distinct, but the performance/audit cluster overlaps heavily: browser_audit, browser_performance_score, browser_performance_metrics, browser_trace_start/stop/insight all measure page performance with subtly different scope. browser_close is explicitly an alias of browser_session_close, and browser_evaluate vs browser_run_code have fuzzy boundaries.
Nearly all tools use a snake_case browser_<verb>_<noun> pattern (browser_session_create, browser_navigate_back, browser_network_details). Minor deviations exist where the pattern collapses to a bare noun or verb (browser_tabs, browser_snapshot, browser_audit), but the prefix convention makes the set readable and predictable.
35 tools is heavy for the domain and includes clear redundancy: a legacy alias (browser_close), four performance-measurement tools, and three overlay-style tools that could be consolidated. Splitting session lifecycle, navigation, interaction, inspection, and performance into this many endpoints creates a large surface to triage.
Coverage is strong for browser automation: session lifecycle, storage state export, navigation, rich element interaction, file upload, dialogs, snapshots, console/network inspection, emulation, and performance tracing are all present. Minor gaps remain around cookie manipulation, request interception/mocking, downloads, and dedicated iframe handling, which could block some workflows.