# MCP Virtual Cursor > macOS 上的"不抢鼠标"computer-use MCP 服务器。 > AI 操作物理鼠标永远不被打扰,主路径用 macOS Accessibility 树扫描 + 语义操作。 **Built FOR Claude Code** (and any other MCP-compliant client). **Authored BY Claude** (Anthropic Opus 4.7, 1M context) under human direction over 10 days, audited 3 rounds by GPT-5.5 via OpenAI Codex CLI — see [Authoring](#authoring). ## Why this exists Claude Code 自带的内置 `mcp__computer-use__*` 工具直接接管物理鼠标 — AI 操作时用户没法同时用电脑,频繁打断手头工作。OpenAI Codex Desktop 用了 macOS Accessibility 树作主感知通道(VoiceOver 同款 API)所以不抢鼠标,但 Anthropic 自家 Claude Mac 客户端到现在还是用 CGEvent 抢鼠标。这个项目把 Codex Desktop 那条路在开源 MCP 里实装出来,让任何 MCP 客户端(首要是 Claude Code)都能用。 **状态:v0.5.0** — 在 v0.4 之上把 codex 4 轮报告剩下的 4 个 issue(high-2 / medium-2 / medium-4 / low-1)全部清理,bundle@team 双因子 ACL 现在真正在 enforce 路径生效;详见 [PROGRESS.md](PROGRESS.md) v0.5 段。 历史:v0.4 在 v0.3.0 之上修了 codex 审计遗留的 3 个 issue(M-4/M-9/L-12),并加入 v0.4 主增强: - ✅ **bundle@team 强 ACL**(policy.toml 支持 `com.foo@TEAMID` 双因子语法,team id 由 SecCode 验证) - ✅ **policy.toml 热重载**(notify watcher 监听文件变化,无需重启 MCP server) - ✅ **可视虚拟光标 overlay**(透明 NSWindow + 用户提供的霓虹箭头图,AI 操作时短暂显示在目标元素上 — 不抢鼠标) - ✅ **AppleScript 模板 52 → 138**(覆盖 Photos/Shortcuts/Pages/Numbers/Keynote/Preview/Maps + 系统只读信息) - ✅ **VisionAX shape detection**(VNDetectRectanglesRequest 检测按钮/卡片/图标,含 OCR 元素一同返回) - ✅ **拖拽 .app 到白名单**(SwiftUI onDrop + Bundle URL 解析) - ✅ **NSWorkspace 监听 cgevent grant 自动 abort**(M-4 修复:前台变化即取消 token,关闭 cgevent race) - ✅ **element_id ACL 复查**(M-9 修复:cache.bundle_for RPC + recheck_element_acl,防 stale id 绕过 policy 改动) - ✅ **vc-agent 命令失败返回 tonic::Status::internal**(L-12 修复,含 stderr) - ✅ **container_open_viewer 探测后端健康**,install.sh 加 `--enable-container` 自动 docker run - ✅ **GitHub Actions CI**(fmt / clippy `-D warnings` / test / swift build)+ Homebrew formula + CONTRIBUTING.md + SECURITY.md - ✅ **codex 共 3 轮审计累计修了 23 个 issue** 详见 [PROGRESS.md](PROGRESS.md)。 ## 快速开始 ```bash git clone ~/Claude/mcp-virtual-cursor cd ~/Claude/mcp-virtual-cursor ./scripts/install.sh ``` 安装脚本会: 1. cargo + swift 构建 release 二进制 2. 复制 `policy.toml.example` 到 `~/.config/mcp-virtual-cursor/policy.toml` 3. 通过 `claude mcp add` 注册到 Claude Code 4. 安装 LaunchAgent 让 helper 在登录时自启 首次使用时 macOS 会弹三个权限请求(Accessibility / Screen Recording / Input Monitoring),开就完事。详见 [docs/permissions.md](docs/permissions.md)。 ## 设计核心 学 OpenAI Codex Desktop 路线:**macOS Accessibility 树作为主感知通道**,截图作为辅助视觉确认,CGEvent 抢鼠标仅作极少数 corner case 兜底。完整设计文档: - 简版:[docs/architecture.md](docs/architecture.md) - 完整版:`/Users/xiaolaopei/.claude/plans/mcp-codex-computer-use-modular-mitten.md` ### 多层兜底序 ``` Layer 0 AX 树扫描 + 操作 (主路径,~75-90% 应用) Layer 1 AppleScript 语义 (Apple 生态 60-70%,32 个内置模板) Layer 2 Full Keyboard Access (85-90% 通用键盘导航;用 cgevent_key 实现) Layer 3 VisionAX OCR (Tier 4 应用兜底,Apple Vision 框架,零外部模型) Layer 4 CGEvent 抢鼠标 + 快进快出 (极少数,需用户额外授权) ``` ### 应用 Tier 分级(实测驱动) - **Tier 1**:开箱即用 — Discord / Sketch / Notes / Finder / Safari / Slack / Apple 系列 - **Tier 2**:需 AXManualAccessibility 激活 — **QQ NTQQ ★ / VS Code / Obsidian / 钉钉 / 飞书** - **Tier 3**:AX 部分支持 — **微信 ★** / Word / Notion 桌面 / Spotify / Photoshop - **Tier 4**:完全不支持 — Steam / 原神 / Telegram Desktop / Riot Games(建议走 container 后端) ★ = 用户实测验证 ## MCP 工具(36 个)+ AppleScript 模板(138 个) | 类别 | 工具 | |------|------| | 高层入口 | echo, helper_ping, list_apps, get_active_app, get_app_tier, check_permissions, request_accessibility_permission | | AX 主路径 | ax_snapshot, ax_query, ax_perform, ax_set_value, ax_get_value, ax_focus, activate_ax_for_app | | AppleScript(52 个模板) | applescript_execute, applescript_template, list_applescript_templates | | 视觉 | screenshot, screenshot_annotated(含 OCR overlay), visionax_snapshot | | 容器(完备)| container_health, **container_screenshot, container_click, container_move, container_type, container_key, container_scroll, container_list_windows, container_open_viewer** | | 抢鼠标兜底 | request_intrusive_mode(NSAlert 强制确认), release_intrusive_mode, intrusive_status, cgevent_click, cgevent_move, cgevent_type, cgevent_key | **v0.3 新增(粗体)**:8 个 container 工具,把 vc-agent gRPC 全部 RPC 暴露给 AI。配合 `ENABLE_VNC=1` 和 `container_open_viewer` 输出的 noVNC URL,用户可在浏览器实时观察 AI 在容器内的操作。 ## 安全设计 - **黑名单 hardcoded**(不可由用户改):System Settings / Keychain / Terminal / iTerm / VS Code / Cursor / Zed / JetBrains 全系列 / 1Password / Bitwarden / Disk Utility / Activity Monitor / Apple Passwords / **Claude Code 自身**(防自残) / **Claude Desktop** - **黑名单 user-extra**:通过 `~/.config/mcp-virtual-cursor/policy.toml` 追加 - **每次工具调用都查 ACL**,bundle id + team id 双因子(team id 校验 v3.5 加) - **Abort hotkey ⌘⇧F19** 4 层防 AI 自模拟(**全部已实装 + v0.3 顺序修正**): 1. CGEvent userData magic 标记("MCVC" = 0x4D435643) 2. **IOHIDManager 硬件信号校验**(**Layer 2 优先于 Layer 4** — v0.3 修正后 AI 不能用 self-emit buffer 压制真硬件 abort) 3. MCP 工具层先验拦截(cgevent_key 拒绝 abort combo) 4. 自身合成事件环形缓冲(仅作 IOHID 不可用时的 echo 检测) - **Intrusive mode 强制 NSAlert 弹窗**(v0.3 修复 plan §8.4 缺陷):每次 `request_intrusive_mode` 必弹模态确认,3 个按钮(Allow Once / Allow For Session / Deny)+ 60s 自动 deny。 - **cgevent token 绑定 frontmost app**:v0.3 修复,token 给 Figma 但 AI 不能 cgevent 焦点的密码弹窗。 - **screenshot/visionax ACL**:黑名单应用拒绝截图(防 AI 视觉读取 Terminal / 钥匙串)。 - **policy.toml fail_closed**:parse 失败 → 全部 host 操作 deny 直到修好。 - **AppleScript 注入防御**:raw `applescript_execute` 拒绝 `do shell script` / `tell application "System Events"` / `Terminal` / `iTerm` / `Keychain` / `Script Editor`。模板(applescript_template)已审查,bypass。 - **bundle_id + team_id 双因子(部分)**:list_apps / get_active_app 输出含 team_id(通过 SecCode 验证),AI 可识别 bundle id spoofing。 - **Intrusive Mode 治理**:单次 30s 上限,5s cooldown ## 技术栈 - **MCP server**: Rust 1.94 + [rmcp 1.5](https://github.com/modelcontextprotocol/rust-sdk)(stdio) - **macOS helper**: Swift 6 + ScreenCaptureKit + AXUIElement + CGEvent + AppKit/SwiftUI - **协议**: JSON-RPC 2.0 over Unix Domain Socket(host↔helper),gRPC + tonic(host↔container) - **容器**: Apple Container(macOS 26 优先)/ Docker 兜底,Ubuntu 24.04 + Xvfb + xdotool ## 系统要求 - macOS 15+ (Sequoia / Tahoe) — 实测在 macOS 26 / Xcode 26.4.1 / Swift 6.3.1 上构建 - Rust 1.94+ - Apple Silicon 推荐 - Apple Container 或 Docker(仅 Day 7 容器后端需要,Day 1-6 + Day 8 不需要) ## License **MIT** — see [LICENSE](LICENSE). Open source from v0.3.0 onwards. Contributions welcome (especially: new AppleScript templates, AX adapters for niche apps, container backend tweaks). Please run `cargo fmt` + `cargo clippy --all-targets -- -D warnings` and `swift build` before opening a PR. ## Authoring Every line of source in this repository was written by **Claude Opus 4.7 (1M context)** running in Claude Code IDE, over 10 working days, under human direction. The human role was: planning sessions, code review, real-world QQ / WeChat / Notes / Finder testing, and security calls. Architectural sanity-check + 3-round security audit (23 issues found and fixed across critical / high / medium severities) was performed by **GPT-5.5 (xhigh reasoning)** via OpenAI's Codex CLI, called as a "second pair of eyes" agent. This is — somewhat fittingly — the second AI vendor's tool fixing the first AI vendor's UX papercut: Claude wrote the workaround for Claude Code's own mouse-stealing bug. We hope Anthropic eventually makes this redundant. ## 关键合规 严格遵守 CLAUDE.md 第 1 章核心原则: - 完整功能、无 TODO、无半成品 - 必有日志(写 `~/.local/state/mcp-virtual-cursor/log/`) - 维护 README / PROGRESS / [ERRORS.md](ERRORS.md) 三件套 - 编译 0 警告 0 错误