使用说明
木偶MCP服务器
使用Puppeteer提供浏览器自动化功能的模型上下文协议(MCP)服务器。此服务器使LLM能够在真实的浏览器环境中与网页交互、截图和执行JavaScript 反检测 能力。
特性
- 🚀 浏览器自动化 与Puppeter
- 🛡️ 反侦测 使用
puppeteer-extra-plugin-stealth - 🚫 广告拦截 随着
puppeteer-extra-plugin-adblocker - 📸 屏幕截图功能 (PNG/JPEG格式)
- 💻 JavaScript执行 在浏览器环境中
- 🍪 Cookie管理 (获取/设置Cookie)
- 📝 控制台日志监控
工具
| 工具 | 说明 |
|---|---|
puppeteer_navigate |
导航到具有可选启动选项的URL |
puppeteer_screenshot |
捕获页面或特定元素的屏幕截图 |
puppeteer_click |
使用CSS选择器点击元素 |
puppeteer_fill |
用文本填充输入字段 |
puppeteer_select |
在下拉元素中选择选项 |
puppeteer_hover |
将鼠标悬停在元素上 |
puppeteer_evaluate |
在浏览器上下文中执行JavaScript |
puppeteer_set_cookie |
为域设置Cookie |
puppeteer_get_cookies |
获取当前页面的所有Cookie |
资源
- 控制台日志 (
console://logs)-浏览器控制台输出 - 截图 (
screenshot://<name>)-捕获的屏幕截图图像
安装
NPX(推荐)
{
"mcpServers": {
"puppeteer": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-puppeteer"]
}
}
}
本地开发
# Clone the repository
git clone https://github.com/ffffyhffff/puppeteer-mcp-server.git
cd puppeteer-mcp-server
# Install dependencies
npm install
# Build the project
npm run build
码头工人
{
"mcpServers": {
"puppeteer": {
"command": "docker",
"args": [
"run", "-i", "--rm", "--init",
"-e", "DOCKER_CONTAINER=true",
"mcp/puppeteer"
]
}
}
}
配置
光标IDE配置
添加到您的 ~/.cursor/mcp.json:
{
"puppeteer": {
"command": "node",
"args": ["<path-to-project>/dist/index.js"],
"env": {
"PUPPETEER_EXECUTABLE_PATH": "C:/Program Files/Google/Chrome/Application/chrome.exe"
}
}
}
环境变量
| 变量 | 描述 |
|---|---|
CHROME_PATH |
Chrome/Chromium可执行文件的路径 |
PUPPETEER_LAUNCH_OPTIONS |
JSON编码的Puppeteer启动选项 |
ALLOW_DANGEROUS |
允许危险的浏览器参数(默认值:false) |
DOCKER_CONTAINER |
在Docker中运行时设置为“true” |
启动选项
您可以通过两种方式自定义浏览器行为:
- 环境变量:
{
"env": {
"PUPPETEER_LAUNCH_OPTIONS": "{ \"headless\": false, \"args\": [] }",
"ALLOW_DANGEROUS": "true"
}
}
- 工具调用参数:
{
"url": "https://example.com",
"launchOptions": {
"headless": false,
"defaultViewport": { "width": 1280, "height": 720 }
}
}
用法示例
导航和屏幕截图
// Navigate to a page
await puppeteer_navigate({ url: "https://example.com" });
// Take a screenshot
await puppeteer_screenshot({
name: "example",
width: 1280,
height: 720,
format: "png"
});
表单交互
// Fill a form field
await puppeteer_fill({
selector: "input[name='email']",
value: "user@example.com"
});
// Click a button
await puppeteer_click({
selector: "button[type='submit']"
});
JavaScript执行
// Execute JavaScript in browser
const result = await puppeteer_evaluate({
script: "document.querySelectorAll('a').length"
});
安全
服务器包括对危险浏览器参数的安全验证:
--no-sandbox--disable-setuid-sandbox--single-process--disable-web-security--ignore-certificate-errors
这些要求明确 allowDangerous: true 或 ALLOW_DANGEROUS=true 环境变量。
构建
# Development build with watch mode
npm run watch
# Production build
npm run build
Docker构建
docker build -t mcp/puppeteer -f Dockerfile .
依赖项
@modelcontextprotocol/sdk-MCP-SDKpuppeteer-浏览器自动化puppeteer-extra-Puppeter插件框架puppeteer-extra-plugin-stealth-反检测puppeteer-extra-plugin-adblocker-广告拦截
许可证
MIT许可证
贡献
欢迎投稿!请随时提交拉取请求。