🚀 Crucible
Crucible 是一個基於 Ruby 的 MCP(模型上下文協議)服務器,它藉助 Ferrum 和無頭 Chrome 瀏覽器實現自動化操作。該項目提供了 29 種工具,可供 AI 代理控制瀏覽器,並且內置了隱身模式,能夠有效躲避機器人檢測。
🚀 快速開始
運行服務器
crucible
crucible --no-headless
crucible \
--no-headless \
--width 1920 \
--height 1080 \
--timeout 60 \
--chrome /usr/bin/chromium \
--error-level debug
CLI 選項
| 選項 |
描述 |
默認值 |
-c, --config FILE |
YAML 配置文件的路徑 |
自動檢測 |
--[no-]headless |
是否以無頭模式運行瀏覽器 |
true |
-w, --width WIDTH |
視口寬度(像素) |
1280 |
-h, --height HEIGHT |
視口高度(像素) |
720 |
--chrome PATH |
Chrome/Chromium 可執行文件的路徑 |
自動檢測 |
-t, --timeout SECONDS |
默認超時時間(秒) |
30 |
--error-level LEVEL |
日誌記錄級別(debug/info/warn/error) |
warn |
--screenshot-format FMT |
默認截圖格式(png/jpeg/base64) |
png |
--content-format FMT |
默認內容格式(html/text) |
html |
--[no-]stealth |
啟用/禁用隱身模式 |
true |
--stealth-profile PROFILE |
隱身模式配置文件(minimal/moderate/maximum) |
moderate |
--stealth-locale LOCALE |
隱身模式下的瀏覽器區域設置 |
en-US,en |
Claude Code 集成
gem install crucible
將以下內容添加到你的 Claude Code MCP 設置文件(~/.claude/settings.json)中:
{
"mcpServers": {
"crucible": {
"command": "crucible",
"args": ["--config", "~/.config/crucible/config.yml"]
}
}
}
✨ 主要特性
- 提供 29 種工具,方便 AI 代理控制瀏覽器。
- 內置隱身模式,可有效躲避機器人檢測。
- 支持多會話管理,可同時處理多個獨立的瀏覽器實例。
📦 安裝指南
使用 gem 安裝
gem install crucible
從源碼安裝
git clone https://github.com/joshfng/crucible.git
cd crucible
bundle install
💻 使用示例
基礎導航
navigate(url: "https://example.com")
wait_for(selector: ".content")
get_content(format: "text")
表單提交
navigate(url: "https://example.com/login")
type(selector: "#email", text: "user@example.com")
type(selector: "#password", text: "secret123")
click(selector: "button[type=submit]")
wait_for(selector: ".dashboard")
截圖與 PDF 生成
screenshot()
screenshot(full_page: true)
screenshot(selector: ".hero-image")
screenshot(path: "/tmp/page.png")
screenshot(format: "jpeg", quality: 90, path: "/tmp/page.jpg")
pdf()
pdf(path: "/tmp/page.pdf")
pdf(format: "Letter", landscape: true)
JavaScript 執行
evaluate(expression: "[window.innerWidth, window.innerHeight]")
evaluate(expression: "window.scrollTo(0, 0)")
evaluate(expression: "document.querySelectorAll('a').length")
文件下載
set_download_path(path: "/tmp/downloads")
click(selector: "a.download-btn")
wait_for_download(timeout: 30)
list_downloads()
clear_downloads(delete_files: true)
📚 詳細文檔
工具列表
導航工具
| 工具 |
描述 |
navigate |
將瀏覽器導航到指定 URL |
wait_for |
等待元素出現 |
back |
後退到歷史記錄中的上一頁 |
forward |
前進到歷史記錄中的下一頁 |
refresh |
刷新當前頁面 |
交互工具
| 工具 |
描述 |
click |
點擊元素(支持雙擊、右鍵點擊) |
type |
在輸入框中輸入文本(可選清空/提交) |
fill_form |
一次性填充多個表單字段 |
select_option |
從下拉菜單中選擇選項 |
scroll |
將頁面或元素滾動到可見區域 |
hover |
懸停在元素上 |
提取工具
| 工具 |
描述 |
screenshot |
截圖(視口、全頁或元素);保存到文件或返回 base64 |
get_content |
獲取頁面內容(HTML 或文本) |
pdf |
生成頁面的 PDF;保存到文件或返回 base64 |
evaluate |
執行 JavaScript 並返回結果 |
get_url |
獲取當前頁面的 URL |
get_title |
獲取當前頁面的標題 |
Cookie 工具
| 工具 |
描述 |
get_cookies |
獲取所有 Cookie 或特定 Cookie |
set_cookies |
設置一個或多個 Cookie |
clear_cookies |
清除所有或特定 Cookie |
會話工具
| 工具 |
描述 |
list_sessions |
列出所有活動的瀏覽器會話 |
close_session |
關閉一個會話或所有會話 |
下載工具
| 工具 |
描述 |
set_download_path |
設置下載目錄 |
wait_for_download |
等待下載完成 |
list_downloads |
列出所有跟蹤的下載文件 |
clear_downloads |
清除跟蹤的下載文件(可選刪除文件) |
隱身工具
| 工具 |
描述 |
enable_stealth |
為會話啟用隱身模式 |
disable_stealth |
為會話禁用隱身模式 |
get_stealth_status |
獲取會話的隱身模式狀態 |
set_stealth_profile |
更改隱身模式配置文件(minimal/moderate/maximum) |
會話管理
所有工具都接受一個可選的 session 參數,用於管理多個獨立的瀏覽器實例:
navigate(session: "login-flow", url: "https://example.com/login")
navigate(session: "signup-flow", url: "https://example.com/signup")
list_sessions()
close_session(session: "login-flow")
close_session(all: true)
會話在首次使用時自動創建,並在顯式關閉之前一直存在。
隱身模式
隱身模式應用了各種規避技術,使無頭 Chrome 瀏覽器在機器人檢測系統中看起來像普通瀏覽器。默認情況下,它以“moderate”配置文件啟用。
隱身模式配置文件
| 配置文件 |
描述 |
minimal |
基本規避(navigator.webdriver、窗口尺寸) |
moderate |
適用於大多數用例的常見規避(默認) |
maximum |
針對最嚴格的機器人檢測的所有規避 |
應用的規避技術
隱身模塊包含從 puppeteer-extra 移植的規避技術:
navigator.webdriver - 移除 webdriver 標誌
chrome.app - 模擬 chrome.app 對象
chrome.csi - 模擬 chrome.csi 函數
chrome.loadTimes - 模擬 chrome.loadTimes
chrome.runtime - 為擴展程序模擬 chrome.runtime
navigator.vendor - 覆蓋 navigator.vendor
navigator.languages - 匹配 Accept-Language 標頭
navigator.plugins - 模擬插件和 mimeTypes
navigator.permissions - 修復 Notification.permission
navigator.hardwareConcurrency - 設置合理的核心數
webgl.vendor - 修復 WebGL 供應商/渲染器
media.codecs - 報告對專有編解碼器的支持
iframe.contentWindow - 修復 iframe 檢測
window.outerdimensions - 修復 outerWidth/outerHeight
- 用戶代理覆蓋 - 去除“Headless”並修復平臺
運行時控制
get_stealth_status(session: "default")
enable_stealth(session: "default", profile: "maximum")
disable_stealth(session: "default")
set_stealth_profile(session: "default", profile: "minimal")
配置文件
創建 ~/.config/crucible/config.yml 文件:
browser:
headless: true
window_size: [1280, 720]
stealth:
enabled: true
profile: moderate
locale: "en-US,en"
server:
log_level: info
項目結構
crucible/
├── exe/crucible # CLI 可執行文件
├── crucible.gemspec # Gem 規範文件
├── Gemfile # 依賴文件
├── Rakefile # 構建任務文件
├── lib/
│ ├── crucible.rb # 主模塊
│ └── crucible/
│ ├── version.rb # 版本常量
│ ├── configuration.rb # 支持 YAML 的配置文件
│ ├── session_manager.rb # 多會話管理
│ ├── server.rb # MCP 服務器設置
│ ├── stealth.rb # 隱身模式模塊
│ ├── stealth/
│ │ ├── utils.js # 隱身實用工具
│ │ └── evasions/ # 單個規避腳本
│ └── tools/
│ ├── helpers.rb # 共享實用工具
│ ├── navigation.rb # 導航工具
│ ├── interaction.rb # 交互工具
│ ├── extraction.rb # 提取工具
│ ├── cookies.rb # Cookie 工具
│ ├── sessions.rb # 會話工具
│ ├── downloads.rb # 下載工具
│ └── stealth.rb # 隱身控制工具
└── spec/ # RSpec 測試文件
開發
bundle exec rspec
bundle exec rubocop
bundle exec rake console
bundle exec rake server
發佈
bin/release 0.2.0
此腳本會更新版本號、提交更改、打標籤、推送代碼、創建 GitHub 發佈、構建 gem 並推送到 RubyGems(你需要通過瀏覽器處理 MFA)。
要求
- Ruby >= 3.2.0
- Chrome 或 Chromium 瀏覽器
- 依賴項:
ferrum ~> 0.17.1
mcp ~> 0.4.0
📄 許可證
本項目採用 MIT 許可證。有關詳細信息,請參閱 LICENSE 文件。