木偶MCP服务器
一种模型上下文协议(MCP)服务器,通过Puppeteer提供浏览器自动化功能。该服务器使AI代理能够与网页交互、截图、执行JavaScript和执行各种浏览器操作。
特性
- 多标签支持:使用唯一ID管理多个浏览器选项卡
- 综合工具:27个导航、交互、内容提取等工具
- 双重运输:支持stdio(用于克劳德桌面/代码)和HTTP传输
- 结果类型:使用结构化结果类型进行一致的错误处理
安装
npm install
npm run build
用法
标准模式(默认)
与克劳德桌面或克劳德代码一起使用:
npm start
# or
node dist/index.js
HTTP模式
对于远程或容器化部署:
npm start -- --http
# or
node dist/index.js --http --port=3000
Claude桌面配置
添加到您的Claude Desktop配置中:
{
"mcpServers": {
"puppeteer": {
"command": "node",
"args": ["/path/to/puppeteer-mcp/dist/index.js"]
}
}
}
可用工具
选项卡管理
| 工具 |
说明 |
list_tabs |
列出所有打开的浏览器选项卡 |
new_tab |
创建一个新标签页(可选配URL) |
close_tab |
关闭选项卡 |
switch_tab |
切换到其他选项卡 |
导航
| 工具 |
说明 |
navigate |
导航到URL |
reload |
重新加载当前页面 |
go_back |
返回历史记录 |
go_forward |
在历史中向前导航 |
交互
| 工具 |
说明 |
click |
单击元素 |
fill |
填写文本输入 |
select |
选择下拉选项 |
hover |
将鼠标悬停在元素上 |
focus |
聚焦一个元素 |
输入
| 工具 |
说明 |
keyboard |
按键盘键 |
mouse |
执行鼠标操作 |
scroll |
滚动页面或元素 |
内容
| 工具 |
说明 |
evaluate |
执行JavaScript |
get_content |
获取页面/元素HTML或文本 |
query_selector |
获取元素信息 |
等待
| 工具 |
说明 |
wait_for_selector |
等待元素出现 |
wait_for_navigation |
等待导航 |
wait |
等待指定时间 |
媒体
| 工具 |
说明 |
screenshot |
截图 |
pdf |
生成PDF |
Cookie
| 工具 |
说明 |
get_cookies |
获取Cookie |
set_cookies |
设置Cookie |
delete_cookies |
删除Cookie |
刀具参数
所有在页面上操作的工具都接受可选 tabId 参数。如果未指定,则使用活动选项卡。
示例:导航和截图
// Navigate
{ "name": "navigate", "arguments": { "url": "https://example.com" } }
// Take screenshot
{ "name": "screenshot", "arguments": { "fullPage": true, "format": "png" } }
示例:多选项卡工作流
// Create new tab
{ "name": "new_tab", "arguments": { "url": "https://site-a.com" } }
// Returns: { "id": "tab_abc123", "url": "https://site-a.com", ... }
// Create another tab
{ "name": "new_tab", "arguments": { "url": "https://site-b.com" } }
// Returns: { "id": "tab_def456", "url": "https://site-b.com", ... }
// List all tabs
{ "name": "list_tabs", "arguments": {} }
// Interact with specific tab
{ "name": "click", "arguments": { "selector": "button", "tabId": "tab_abc123" } }
环境变量
| 变量 |
描述 |
默认值 |
PORT |
HTTP服务器端口 |
3000 |
HEADLESS |
无头运行浏览器 |
true |
TIMEOUT |
默认操作超时(ms) |
30000 |
发展
# Install dependencies
npm install
# Run in development mode
npm run dev
# Type check
npm run typecheck
# Run tests
npm test
# Build
npm run build
建筑
src/
├── index.ts # Entry point, transport setup
├── server.ts # MCP server configuration
├── browser.ts # Browser lifecycle management
├── tabs.ts # Multi-tab state management
├── types.ts # TypeScript interfaces
├── errors.ts # Result types and error handling
├── schemas.ts # Zod validation schemas
└── tools/
├── tab-tools.ts # Tab management tools
├── navigation.ts # Navigation tools
├── interaction.ts # Click, fill, select, etc.
├── content.ts # Evaluate, get content
├── waiting.ts # Wait tools
├── media.ts # Screenshot, PDF
├── cookies.ts # Cookie management
└── input.ts # Keyboard, mouse, scroll
许可证
麻省理工学院
木偶师mcp