CoDriver MCP
通过模型上下文协议实现AI驱动的桌面自动化
CoDriver是一个MCP服务器,它使Claude能够控制任何桌面应用程序。它捕获屏幕截图,读取可访问性树,执行OCR,并注入鼠标/键盘输入,从而在桌面上实现实时人工智能协作。
CoDriver适用于整个桌面,就像“Chrome中的克劳德”适用于浏览器一样。
特性
| 工具 | 说明 |
|---|---|
desktop_screenshot | 捕获整个桌面、窗口或特定显示器(PNG/JPEG) |
desktop_click | 单击坐标或按元素参照 |
desktop_type | 在光标处或特定元素中键入文本 |
desktop_key | 按组合键(ctrl+c, alt+tab, f5) |
desktop_scroll | 在某个位置向任意方向滚动 |
desktop_drag | 在坐标或元素参照之间拖放 |
desktop_windows | 列出并聚焦应用程序窗口 |
desktop_read_ui | 使用引用ID读取可访问性树 |
desktop_find | 按名称、角色或值查找UI元素 |
desktop_launch | 启动、退出或检查应用程序的状态 |
desktop_ocr | 通过OCR从屏幕提取文本(tesseract.js) |
desktop_displays | 列出连接的监视器以进行多显示器捕获 |
平台支持
| 平台 | 状态 | 鼠标/键盘 | 窗口管理 | 辅助功能 | 屏幕截图 | OCR |
|---|---|---|---|---|---|---|
| macOS | 支持 | Swift/CGEvent+robotjs | Swift/CoreGraphics | JXA/osascript | 截图桌面 | tesseract.js |
| 视窗 | 支持 | robotjs | PowerShell+Win32 P/Invoke | PowerShell+UI自动化 | 屏幕截图桌面 | tesseract.js |
| Linux | 计划中 | - | - |
快速开始
先决条件
- Node.js 20+
- macOS 或 Windows 10/11
- 仅限Windows:Visual Studio构建工具(用于robotjs本机编译)
macOS权限
CoDriver需要两个系统权限。授予他们 系统设置>隐私和安全:
| 权限 | 必需 | 如何授予 |
|---|---|---|
| 屏幕录制 | 截图、窗口列表 | 添加您的终端/IDE应用程序 |
| 无障碍 | 鼠标点击、键盘输入、滚动、UI树阅读 | 添加您的终端/IDE应用程序 |
提示: 如果您使用IDE中的CoDriver(例如Windsurf、VS Code),请添加 IDE应用程序 打开两个权限列表,然后完全重新启动它(Cmd+Q)。
Windows权限
| 权限 | 需要 | 备注 |
|---|---|---|
| 无 | 截图、窗口列表、UI树阅读 | 开箱即用 |
| 管理员 (可选) | 读取管理员提升进程的UI | 以管理员身份运行终端 |
注: robotjs需要 Visual Studio 生成工具 在Windows上编译本机模块。通过安装 npm install --global windows-build-tools 或从以下网址下载 Visual Studio.安装
git clone https://github.com/ViktorTrn/codriver-mcp.git
cd codriver-mcp
npm install
npm run build用克劳德代码配置(本地)
增添 ~/.claude/settings.json:
{
"mcpServers": {
"codriver": {
"command": "node",
"args": ["/absolute/path/to/codriver-mcp/dist/index.js"]
}
}
}远程访问(HTTP传输)
node dist/index.js --http # localhost:3100
node dist/index.js --http --port 8080 # custom port
node dist/index.js --http --host 0.0.0.0 # all interfaces
node dist/index.js --http --api-key YOUR_SECRET # with authentication远程克劳德代码配置:
{
"mcpServers": {
"codriver-remote": {
"url": "http://your-machine:3100/mcp",
"headers": {
"Authorization": "Bearer YOUR_API_KEY"
}
}
}
}使用示例
"Take a screenshot of my desktop"
-> desktop_screenshot
"Read the UI tree of the frontmost app"
-> desktop_read_ui
"Find the Save button"
-> desktop_find { query: "Save" }
"Click the Save button"
-> desktop_click { ref: "ref_3" }
"Drag the file to the trash"
-> desktop_drag { startRef: "ref_5", endRef: "ref_12" }
"Type into the search field"
-> desktop_type { ref: "ref_5", text: "hello world" }
"Launch Safari"
-> desktop_launch { action: "launch", appName: "Safari" }
"Read text from this area of the screen"
-> desktop_ocr { x: 100, y: 200, width: 500, height: 100 }
"Which monitors are connected?"
-> desktop_displays可访问性驱动的工作流
推荐的工作流程反映了Chrome的可访问性方法:
- 读取UI -
desktop_read_ui返回一个包含引用ID的元素树 - 查找元素 -
desktop_find按名称、角色或值搜索 - 通过ref进行交互 -
desktop_click { ref: "ref_1" }或desktop_type { ref: "ref_3", text: "..." }
这比基于坐标的点击更可靠,因为元素是在语义上标识的。
组合键
| 输入 | 操作 |
|---|---|
enter | 按Enter键 |
ctrl+c | 复制 |
ctrl+v | 粘贴 |
ctrl+shift+s | 另存为 |
cmd+a | 全选(macOS) |
alt+tab | 切换窗口 |
f5 | 刷新 |
esc | 逃跑 |
发展
npm run build # Compile TypeScript
npm run dev # Watch mode (tsx)
npm test # Run tests (107 tests)
npm run typecheck # Type-check without emit建筑
CoDriver MCP Server (Node.js/TypeScript)
|
+-- Transport
| +-- stdio (local, default)
| +-- Streamable HTTP/SSE (remote, --http flag)
|
+-- Tools (12 total)
| +-- desktop_screenshot PNG/JPEG capture, multi-monitor
| +-- desktop_click Mouse click (coords or ref)
| +-- desktop_type Keyboard input
| +-- desktop_key Key combinations
| +-- desktop_scroll Scroll wheel
| +-- desktop_drag Drag & drop
| +-- desktop_windows Window management
| +-- desktop_read_ui Accessibility tree
| +-- desktop_find Element search
| +-- desktop_launch App lifecycle
| +-- desktop_ocr Text recognition
| +-- desktop_displays Monitor listing
|
+-- Modules
+-- ScreenCapture screenshot-desktop + sharp (cross-platform)
+-- InputController Swift/CGEvent (macOS) | robotjs (Windows)
+-- WindowManager Swift/CoreGraphics (macOS) | PowerShell+Win32 (Windows)
+-- AccessibilityReader JXA/osascript (macOS) | PowerShell+UIA (Windows)
+-- AppLauncher AppleScript (macOS) | PowerShell (Windows)
+-- OcrEngine tesseract.js (cross-platform)技术栈
| 组件 | macOS | Windows |
|---|---|---|
| 运行时 | Node.js 20 LTS,TypeScript 5.7+严格版 | 相同 |
| MCP SDK | @modelcontextprotocol/SDK v1.26 | 相同 |
| 截图 | 截图桌面+锐化 | 相同 |
| 鼠标输入 | Swift/CGEvent | @jitsi/robotjs |
| 键盘输入 | @jitsi/robotjs | 相同 |
| 可访问性 | JXA/osascript | PowerShell+用户界面自动化(System.Windows.Automation) |
| 窗口管理 | Swift/核心图形 | PowerShell+Win32 P/Invoke |
| 应用程序启动器 | AppleScript/osascript | PowerShell(启动进程/停止进程) |
| OCR | tesseract.js | 相同 |
| HTTP传输 | Express+StreamableHTTPServerTransport | 相同 |
| 测试 | vitest(107次测试) | 相同 |
路线图
- \[x\] 第一阶段:MVP -屏幕截图、鼠标、键盘、windows(macOS)
- \[x\] 第二阶段:可访问性 -UI树读取、元素引用、自然语言查找
- \[x\] 第三阶段:远程 -HTTP/SSE传输、API-key身份验证、JPEG压缩
- \[x\] 第四阶段:波兰语 -OCR、拖放、应用程序启动、多显示器
- \[x\] 第五阶段:窗户 -完全支持Windows 10/11
未来
- \[x\] npm包发布(
npm install -g codriver-mcp) - \[\]GIF录制
- \[\]Linux平台支持
许可证
麻省理工学院
作者
维克托·特伦切克- IBT 工程 办公 Trncik
