Puppeteer MCP Server (Python Implementation)

Puppeteer MCP Server (Python Implementation)

镜像

概述

这是一个使用 Python 实现的 Playwright 浏览器自动化 MCP 服务器,使 LLM 能够与网页交互、截取屏幕截图并执行 JavaScript。

安装

# 安装依赖包
pip install -r requirements.txt

# 安装 Playwright 浏览器
playwright install

启动服务器

python puppeteer_server.py

Claude 桌面配置

将以下内容添加到 Claude 配置文件中:

{
  "mcpServers": {
    "puppeteer": {
      "command": "python",
      "args": ["path/to/puppeteer.py"]
    }
  }
}

可用工具

网页导航

{
  "name": "puppeteer_navigate",
  "arguments": {
    "url": "https://example.com",
    "timeout": 60000  // 可选
  }
}

截图

{
  "name": "puppeteer_screenshot",
  "arguments": {
    "name": "my_screenshot",
    "selector": "#specific-element",  // 可选
    "width": 1280,  // 可选
    "height": 720   // 可选
  }
}

点击元素

{
  "name": "puppeteer_click",
  "arguments": {
    "selector": ".button-class"
  }
}

填写表单

{
  "name": "puppeteer_fill",
  "arguments": {
    "selector": "#input-id",
    "value": "text to fill"
  }
}

执行 JavaScript

{
  "name": "puppeteer_evaluate",
  "arguments": {
    "script": "document.title"
  }
}

注意事项

  • 需要 Python 3.8+
  • 浏览器以非无头模式启动以便于调试
  • 所有工具均支持可选的 timeout 参数
  • 错误处理和日志记录已内置

有关详细信息,请参阅完整文档。