Chrome MCP服务器
一个模型上下文协议(MCP)服务器,使克劳德等人工智能助手能够通过Chrome扩展程序和WebSocket通信控制Chrome浏览器。非常适合跨平台自动化,特别是WSL/Windows设置。
🚀 特性
- 浏览器自动化:导航、单击、滚动、填写表单、截图
- 交叉平台的:跨WSL/Windows网络边界工作
- 双重通信:本地消息传递+WebSocket(网络)
- 克劳德集成:与Claude Code和Claude Desktop直接集成
- 实时控制:通过MCP工具进行实时浏览器交互
- Chrome 扩展:易于安装带有弹出控件的浏览器扩展
🏗️ 建筑
┌─────────────┐ WebSocket ┌─────────────┐ MCP/stdio ┌─────────────┐
│ Windows │ ←─────────────→ │ WSL │ ←─────────────→ │ Claude Code │
│ Chrome │ ws://IP:9222 │ Server │ │ │
│ + Extension │ │ │ │ │
└─────────────┘ └─────────────┘ └─────────────┘📦 安装
先决条件
- Node.js>=18.0.0
- Chrome/Chromium浏览器
- TypeScript(用于开发)
快速设置
- 克隆存储库
git clone https://github.com/deoxy/chrome-pilot.git
cd chrome-pilot- 安装依赖项
cd server
npm install
npm run build- 启动WebSocket服务器
node dist/index.js --websocket- 加载Chrome扩展程序
- 打开 chrome://extensions/ - 启用“开发人员模式” - 点击“加载解包” - 选择 extension 文件夹
- 配置扩展
- 点击扩展图标 - 输入WebSocket URL: ws://YOUR_IP:9222/ws - 点击“保存配置”和“重新连接”
🔧 配置
克劳德代码(WSL)
增添 ~/.claude/settings.json:
{
"mcpServers": {
"chrome-pilot": {
"command": "node",
"args": ["/path/to/chrome-pilot/server/dist/index.js", "--websocket"],
"env": {}
}
}
}适用于克劳德桌面
添加到Claude桌面设置:
{
"mcpServers": {
"chrome-pilot": {
"command": "node",
"args": ["/path/to/chrome-pilot/server/dist/index.js"]
}
}
}🛠️ 可用工具
| 工具 | 说明 | 参数 |
|---|---|---|
navigate | 导航到URL | url, tabId? |
get_tabs | 获取所有打开的浏览器选项卡 | - |
get_current_tab | 获取当前活动选项卡 | - |
close_tab | 关闭浏览器选项卡 | tabId |
click | 点击一个元素 | selector, tabId? |
type | 在输入中键入文本 | selector, text, tabId? |
scroll | 滚动页面 | direction, amount?, tabId? |
screenshot | 截图 | tabId? |
get_content | 提取页面内容 | selector?, tabId? |
get_interactive_elements | 查找可点击的元素 | tabId? |
wait_for_element | 等待元素出现 | selector, timeout?, tabId? |
🌐 网络设置(WSL/Windows)
1.查找WSL IP
ip route | grep default2.配置Windows防火墙
# Run as Administrator
New-NetFirewallRule -DisplayName "Chrome MCP Server" -Direction Inbound -Port 9222 -Protocol TCP -Action Allow3.扩展设置
- 通过访问扩展
\\wsl$\Ubuntu\path\to\chrome-pilot\extension - 在Windows Chrome中加载
- 在弹出窗口中配置WebSocket URL
- 测试连接
🧪 测试
测试WebSocket服务器
curl http://localhost:9222/info
curl -X POST http://localhost:9222/command \
-H "Content-Type: application/json" \
-d '{"action": "get_tabs", "params": {}}'与克劳德一起测试
Can you navigate to google.com and take a screenshot?📁 项目结构
chrome-pilot/
├── server/ # MCP Server (TypeScript)
│ ├── src/
│ │ ├── index.ts # Main server entry
│ │ ├── websocket-server.ts # WebSocket server
│ │ ├── native-host.ts # Native messaging
│ │ └── tools/ # Browser automation tools
│ ├── package.json
│ └── tsconfig.json
├── extension/ # Chrome Extension
│ ├── manifest.json # Extension config
│ ├── background-websocket.js # Service worker
│ ├── content.js # Content script
│ ├── popup.html # Extension popup
│ └── popup.js
├── native-host/ # Native messaging setup
│ ├── install.sh # Installation script
│ └── com.chrome_mcp.host.json.template
└── docs/ # Documentation🔍 故障排除
扩展未连接
- 在扩展弹出窗口中验证WebSocket URL
- 检查WSL IP地址是否未更改
- 确保服务器在正确的端口上运行
- 检查Windows防火墙设置
MCP工具不工作
- 重新启动Chrome扩展程序
- 在弹出窗口中验证“已连接”状态
- 检查服务器日志是否有错误
- 确保扩展具有必要的权限
性能问题
- 使用以太网连接以获得最佳性能
- 监控WSL和Windows之间的网络延迟
- 考虑在固定IP上运行
🤝 贡献
- 分叉存储库
- 创建要素分支
- 进行更改
- 如果适用,添加测试
- 提交拉取请求
📝 许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
🙏 致谢
- 内置于 MCP-SDK 通过Anthropic
- 使用Chrome扩展程序API实现浏览器自动化
- 支持跨平台的WebSocket通信
