Puppeteer MCP Server (Python Implementation)

Puppeteer MCP Server (Python Implementation)

未知

简介

这是一个 Model Context Protocol 服务器,使用 Playwright(Python)提供浏览器自动化功能,让 LLMs 能够与网页交互、截图并执行 JavaScript。

安装步骤

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

# 2. 安装 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+
  • pip(Python 包管理器)

注意事项

  • 浏览器默认以非无头模式启动(便于调试)
  • 默认视口大小:1280x720
  • 所有操作都有可配置的超时时间
  • 详细的错误处理和日志记录

许可证

Apache 2.0