Skip to main content
Glama
playwright-mcp-router

playwright-mcp-router

by huangzt

playwright-mcp-router

Session-isolated, multi-account MCP router for @playwright/mcp — let multiple AI agents share your logged-in Chrome profiles concurrently without hijacking each other's active tab, with meaningful per-task Chrome tab group names.

简体中文


Why This Exists

When using @playwright/mcp --extension in multi-session AI IDEs / coding agents (Antigravity, Claude Code, Cursor, Codex, etc.):

  1. Most MCP hosts spawn one shared singleton MCP server process across all concurrent conversations.

  2. @playwright/mcp tools (browser_navigate, browser_click, browser_snapshot, browser_network_requests, ...) operate on a single current active tab pointer — so two concurrent agents inevitably hijack each other's active tab.

  3. --session-name (the Chrome tab group label) is fixed at server startup, so you cannot dynamically name tab groups per task.

  4. Switching across multiple Chrome accounts/profiles requires duplicating MCP servers (playwright-1a, playwright-1b, playwright-2, ...).

playwright-mcp-router solves all four problems with a zero-dependency Node.js proxy:

flowchart LR
  A1["Agent 1 (session: T1867-api)"] --> R["playwright-mcp-router (Single MCP)"]
  A2["Agent 2 (session: home-css)"] --> R
  A3["Agent 3 (account: 2, session: rbac)"] --> R

  R -->|"account=1 / T1867-api"| W1["@playwright/mcp worker #1"]
  R -->|"account=1 / home-css"| W2["@playwright/mcp worker #2"]
  R -->|"account=2 / rbac"| W3["@playwright/mcp worker #3"]

  W1 -->|"Chrome Default (Tab Group: T1867-api)"| C1["Chrome Profile: Default"]
  W2 -->|"Chrome Default (Tab Group: home-css)"| C1
  W3 -->|"Chrome Profile 1 (Tab Group: rbac)"| C2["Chrome Profile: Profile 1"]

Related MCP server: agent-tab-bridge

Features

  • Zero Runtime Dependencies: Pure Node.js (>= 20) ESM, instant startup.

  • True Process-Level Session Isolation: Every (account, session) pair gets its own @playwright/mcp worker process and Chrome tab group — concurrent agents never steal focus or overwrite each other's active tab.

  • Dynamic Meaningful Tab Group Names: Injects a required session parameter into all proxied Playwright tools so every agent creates a clearly labeled, color-coded Chrome tab group (e.g. T1867-api-debug, checkout-css).

  • Multi-Account Chrome Profile Routing: Configure multiple Chrome profiles (Default, Profile 1, ...) and Playwright MCP Bridge tokens in one place, with a default primary account and on-demand switching via account.

  • Automatic Lifecycle & Cleanup:

    • Coalesces concurrent in-flight startup calls for the same session.

    • Auto-evicts idle sessions after idleTimeoutMs (default 15 minutes), cleanly closing their Chrome tab groups.

    • Evicts the worker immediately when browser_close or router_close_session is called.

    • Enforces maxSessions cap and auto-recovers if a worker crashes.

  • Always Up-to-Date with Official @playwright/mcp: Dynamically discovers and forwards the exact tool catalog from your installed @playwright/mcp binary (including browser_network_requests, browser_network_request, browser_evaluate, browser_take_screenshot, etc.).

  • Secret Safe: Never exposes tokens in router_list_sessions or redacts accidental leaks from upstream error messages.


Prerequisites

  1. Node.js >= 20

  2. Official @playwright/mcp installed globally (recommended for fast startup):

    npm install -g @playwright/mcp@latest
  3. (For reusing logged-in Chrome sessions) Install the Playwright MCP Bridge Chrome extension in each Chrome profile you want to automate, and copy each profile's PLAYWRIGHT_MCP_EXTENSION_TOKEN.


Setup

1. Clone the repository

git clone https://github.com/huangzt/playwright-mcp-router.git

2. Create your private accounts.json

Store it outside the repository (default path ~/.config/playwright-mcp-router/accounts.json, chmod 600):

mkdir -p ~/.config/playwright-mcp-router
cp accounts.example.json ~/.config/playwright-mcp-router/accounts.json
chmod 600 ~/.config/playwright-mcp-router/accounts.json

Example ~/.config/playwright-mcp-router/accounts.json:

{
  "defaultAccount": "1",
  "idleTimeoutMs": 900000,
  "maxSessions": 12,
  "playwrightArgs": [
    "--extension",
    "--background",
    "--caps=devtools"
  ],
  "accounts": {
    "1": {
      "label": "Work Account (Chrome Default)",
      "profileDirName": "Default",
      "token": "YOUR_ACCOUNT_1_EXTENSION_TOKEN",
      "colors": ["blue", "cyan", "purple"]
    },
    "2": {
      "label": "Secondary Account (Chrome Profile 1)",
      "profileDirName": "Profile 1",
      "token": "YOUR_ACCOUNT_2_EXTENSION_TOKEN",
      "colors": ["green", "orange", "yellow"]
    }
  }
}

Tip: token also supports ${ENV_VAR} interpolation if you prefer keeping tokens in environment variables. To find your exact Chrome profileDirName (Default, Profile 1, etc.), inspect ~/Library/Application Support/Google/Chrome/Local State (macOS) or Chrome's chrome://version ("Profile Path").

3. Register in your MCP client (mcp_config.json)

{
  "mcpServers": {
    "playwright": {
      "command": "/path/to/node",
      "args": [
        "/path/to/playwright-mcp-router/bin/playwright-mcp-router.js",
        "--config",
        "/Users/<you>/.config/playwright-mcp-router/accounts.json",
        "--playwright-bin",
        "/path/to/node_modules/@playwright/mcp/cli.js"
      ]
    }
  }
}

Router Tools & Parameters

Every official @playwright/mcp tool is automatically augmented with:

Parameter

Required

Description

session

Yes

Unique, descriptive task name (also shown as the Chrome tab group title, e.g. T1867-api-debug).

account

No

Account key from accounts.json (defaults to defaultAccount).

color

No

Optional Chrome tab group color override (blue, red, yellow, green, pink, purple, cyan, orange).

Additional management tools provided by the router:

  • router_list_sessions — List active isolated sessions (account, session name, color, PID, idle time) and configured accounts (without tokens).

  • router_close_session — Gracefully close a specific (account, session) and remove its Chrome tab group.

  • router_close_all_sessions — Gracefully close all active sessions.


Testing

Run unit & mock concurrency tests (no browser required):

npm test

Run live concurrency test against your real Chrome profiles:

npm run test:live

License

MIT

Available Tools

41 tools
browser_annotateA
Read-only

Open the Playwright Dashboard in annotation mode for the current page and wait for the user to draw annotations. Returns the annotated screenshot, ARIA snapshot, and the list of annotations.

Inputs: session (required), color, account.

browser_clickC
Destructive

Perform click on a web page

Inputs: target (required), session (required), color, button, +4 more.

browser_closeB
Destructive

Close the browser and all open tabs.

Inputs: session (required), color, account.

browser_console_messagesC
Read-only

Returns all console messages

Inputs: level (required), session (required), all, color, +2 more.

browser_dragC
Destructive

Perform drag and drop between two elements

Inputs: session (required), endTarget (required), startTarget (required), color, +3 more.

browser_dropA
Destructive

Drop files or MIME-typed data onto an element, as if dragged from outside the page. At least one of "paths" or "data" must be provided.

Inputs: target (required), session (required), data, color, +3 more.

browser_emulate_mediaA
Destructive

Emulate CSS media features for the page, for example switch between the light and dark color scheme. Omitted parameters are left unchanged; null clears an override.

Inputs: session (required), color, media, account, +4 more.

browser_evaluateC
Destructive

Evaluate JavaScript expression on page or element

Inputs: session (required), function (required), color, target, +3 more.

browser_file_uploadC
Destructive

Upload one or multiple files

Inputs: session (required), color, paths, account.

browser_fill_formC
Destructive

Fill multiple form fields

Inputs: fields (required), session (required), color, account.

browser_findA
Read-only

Search the accessibility snapshot of the current page for text or a regular expression. Returns matching snapshot nodes with a few lines of surrounding context (like search snippets), each shown under its path from the root of the tree, which is cheaper than capturing the whole snapshot when you only need to locate an element and its ref.

Inputs: session (required), text, color, regex, +3 more.

browser_handle_dialogD
Destructive

Handle a dialog

Inputs: accept (required), session (required), color, account, +1 more.

browser_hide_highlightA
Read-only

Remove a highlight overlay previously added for the element.

Inputs: session (required), color, target, account, +1 more.

browser_highlightB
Read-only

Show a persistent highlight overlay around the element on the page.

Inputs: target (required), session (required), color, style, +2 more.

browser_hoverC
Destructive

Hover over element on page

Inputs: target (required), session (required), color, account, +1 more.

browser_navigateC
Destructive

Navigate to a URL

Inputs: url (required), session (required), color, account.

browser_navigate_backC
Destructive

Go back to the previous page in the history

Inputs: session (required), color, account.

browser_network_requestA
Read-only

Returns full details (headers and body) of a single network request, or a single part if part is set. Use the number from browser_network_requests.

Inputs: index (required), session (required), part, color, +2 more.

browser_network_requestsA
Read-only

Returns a numbered list of network requests since loading the page. Use browser_network_request with the number to get full details.

Inputs: static (required), session (required), all, color, +3 more.

browser_press_keyC
Destructive

Press a key on the keyboard

Inputs: key (required), session (required), color, account.

browser_resizeC
Destructive

Resize the browser window

Inputs: width (required), height (required), session (required), color, +1 more.

browser_resumeB
Destructive

Resume script execution after it was paused. When called with step set to true, execution will pause again before the next action.

Inputs: session (required), step, color, account, +1 more.

browser_run_code_unsafeB
Destructive

Run a Playwright code snippet. Unsafe: executes arbitrary JavaScript in the Playwright server process and is RCE-equivalent.

Inputs: session (required), code, color, account, +1 more.

browser_select_optionC
Destructive

Select an option in a dropdown

Inputs: target (required), values (required), session (required), color, +2 more.

browser_snapshotB
Read-only

Capture accessibility snapshot of the current page, this is better than screenshot

Inputs: session (required), boxes, color, depth, +3 more.

browser_start_recordingA
Read-only

Start recording actions that the user performs in the browser as Playwright code. Use it when the user wants to demonstrate a flow manually. Call browser_stop_recording when the user says they are done to retrieve the recorded actions.

Inputs: session (required), color, account.

browser_start_tracingC
Read-only

Start trace recording

Inputs: session (required), color, account.

browser_start_videoC
Read-only

Start video recording

Inputs: session (required), fps, size, color, +3 more.

browser_stop_recordingA
Read-only

Stop the recording started with browser_start_recording and return the recorded actions as Playwright code.

Inputs: session (required), color, account.

browser_stop_tracingC
Read-only

Stop trace recording

Inputs: session (required), color, account.

browser_stop_videoC
Read-only

Stop video recording

Inputs: session (required), color, account.

browser_tabsC
Destructive

List, create, close, or select a browser tab.

Inputs: action (required), session (required), url, color, +3 more.

browser_take_screenshotA
Read-only

Take a screenshot of the current page. Use browser_snapshot for actions by default. With the vision capability enabled, use screenshot coordinates with the coordinate-based mouse tools for elements not exposed in the accessibility snapshot.

Inputs: scale (required), session (required), type, color, +5 more.

browser_typeC
Destructive

Type text into editable element

Inputs: text (required), target (required), session (required), color, +4 more.

browser_video_chapterB
Read-only

Add a chapter marker to the video recording. Shows a full-screen chapter card with blurred backdrop.

Inputs: title (required), session (required), color, account, +2 more.

browser_video_hide_actionsB
Read-only

Stop annotating actions performed on the page.

Inputs: session (required), color, account.

browser_video_show_actionsA
Read-only

Annotate subsequent actions performed on the page with a callout that names the action and, when styled, marks the action point and highlights the target element. Useful while video recording or screencasting.

Inputs: session (required), color, style, cursor, +3 more.

browser_wait_forB
Read-only

Wait for text to appear or disappear or a specified time to pass. When both text and textGone are provided, waits for the first one to happen

Inputs: session (required), text, time, color, +2 more.

router_close_all_sessionsB

Gracefully close all active browser sessions managed by playwright-mcp-router.

Inputs: no named parameters.

router_close_sessionA

Gracefully close a specific isolated browser session (closes its Chrome tab group and terminates its worker process). Always close your session when finished.

Inputs: session (required), account.

router_list_sessionsB

List all active isolated browser sessions managed by playwright-mcp-router, along with configured Chrome accounts (without exposing secrets).

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.9/5.0

    Scored across 41 tools

    Disambiguation3/5

    Core interaction tools (click, type, hover, drag, select_option, press_key) are clearly distinct, but several clusters overlap: browser_network_request vs browser_network_requests differ only by plurality, browser_start_recording / browser_start_tracing / browser_start_video are three near-identical 'start recording' verbs, and router_close_session / router_close_all_sessions / browser_close have unclear boundaries about what gets terminated. browser_evaluate vs browser_run_code_unsafe and browser_highlight vs browser_video_show_actions also require reading the full description to separate.

    Naming Consistency4/5

    A predictable prefix scheme (browser_* for page actions, router_* for session management) is applied uniformly across all 41 tools. Within that scheme the ordering drifts between verb-first (browser_take_screenshot) and noun-first (browser_console_messages, browser_snapshot, browser_tabs), and the singular/plural pair browser_network_request(s) is easy to misread, but nothing is chaotic.

    Tool Count3/5

    41 tools is heavy even for full browser automation, and a meaningful slice of the surface is niche instrumentation rather than core capability (video_chapter, video_show_actions/hide_actions, start/stop_tracing, start/stop_recording, annotate, highlight/hide_highlight, emulate_media). Each earns some place, but the count trends toward over-specialization rather than a tight, well-scoped set.

    Completeness4/5

    Coverage of the browser-automation lifecycle is strong: navigation and history, full input/gesture set, snapshots and search, console/network inspection, dialogs, tabs, uploads, tracing, video, and explicit session routing. Remaining gaps are moderate rather than blocking — no cookie/storage-state management, no request interception or network mocking, and no download handling.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers