剧作家通用MCP
一个普遍的 模型上下文协议(MCP) 用于浏览器自动化的服务器,在权限有限的容器化环境中可靠工作。它为Claude、GPT-4等人工智能助手提供浏览器控制功能。
特性
- 🌐 多浏览器支持:在Chromium、Chrome、Microsoft Edge、Firefox或WebKit之间进行选择
- 🐳 集装箱友好型:适用于权限有限的环境(如Docker容器)
- 👁️ 无头/有头模式:在服务器环境中以无头模式运行,或在调试中以头模式运行
- 🛠️ 广泛的浏览器控制:导航、单击、键入、截图等
- 📄 多页支持:创建和管理多个浏览器页面/选项卡
安装
选项1:使用管道安装(推荐)
# 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 --helpusage: 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配置
要将此MCP服务器与Claude Desktop或其他启用MCP的应用程序一起使用,请添加以下配置:
Claude桌面配置
将以下内容添加到您的 ~/.config/Claude/claude_desktop_config.json 文件:
{
"mcpServers": {
"browser": {
"command": "playwright-universal-mcp",
"args": ["--browser", "msedge", "--headless"]
}
}
}作为PM2服务运行
要将MCP服务器作为PM2的持久服务运行,请执行以下操作:
- 创建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- 启动服务:
pm2 start ~/playwright-universal-mcp.config.js- 保存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:导航到URLclick:通过选择器或文本单击元素type:在输入元素中键入文本get_text:从元素中获取文本内容get_page_content:获取当前页面HTML内容take_screenshot:截取当前页面的屏幕截图new_page:创建新的浏览器页面switch_page:切换到其他浏览器页面get_pages:列出所有可用的浏览器页面wait_for_selector:等待页面上的元素可见get_browser_info:获取当前浏览器会话的信息
许可证
MIT许可证
致谢
本项目建立在以下基础之上:
- 剧作家 用于浏览器自动化
- 模型上下文协议(MCP) 对于连接标准
- MCP Python SDK 用于MCP实施
