浏览器自动化服务器

Chrome MCP Server是一个强大的浏览器自动化服务器,用于控制Chrome浏览器并与Cursor IDE集成,实现任务自动化和工作流构建。

  • by letuhao
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 letuhao/chrome-mcp

使用说明

Chrome MCP服务器

一个强大的 模型上下文协议(MCP)服务器 用于Chrome浏览器自动化和与Cursor IDE集成。直接从Cursor控制您的Chrome浏览器,自动化任务,并在人工智能的帮助下构建浏览器自动化工作流程。

✨ 特性

🎯 核心能力

  • 浏览器控件:导航、单击、键入网页并与之交互
  • 选项卡管理:列出、切换和关闭Chrome选项卡
  • 页面检查:获取页面内容、截图、执行JavaScript
  • 下载自动化:下载文件并自动化下载工作流程
  • 智能洪流选择:使用种子/日期逻辑自动选择种子

🚀 高级功能

  • 连接健康检查:Chrome断开连接时自动重新连接
  • 超时保护:通过可配置的超时防止无限挂起
  • 重试逻辑:对于失败的操作,会自动重新加载页面重试
  • 批处理:同时处理多个选项卡
  • 综合报告:详细的下载前/下载后报告
  • 独立自动化:用于持续监控的后台脚本

🛠️ 技术亮点

  • ✅ 稳健的错误处理:优雅的故障恢复
  • ✅ TypeScript:全型安全
  • ✅ 连接池:高效的资源管理
  • ✅ 健康监测:自动连接验证
  • ✅ 生产就绪:经过超时和重试机制的战斗测试

📋 目录

🚀 安装

先决条件

  • Node.js 20+已安装
  • 铬 浏览器已安装
  • 光标IDE (用于MCP集成)

步骤1:克隆并安装

git clone <repository-url>
cd chrome-mcp
npm install

步骤2:构建服务器

npm run build

步骤3:使用远程调试启动Chrome

⚠️ 重要: 对于Chrome 136+,始终使用配置文件脚本来处理安全限制。

Windows(推荐):

.\scripts\startup\start-chrome-debug-with-profile.ps1

此脚本会自动处理Chrome 136+安全限制并保留您的用户数据。

替代方案(Chrome<136):

.\scripts\startup\start-chrome-debug.bat

手动方法(不推荐):

"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222

📖 有关详细的设置说明,请参阅 SETUP_INSTRUCTIONS.md

macOS:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222

Linux:

google-chrome --remote-debugging-port=9222

注: 在启用远程调试之前,请关闭所有Chrome实例。

步骤4:配置游标

  1. 打开 光标设置 (Ctrl+, 或 Cmd+,)

  2. 引导到 特性 → 模型上下文协议

  3. 点击 添加MCP服务器

  4. 配置如下:

    姓名: chrome-mcp

    命令: node

    论据: ["<absolute-path-to-project>/dist/index.js"]

    例子:

    ["D:\\Works\\source\\chrome-mcp\\dist\\index.js"]
    
  5. 保存并验证连接状态(应显示“已连接”)

🎯 快速开始

运行下载自动化

快速设置:

  1. 启动Chrome浏览器: .\scripts\startup\start-chrome-debug-with-profile.ps1
  2. 启动自动化: npm run auto-download

看 SETUP_INSTRUCTIONS.md 详细说明。

在游标中使用MCP工具

配置后,您可以直接从Cursor聊天中控制Chrome:

# List all Chrome tabs
"List my Chrome tabs"

# Navigate to a website
"Navigate to https://example.com"

# Get current tab info
"What's the current Chrome tab?"

# Take a screenshot
"Take a screenshot of the current page"

📚 可用工具

浏览器控件

  • get_current_tab -获取有关当前活动Chrome选项卡的信息
  • list_tabs -列出所有打开的Chrome标签页及其详细信息
  • navigate_to_url -导航到特定URL
  • switch_to_tab -按URL或ID切换到特定选项卡
  • close_tab -关闭特定选项卡
  • check_chrome_connection -验证Chrome远程调试连接

页面交互

  • get_page_content -获取当前页面的HTML或文本内容
  • click_element -使用CSS选择器或XPath单击元素
  • type_text -在输入框中键入文本
  • execute_script -在页面上执行JavaScript
  • take_screenshot -捕获页面或视口屏幕截图

下载

  • download_file -从URL下载文件或单击下载链接
  • wait_for_download -等待下载完成
  • get_downloads -获取最近下载的列表
  • batch_download_and_close -从多个选项卡批量下载

高级自动化

  • download_newest_torrent -智能种子选择和下载

    • 选择带有种子的最新种子
    • 带着播种机回到旧的激流中
    • 处理过时的torrent部分
  • batch_download_torrents -批量下载带有报告的torrent

    • 处理多个选项卡
    • 重新加载页面重试逻辑
    • 全面的事前/事后报告
    • 成功后自动关闭选项卡

💡 使用示例

基本导航

// Via Cursor chat:
"Navigate to https://github.com and take a screenshot"

表单交互

// Via Cursor chat:
"Go to google.com, find the search box, and type 'MCP server'"

批量操作

// Via Cursor chat:
"Download newest torrents from all ExHentai tabs that are open"

JavaScript执行

// Via Cursor chat:
"Execute JavaScript to get all links on the current page"

🤖 自动化功能

独立自动化脚本

⚠️ 重要: 始终先使用配置文件脚本进行远程调试,然后启动Chrome:

.\scripts\startup\start-chrome-debug-with-profile.ps1

然后在后台运行连续监控:

npm run auto-download

📖 看 SETUP_INSTRUCTIONS.md 获取完整的设置指南

特征:

  • 监控ExHentai种子页面的Chrome标签页
  • 自动下载最新的种子
  • 成功下载后关闭选项卡
  • 生成详细的日志和报告
  • 独立于Cursor运行

配置:

  • 编辑 auto-download-standalone.js 自定义:
    • 下载文件夹路径
    • 轮询间隔
    • 重试逻辑
    • 日志记录设置

智能洪流选择逻辑

自动化使用智能选择:

  1. 更喜欢最新的部分:仅考虑“最新”部分中的种子
  2. 种子优先级:更喜欢有活跃种子的种子
  3. 回退逻辑:如果没有最新的种子,则退回到过时的部分
  4. 选择顺序:
    • 最新的种子种子洪流✓
    • 带有播种机的替代最新种子
    • 没有播种机的最新洪流(最后手段)
    • 过时的种子种子种子(如果没有最新的可用种子)

📁 项目结构

chrome-mcp/
├── README.md                    # Main project documentation
├── package.json                 # Node.js dependencies and scripts
├── tsconfig.json                # TypeScript configuration
├── .gitignore                   # Git ignore rules
├── auto-download-standalone.js  # Standalone automation script
│
├── src/                         # Source code
│   └── index.ts                 # Main MCP server implementation
│
├── dist/                        # Compiled output (generated, gitignored)
│   └── index.js
│
├── docs/                        # Documentation
│   ├── README.md                # Documentation index
│   ├── AUTOMATION_SETUP.md
│   ├── QUICK_START_AUTOMATION.md
│   ├── AUTO_DOWNLOAD_USAGE.md
│   └── ... (see docs/README.md for full list)
│
├── scripts/                     # Scripts and utilities
│   ├── download-newest-torrent.js          # Basic torrent selector
│   ├── download-newest-torrent-enhanced.js # Enhanced torrent selector
│   ├── retry-failed-downloads.js           # Retry logic
│   ├── helpers/                            # Helper scripts
│   │   └── test-mcp-connection.js          # Connection testing
│   └── startup/                             # Chrome startup scripts
│       ├── start-chrome-debug.bat
│       └── start-chrome-debug.ps1
│
├── logs/                        # Logs and reports (gitignored)
│   ├── auto-download-*.log
│   └── batch-report-*.json
│
└── reports/                     # Temporary reports (gitignored)
    └── *-report*.json

有关详细的文件夹结构,请参阅 docs/FOLDER_STRUCTURE.md.

🔧 配置

自定义下载文件夹

编辑 auto-download-standalone.js:

const DOWNLOAD_FOLDER = 'D:\\Your\\Download\\Folder';

Chrome远程调试端口

违约: 9222

要更改,请在以下位置修改端口:

  • Chrome启动命令: --remote-debugging-port=YOUR_PORT
  • MCP服务器代码: src/index.ts (默认值 9222)

🐛 故障排除

“未连接”错误

  1. 验证Chrome是否正在运行 通过远程调试:

    curl http://localhost:9222/json
    

    应返回选项卡的JSON数组。

  2. 重新启动游标MCP服务器:

    • 在光标设置中关闭/打开MCP服务器
    • 如果需要,重新启动游标
  3. 重建服务器:

    npm run build
    

连接超时

  • 确保Chrome正在运行 --remote-debugging-port=9222
  • 检查防火墙没有阻塞端口9222
  • 验证没有其他进程正在使用端口9222

下载不起作用

  • 检查下载文件夹权限
  • 验证Chrome下载设置
  • 检查浏览器控制台是否有错误

MCP服务器显示错误

  1. 检查游标输出日志(查看→ 输出→ MCP)
  2. 验证 dist/index.js 存在(运行 npm run build)
  3. 检查Node.js版本(需要20+)

📊 监测和报告

自动化日志

日志保存到 logs/auto-download-YYYY-MM-DD.log:

[INFO] Processing tab: Tab Title
[INFO]   Connected to tab...
[INFO]   Found torrent: 2025-11-21 15:47 (Seeds: 2)
[INFO]   ✓ Successfully processed tab

下载报告

报告保存到 logs/batch-report-before-*.json 和 logs/batch-report-after-*.json:

  • 预下载:所选种子详细信息
  • 下载后:成功/失败状态
  • 手动重试:手动干预下载失败

🧪 测试

测试连接

node test-mcp-connection.js

人工验证

使用验证脚本检查下载:

node manual-verification-report-*.json

🤝 贡献

欢迎投稿!拜托:

  1. 复刻仓库
  2. 创建要素分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Add amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

发展

# Install dependencies
npm install

# Build
npm run build

# Development mode (with hot reload)
npm run dev

# Run standalone automation
npm run auto-download

📝 许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。

🙏 致谢

📖 其他文件

设置指南

所有文件均按 docs/ 文件夹:

设置和入门

指南

技术文档

脚本文档

看 docs/README.md 获取完整的文档索引。

🔗 相关项目


由...制作❤️ 面向浏览器自动化爱好者

如有疑问或问题,请打开GitHub issue。