Playwright MCP 标志

Playwright MCP

组织
roxybrowserlabs

@roxybrowser/playwright is a Playwright-style browser-automation library with humanized behavior by default, plus an MCP server (@roxybrowser/playwright/mcp) that exposes the same capabilities as…

发布者roxybrowserlabs
代码仓库roxybrowser-playwright-mcp
语言TypeScript
复刻数
5
星标数
19
可用工具
21
传输类型stdio
分类
链接
  • 将工具接入 AI 工作流

    Playwright MCP 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 21 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 19 个 Star 和 5 个 Fork。

@roxybrowser/playwright

@roxybrowser/playwright is a Playwright-style browser-automation library with humanized behavior by default, plus an MCP server (@roxybrowser/playwright/mcp) that exposes the same capabilities as tools. It targets Chromium over CDP and Firefox over WebDriver BiDi. It is not a fork of Playwright — it reproduces a Playwright-familiar public API on top of a protocol-agnostic adapter layer.

Design goals

  • Keep the public API familiar to Playwright users.
  • Route all browser operations through a protocol-agnostic adapter layer.
  • Support both CDP (Chromium) and WebDriver BiDi (Firefox) as protocol backends.
  • Make click, type, hover, and scroll behavior humanized by default instead of adding a second API.
  • Expose the same capabilities as MCP tools for agent-driven automation.

Install

bash
npm install @roxybrowser/playwright
# or
pnpm add @roxybrowser/playwright

The package is ESM-only ("type": "module", NodeNext resolution). Two entry points are published:

  • @roxybrowser/playwright — the Playwright-style library (chromium, firefox, Browser, BrowserContext, Page, Locator, ElementHandle).
  • @roxybrowser/playwright/mcp — the MCP server factories and transports.

Package layout

  • src/browser*.ts: public browser, context, and browser type objects.
  • src/page.ts and src/locator.ts: Playwright-style page and locator APIs.
  • src/protocol/*: protocol abstraction plus CDP and BiDi backend entry points.
  • src/human/*: humanization profiles and controller contracts.
  • src/mcp/*: the MCP server, runtime, connected-browser session, and tools.
  • CLAUDE.md / AGENTS.md: architecture notes and repository guidance.

Testing

  • pnpm test runs the unit suite in tests/unit.
  • pnpm test:e2e runs a real-browser CDP flow in tests/e2e.
  • pnpm test:e2e:bidi runs the Firefox BiDi e2e suite in tests/e2e/bidi.

The e2e suite writes a temporary HTML fixture, launches Chrome or Edge in headless mode, and verifies the public API against a real page through CDP. If auto-detection is not enough for your machine or CI image, set ROXY_E2E_EXECUTABLE_PATH to a Chromium-based browser binary before running the e2e command.

The BiDi e2e suite prefers connecting to an existing Firefox BiDi websocket when ROXY_BIDI_WS_ENDPOINT is set. Without that variable, it launches a local Firefox binary with a temporary test profile and will use ROXY_BIDI_EXECUTABLE_PATH when provided. Set ROXY_BIDI_USE_ROXYBROWSER_API=1 to opt into opening a Firefox profile through the RoxyBrowser local API; the helper closes the connected browser/profile after each test by default so repeated local runs do not leak Firefox windows. Set ROXY_BIDI_KEEP_BROWSER_OPEN=1 only when deliberately debugging a shared endpoint and you intentionally want the Firefox window to stay open after a test. See .env.example for the supported local settings.

Browser connect

RoxyBrowser uses browserType.connect(endpointURL) as the only browser entry point. launch() and connectOverCDP() are intentionally unsupported and throw migration errors that point callers to connect().

chromium.connect() attaches to a Chromium/CDP WebSocket endpoint such as ws://127.0.0.1:9222/devtools/browser/<id>.

firefox.connect() attaches to a Firefox/WebDriver BiDi WebSocket endpoint. The Firefox BiDi path supports context creation, page creation, navigation, title lookup, script evaluation, and locator-based click, hover, fill, type, press, textContent, and isVisible flows.

  • ws:// and wss:// endpoints are supported.
  • launch() is not supported by the public Roxy API.
  • connectOverCDP() is not supported by the public Roxy API; use connect() for CDP and BiDi.

Examples

The examples directory contains runnable .mjs scripts grouped by entry point. Prefer the shared runner so endpoint environment variables are loaded and injected consistently:

  • pnpm examples page connect-over-cdp Connects to an existing CDP WebSocket endpoint from ROXY_CDP_ENDPOINT with chromium.connect() and runs the same flow.
  • pnpm examples page verify-baidu-search Drives Baidu search through the Page API and types into the search box with page.type(...).
  • pnpm examples page page-events-and-screenshot Connects to an endpoint, starts a temporary HTTP fixture, logs page.on(...) events, removes a request listener, and writes a screenshot to a temporary file.
  • pnpm examples page connect-firefox-bidi Exercises the Firefox WebDriver BiDi backend by connecting to an existing BiDi websocket.
  • pnpm examples mcp verify-baidu-search Drive the MCP server end-to-end (Baidu search, drag, file upload, humanized typing) and double as integration checks.

Use examples/page/ for direct Browser/Context/Page API examples, examples/mcp/ for MCP tool examples, and examples/repro/ for bug reproductions. Use pnpm examples <module> <script> to run a script through the shared examples runner. The runner loads .env, injects ROXY_CDP_ENDPOINT / ROXY_BIDI_ENDPOINT, and can open a RoxyBrowser profile through the local API when an endpoint is missing.

Useful environment variables:

  • ROXY_BROWSER_CHANNEL=chrome|msedge|chromium
  • ROXY_BROWSER_NAME=chromium|firefox
  • ROXY_EXECUTABLE_PATH=/absolute/path/to/browser
  • ROXY_HEADLESS=false
  • ROXY_CDP_ENDPOINT=ws://127.0.0.1:9222/devtools/browser/<id>
  • ROXY_BIDI_ENDPOINT=ws://127.0.0.1:9222/session/<id>
  • ROXY_PLAYWRIGHT_ARTIFACTS_DIR=/absolute/path/to/artifacts
  • ROXY_PLAYWRIGHT_DOWNLOADS_DIR=/absolute/path/to/downloads
  • ROXY_PLAYWRIGHT_TEMP_DIR=/absolute/path/to/temp

Connecting the MCP server to a browser

Before other MCP tools can act on a page, attach the session to a running browser with the roxy_browser_connect tool:

  • endpoint (required): the CDP WebSocket endpoint (Chrome) or the BiDi websocket endpoint (Firefox).
  • browser: chrome (default) or firefox. Chrome connects over CDP; Firefox connects over WebDriver BiDi.
  • sessionId (optional): reuse an existing BiDi session.

Endpoints typically come from the RoxyBrowser desktop app's local API, which opens a profile and returns a debugging endpoint. Once connected, the standard browser_* tools (browser_navigate, browser_snapshot, browser_click, browser_type, browser_take_screenshot, and so on) operate on the active tab.

browser_tabs keeps tab creation, selection, and closing in the background by default, so automation does not steal OS focus. Pass activate: true when the browser tab should be brought to the foreground. Background tab creation requires Chromium 145 or newer because older Chromium builds activate the application even when CDP receives background: true. On an older build, new fails with background_tab_unsupported before creating anything; background select remains available.

The Playwright-style Page API also creates new pages in the background by default. Call page.bringToFront() explicitly when the browser UI should be focused. This is an intentional RoxyBrowser divergence from Playwright's foreground page-creation behavior.

In-memory launch-and-connect

roxy_browser_launch is a special convenience tool for createRoxyBrowserMcpInMemory() only. The stdio and HTTP MCP servers keep exposing roxy_browser_connect and do not register roxy_browser_launch by default.

Enable it by passing RoxyBrowser launch configuration when creating the in-memory server:

ts
import { createRoxyBrowserMcpInMemory } from "@roxybrowser/playwright/mcp";

const bundle = await createRoxyBrowserMcpInMemory({
  roxyBrowserLaunch: {
    workspaceId: 123,
    apiToken: process.env.ROXYBROWSER_API_TOKEN!,
    apiPort: process.env.ROXYBROWSER_API_PORT ?? 50000
  }
});

The tool input is intentionally small:

  • dirId (required): the RoxyBrowser profile/window directory ID.
  • browser: chrome (default) or firefox.
  • forceOpen: passed to the RoxyBrowser open call when the profile is not already open.
  • args: optional browser startup arguments.

Before opening anything, roxy_browser_launch calls the RoxyBrowser connection-info API for that dirId. If an endpoint is already available, it connects directly. Otherwise it opens the profile and then connects. On success, it returns structured JSON in structuredContent and the same JSON as text:

json
{
  "browsers": [
    {
      "dirId": "profile-dir-id",
      "endpoint": "ws://127.0.0.1:9222/devtools/browser/...",
      "connected": true,
      "pageUrl": "https://example.com/",
      "browserType": "chrome"
    }
  ]
}

Asset directories

Page API and MCP tools share one asset model. Screenshots, downloads, snapshots, traces, videos, network exports, console exports, script outputs, and temporary runtime files are resolved by the same asset manager.

API options take precedence over environment variables. Relative filename arguments are resolved inside the relevant asset directory. Absolute asset paths are rejected by default.

Supported environment variables:

  • ROXY_PLAYWRIGHT_ARTIFACTS_DIR: default durable asset root.
  • ROXY_PLAYWRIGHT_DOWNLOADS_DIR: browser downloads.
  • ROXY_PLAYWRIGHT_SCREENSHOTS_DIR: screenshots.
  • ROXY_PLAYWRIGHT_SNAPSHOTS_DIR: accessibility snapshots and snapshot markdown files.
  • ROXY_PLAYWRIGHT_TRACES_DIR: traces.
  • ROXY_PLAYWRIGHT_VIDEOS_DIR: videos and screencast recordings.
  • ROXY_PLAYWRIGHT_NETWORK_DIR: network exports.
  • ROXY_PLAYWRIGHT_CONSOLE_DIR: console exports.
  • ROXY_PLAYWRIGHT_SCRIPTS_DIR: script and evaluate outputs.
  • ROXY_PLAYWRIGHT_TEMP_DIR: short-lived runtime files.
  • SANDBOX_OUTPUT_DIR: agent sandbox output directory. When set and no API asset option is provided, it becomes the default artifacts/downloads/scripts root.

The old MCP-specific variables ROXY_MCP_OUTPUT_DIR, PLAYWRIGHT_MCP_OUTPUT_DIR, ROXY_MCP_TEMP_DIR, and PLAYWRIGHT_MCP_TEMP_DIR are not supported.

You can also set asset directories directly when creating the MCP server or transports:

ts
import {
  createRoxyBrowserMcpInMemory,
  createRoxyBrowserMcpServer,
  startRoxyBrowserMcpHttp,
  startRoxyBrowserMcpStdio
} from "@roxybrowser/playwright/mcp";

const artifactsDir = "/absolute/path/to/artifacts";
const downloadsDir = "/absolute/path/to/downloads";
const screenshotsDir = "/absolute/path/to/screenshots";
const snapshotsDir = "/absolute/path/to/snapshots";
const tempDir = "/absolute/path/to/temp";

createRoxyBrowserMcpServer({
  artifactsDir,
  downloadsDir,
  screenshotsDir,
  snapshotsDir,
  tempDir
});

await createRoxyBrowserMcpInMemory({
  artifactsDir,
  downloadsDir,
  screenshotsDir,
  snapshotsDir,
  tempDir
});

await startRoxyBrowserMcpHttp({
  port: 3000,
  artifactsDir,
  downloadsDir,
  screenshotsDir,
  snapshotsDir,
  tempDir
});

await startRoxyBrowserMcpStdio({
  artifactsDir,
  downloadsDir,
  screenshotsDir,
  snapshotsDir,
  tempDir
});

MCP inspector workflow

This repo includes @modelcontextprotocol/inspector as a dev dependency so we can debug the Playwright MCP server locally.

Local stdio inspector

Use the inspector to spawn the built MCP server over stdio:

bash
pnpm inspector

That command will:

  • build the TypeScript sources into dist/
  • start the MCP Inspector UI on http://127.0.0.1:6274
  • launch node ./dist/bin/roxybrowser-mcp.js as the inspected MCP server

This is the fastest loop when you want to manually exercise tools from the inspector UI.

Local HTTP inspector

If you want to keep the MCP server running separately and connect the inspector over Streamable HTTP:

Terminal 1:

bash
pnpm mcp:http

Terminal 2:

bash
pnpm inspector:http

By default the HTTP server listens on http://127.0.0.1:3333/mcp.

Inspector CLI smoke

For a non-interactive check through the Inspector v2 CLI:

bash
pnpm test:mcp-inspector

This builds the server, runs mcp-inspector --cli against the stdio launcher, calls tools/list, and verifies the expected RoxyBrowser tools are exposed.

MCP server CLI options

The bundled roxybrowser-mcp launcher supports both transports:

bash
node ./dist/bin/roxybrowser-mcp.js --transport stdio
node ./dist/bin/roxybrowser-mcp.js --transport http --port 3333 --host 127.0.0.1 --path /mcp

Optional flags:

  • --artifacts-dir /absolute/path
  • --downloads-dir /absolute/path
  • --screenshots-dir /absolute/path
  • --snapshots-dir /absolute/path
  • --traces-dir /absolute/path
  • --videos-dir /absolute/path
  • --network-dir /absolute/path
  • --console-dir /absolute/path
  • --scripts-dir /absolute/path
  • --temp-dir /absolute/path
  • --snapshot-mode full
  • --snapshot-mode none

安装

TypingMind
{
  "mcpServers": {
    "roxybrowser-playwright-mcp": {
      "command": "npx",
      "args": [
        "@playwright/mcp@latest"
      ]
    }
  }
}

可用工具

  • browser_close

    Close the page

  • browser_resize

    Resize the browser window

  • browser_console_messages

    Returns all console messages

  • browser_handle_dialog

    Handle a dialog

  • browser_evaluate

    Evaluate JavaScript expression on page or element

  • browser_file_upload

    Upload one or multiple files

  • browser_fill_form

    Fill multiple form fields

  • browser_install

    Install the browser specified in the config. Call this if you get an error about the browser not being installed.

  • browser_press_key

    Press a key on the keyboard

  • browser_type

    Type text into editable element

  • browser_navigate

    Navigate to a URL

  • browser_navigate_back

    Go back to the previous page

  • browser_network_requests

    Returns all network requests since loading the page

  • browser_take_screenshot

    Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.

  • browser_snapshot

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

  • browser_click

    Perform click on a web page

  • browser_drag

    Perform drag and drop between two elements

  • browser_hover

    Hover over element on page

  • browser_select_option

    Select an option in a dropdown

  • browser_tabs

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

  • browser_wait_for

    Wait for text to appear or disappear or a specified time to pass

将 Playwright MCP MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 Playwright MCP 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 Playwright MCP 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 Playwright MCP MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "roxybrowser-playwright-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@roxybrowser/playwright-mcp"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 Playwright MCP MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Playwright MCP MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Playwright MCP 帮我完成这项任务吗?
Playwright MCP
当然。我已阅读。
以下是我使用 Playwright MCP 得到的结果。

常见问题

Playwright MCP MCP 服务器有什么用途?

Playwright MCP 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Playwright MCP MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 Playwright MCP,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 Playwright MCP MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 Playwright MCP 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Playwright MCP MCP 连接到 TypingMind?

Playwright MCP 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Playwright MCP MCP 在 TypingMind 中提供哪些工具?

Playwright MCP 提供 21 个 MCP 工具,您可以在 TypingMind 的插件页面启用这些工具,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Playwright MCP MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 Playwright MCP 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇