mcpField
P
Playwright Universal MCP

Playwright Universal MCP

本地服务
github.com/xkiranj浏览器自动化083 周前更新

关于 Playwright Universal MCP

Playwright Universal MCP 是供 AI 助手使用的浏览器自动化 MCP 服务,也适用于权限受限的容器环境。它支持多种浏览器、多页面操作,以及无头或可视模式。

主要功能

  1. 01支持 Chromium、Chrome、Edge、Firefox 和 WebKit
  2. 02适用于容器环境
  3. 03支持无头与可视模式
  4. 04导航、点击、输入和截图
  5. 05管理多个页面与标签页

适用场景

  1. 01在容器中自动执行浏览器操作
  2. 02在浏览器任务中截取页面
  3. 03在单次会话中管理多个浏览器页面

MCP 相关

该服务向 MCP 客户端提供浏览器控制工具,包括导航、页面交互、截图和页面管理。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

Playwright 通用 MCP

一个通用的模型上下文协议(MCP)浏览器自动化服务,可在权限受限的容器化环境中可靠运行。它为 Claude、GPT-4 等 AI 助手提供浏览器控制能力。

功能

  • 🌐 多浏览器支持:可选择 Chromium、Chrome、Microsoft Edge、Firefox 或 WebKit
  • 🐳 适用于容器环境:可在权限受限的环境中运行(例如 Docker 容器)
  • 👁️ 无头/有头模式:在服务端环境中以无头模式运行,或以有头模式进行调试
  • 🛠️ 全面的浏览器控制:导航、点击、输入、截图等
  • 📄 支持多个页面:创建和管理多个浏览器页面/标签页

安装

选项 1:使用 pipx 安装(推荐)
# Install the MCP Python SDK
pip install git+https://github.com/microsoft/mcp-python-sdk.git

# Install the MCP server globally
pipx install playwright-universal-mcp

# Install the required browsers
playwright install chromium
# Optional: install other browsers
playwright install firefox webkit msedge chrome
选项 2:在 Python 虚拟环境中安装
# Create and activate a virtual environment
python -m venv playwright-mcp-venv
source playwright-mcp-venv/bin/activate

# Install the MCP Python SDK
pip install git+https://github.com/microsoft/mcp-python-sdk.git

# Install the package
pip install playwright-universal-mcp

# Install browsers
playwright install chromium
选项 3:从源代码安装
# Clone the repository
git clone https://github.com/xkiranj/playwright-universal-mcp.git
cd playwright-universal-mcp

# Install the MCP Python SDK
pip install git+https://github.com/microsoft/mcp-python-sdk.git

# Install the package
pip install -e .

# Install browsers
playwright install chromium

使用方法

命令行选项
playwright-universal-mcp --help
usage: playwright-universal-mcp [-h] [--browser {chromium,firefox,webkit,msedge,chrome}] [--headless] [--headful] [--debug] [--browser-arg BROWSER_ARG]

Universal Playwright MCP server with multi-browser support

options:
  -h, --help            show this help message and exit
  --browser {chromium,firefox,webkit,msedge,chrome}, -b {chromium,firefox,webkit,msedge,chrome}
                        Browser to use (default: chromium)
  --headless            Run browser in headless mode (default: true)
  --headful             Run browser in headful mode (with GUI)
  --debug               Enable debug logging
  --browser-arg BROWSER_ARG
                        Additional browser arguments (can be specified multiple times)
基本示例
# Start with default options (Chromium in headless mode)
playwright-universal-mcp

# Use Microsoft Edge
playwright-universal-mcp --browser msedge

# Use Firefox in headful mode (visible browser window)
playwright-universal-mcp --browser firefox --headful

# Enable debug logging
playwright-universal-mcp --debug

# Pass additional arguments to the browser
playwright-universal-mcp --browser-arg="--disable-gpu" --browser-arg="--window-size=1920,1080"

MCP 配置

要在 Claude Desktop 或其他支持 MCP 的应用程序中使用此 MCP 服务,请添加以下配置:

Claude Desktop 配置

将以下内容添加到 ~/.config/Claude/claude_desktop_config.json 文件中:

{
  "mcpServers": {
    "browser": {
      "command": "playwright-universal-mcp",
      "args": ["--browser", "msedge", "--headless"]
    }
  }
}
作为 PM2 服务运行

要使用 PM2 将 MCP 服务作为持久服务运行:

  1. 创建 PM2 配置文件:
cat > ~/playwright-universal-mcp.config.js << 'EOF'
module.exports = {
  apps: [{
    name: "playwright-universal-mcp",
    script: "playwright-universal-mcp",
    args: "--browser msedge --headless",
    watch: false,
    autorestart: true,
    restart_delay: 3000
  }]
}
EOF
  1. 启动服务:
pm2 start ~/playwright-universal-mcp.config.js
  1. 保存 PM2 进程列表:
pm2 save

容器化使用

此 MCP 服务适用于容器化环境。以下是一个简单的 Dockerfile 示例:

FROM python:3.10-slim

# Install dependencies
RUN apt-get update && apt-get install -y \
    wget \
    gnupg \
    && rm -rf /var/lib/apt/lists/*

# Install the package
RUN pip install playwright-universal-mcp

# Install browsers (install the ones you need)
RUN playwright install chromium

# Run the MCP server
ENTRYPOINT ["playwright-universal-mcp", "--headless"]

可用的浏览器工具

MCP 服务提供以下工具:

  • navigate:导航到 URL
  • click:通过选择器或文本点击元素
  • type:在输入元素中输入文本
  • get_text:获取元素的文本内容
  • get_page_content:获取当前页面的 HTML 内容
  • take_screenshot:截取当前页面
  • new_page:创建新的浏览器页面
  • switch_page:切换到其他浏览器页面
  • get_pages:列出所有可用的浏览器页面
  • wait_for_selector:等待页面上的元素变为可见
  • get_browser_info:获取当前浏览器会话的信息

许可证

MIT 许可证

致谢

本项目基于以下项目构建:

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。