网页捕获工具

一个使用Puppeteer捕获网页并提供命令执行的MCP服务器,适用于网页快照和离线浏览。

  • by linguiben
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 linguiben/puppeteer-mcp-server

使用说明

木偶师mcp服务器

这是一个使用Puppeteer捕获网页并提供命令执行的MCP服务器。

工具行为

webpage_save_to_html

webpage_save_to_html 现在会把目标页面保存为一个离线快照目录,而不是单个 HTML 文件。

输出结构示例:

html/20260323123000_example.com/
  index.html
  manifest.json
  assets/
    example.com/...

行为说明:

  • 只保存当前 URL 页面实际加载到的内容,不递归抓取超链接目标页
  • 默认自动滚动页面到底部后回到顶部,用于触发懒加载图片等资源
  • 会保存主页面快照以及页面加载到的 CSS、图片、脚本、媒体资源
  • 不下载字体资源
  • manifest.json 中会记录已保存资源列表和失败项,便于后续分析

运行

  1. docker 方式启动
    startup.sh
  2. 本地方式启动(推荐先创建虚拟环境,参考下面的运行环境步骤)
    python start-mcp-server.py streamable-http
  3. 访问方式
  • 3.1 直接访问 http://0.0.0.0:8001/test/mcp_call_tester.html (推荐)
  • 3.2 通过curl命令远程调用mcp tools
# htpp头必须包含 application/json

# mcp list: list all tools
curl -i -X POST http://localhost:8001/mcp/ \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{"_meta":{"progressToken":2}}}'

# mcp call: run_cmd (在mcp server所在机器上执行命令,支持任何shell命令,注意安全风险)
curl -i -X POST http://localhost:8001/mcp/ \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":10,"method":"tools/call","params":{"name": "run_cmd", "arguments": { "command": "echo \"Hello from MCP Server\"" }, "_meta":{"progressToken":2}}}'

目录结构 todo

当地发展环境

  1. 创建python虚拟环境
python3.11 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# pip freeze > requirements.txt
  1. 安装node.js和puppeteer
npm install puppeteer
  1. python启动mcp server
python start-mcp-server.py streamable-http # 选择启动方式
  1. 通过mcpInspector远程调用mcp tools
# 利用mcpInspector启动访问mcp server
# 先启动/Users/jupiter/15.node-wkspc/mcpInspector, 然后执行:
curl -X POST http://127.0.0.1:5000/api/v1/mcp/run -d '{"url": "https://www.sina.com.cn/", "timeout": 10, "screenshot": true, "screenshot_path": "sina_world.png"}'
curl -X POST http://localhost:8000 --data "url=https://www.qq.com" 
📸 页面截图已保存为 images/20250615071725842_www.qq.com.png
  1. 测试sina_world_mobile.js
jupiter@Jupiter-Mac puppeteer$node sina_world_mobile.js 
✅ 环球板块加载成功
📊 抓取结果: []
📸 页面截图已保存为 sina_world.png