Skip to main content
Glama

Windows 桌面自动化插件,通过本地 stdio MCP 服务器(cu)为 Antigravity 提供 UI Automation 控件树检查、屏幕截图、键鼠控制、Codex 风格紫色接管视觉提示(支持按物理 Esc 立即暂停接管、中英双语自适应与多屏热插拔)以及服务端硬编码安全红线保护。

A Windows desktop automation plugin for Antigravity providing UI Automation inspection, screenshots, mouse/keyboard control, a Codex-style purple takeover overlay (with instant physical Esc pause/reclaim, bilingual ZH/EN UI, and display hotplug support), and hard-coded server-side safety red lines over a local stdio MCP server (cu).


核心特性 / Feature Highlights

  • 通用 Python 3.10+ 启动器 / Universal Python 3.10+: mcp_config.json 使用 py -3 启动;server/launch.py 支持 Python 3.10+ 并自动检测 .venv 次版本不匹配,setup.ps1 支持 -Recreate 与 -Python 覆盖。

  • 17 个懒加载 MCP 工具 / 17 Lazy MCP Tools: 全部设为 "eager": false,不占用日常对话上下文;支持单批多步 computer_batch(含 task、end_session=True、wait_for_title 与自动返回 foreground_window)。

  • 视觉接管覆盖层 + 物理 Esc 急停 / Codex-Style Overlay & Esc Pause: 紫色发光边框(#8B5CF6)、中英双语状态横幅(CU_OVERLAY_LANG=auto|zh|en)、自适应滑行光标(80–220ms)与点击波纹;支持 WDA_EXCLUDEFROMCAPTURE 截屏隐身及 WM_DISPLAYCHANGE 显示器热插拔自适应。

  • 免中文输入法干扰 / IME-Proof Unicode Typing: Windows 下 type_text 使用私有 user32 句柄批量调用 SendInput KEYEVENTF_UNICODE,完整支持 ASCII、中文及 UTF-16 代理对,并提供 clear_first / press_enter。

  • 服务端硬编码安全红线 / Hard-Coded Safety Red Lines: 禁止操作 Antigravity / 宿主祖先进程 / 运行 agy 的终端 / 覆盖层自身 / UAC / Defender / SmartScreen / 主流密码管理器,自动拦截提权窗口(UIPI 完整性级别检测),并发互斥锁(_ACTION_LOCK)串行化写操作,全链路 TOCTOU 复检与脱敏审计日志。

  • 单窗口截图 & Set-of-Marks 标注 / Window-Scoped Capture & SoM: screenshot 支持 handle=<hwnd>(PrintWindow -> DWM 裁剪回退)与 marks=True([eN]/[feN] 编号徽章)。


Related MCP server: windows-computer-use-mcp

架构概览 / Architecture

flowchart LR
    AGY["Antigravity Host"] -- "stdio MCP (py -3 launch.py)" --> SRV["server/server.py (cu, 17 lazy tools)"]
    SRV --> LOCK["_ACTION_LOCK (RLock)"]
    LOCK --> SAFE["server/safety.py (Red Lines, UIPI, Kill Switches)"]
    SAFE --> UIA["server/uia.py (UI Automation)"]
    SAFE --> INPUT["server/input_ctl.py (SendInput UNICODE / Mouse)"]
    SRV --> SCREEN["server/screen.py (mss, PrintWindow, SoM, Desktop State)"]
    SRV -- "JSON-line stdin/stdout pipe (only helper)" --> OVC["server/overlay_client.py"]
    OVC <--> OV["server/overlay.py (Win32 Layered Overlay + WH_KEYBOARD_LL Esc)"]
    SRV --> AUDIT["%LOCALAPPDATA%/agy-computer-use/audit.jsonl"]

快速开始 / Quick Start

系统要求 / Requirements: Windows 10 (2004+) / Windows 11, Python 3.10+ (py launcher on PATH), Antigravity.

# 1. 克隆仓库 / Clone the repository
git clone https://github.com/Niall0218/agy-computer-use.git
cd agy-computer-use

# 2. 一键安装到 Antigravity 插件目录 / Install into Antigravity plugins directory
powershell -ExecutionPolicy Bypass -File .\install.ps1

安装完成后 / After installation:

  1. install.ps1 会仅同步运行时文件(plugin.json, mcp_config.json, requirements.txt, setup.ps1, README.md, LICENSE 以及 server/, rules/, skills/, assets/ 镜像,自动排除 .git/.github/tests/缓存且不破坏 .venv)到 %USERPROFILE%\.gemini\config\plugins\agy-computer-use,并在目标目录运行 setup.ps1。

  2. setup.ps1 自动探测 py -3(校验 >= 3.10)创建 .venv,优先以 1500ms 超时探测 pypi.org,不可达时自动回退至阿里云镜像 https://mirrors.aliyun.com/pypi/simple/。

  3. 在 Antigravity 的插件管理中启用 Computer Use (agy-computer-use) 即可使用。

如需强制重建虚拟环境(例如升级了默认 Python 版本)或指定 PyPI 镜像 / Rebuild .venv or override PyPI index:

powershell -ExecutionPolicy Bypass -File .\install.ps1 -Recreate
powershell -ExecutionPolicy Bypass -File .\install.ps1 -IndexUrl https://mirrors.aliyun.com/pypi/simple/

环境变量 / Environment Variables

变量 / Variable

默认值 / Default

说明 / Description

CU_OVERLAY

1

设为 0 完全禁用视觉覆盖层助手子进程 / Set to 0 to disable the visual overlay helper process.

CU_OVERLAY_LANG

auto

覆盖层横幅与状态文案语言:auto(自动根据 Windows GetUserDefaultUILanguage() 选择 zh/en)、zh 或 en / Overlay banner & activity language: auto (detects Windows UI language), zh, or en.

CU_OVERLAY_IDLE_S

30

无操作自动隐藏覆盖层的空闲超时秒数 / Idle timeout in seconds before the overlay auto-hides.

CU_DISABLED

(unset)

设为 1 立即阻止所有操作类工具(只读工具仍可用)/ Set to 1 to block all action tools (read-only tools remain available).

CU_READONLY

(unset)

设为 1 启用只读模式,阻止所有键鼠与窗口焦点变更 / Set to 1 for read-only mode (blocks all mutating actions).

CU_EXTRA_BLOCKED

(unset)

逗号分隔的额外屏蔽进程/窗口名(只能追加,无法移除内置安全红线)/ Comma-separated extra blocked process or window patterns (strictly additive).


视觉接管覆盖层与 Esc 暂停 / Visual Takeover Overlay & Esc Pause

当 Agent 执行桌面操作(或调用 control_session(action="begin", task="..."))时,服务端按需启动唯一硬编码辅助进程 server/overlay.py:

  • 紫色发光边框 / Purple Glowing Border: 每个显示器四边绘制 #8B5CF6 发光边框,全程点击穿透(WS_EX_TRANSPARENT)且绝不抢占焦点(WS_EX_NOACTIVATE / MA_NOACTIVATE / SW_SHOWNOACTIVATE)。

  • 双语顶部状态横幅 / Bilingual Top Status Pill: 根据 CU_OVERLAY_LANG 自动显示中文(Antigravity 正在控制您的电脑 · 按 Esc 停止)或英文(Antigravity is controlling your computer · Press Esc to stop),过长文案按像素宽度自动省略号截断,绝不溢出;输入类动作仅显示字符数,绝不泄露输入文本。

  • 自适应滑行光标与点击波纹 / Adaptive Gliding Cursor & Click Ripple: 按移动距离自动计算时长(<4px 为 0ms,其余 80–220ms,带单调请求 id 防乱序),滑行后执行 TOCTOU 安全复检,再注入真实输入并渲染点击波纹。

  • 显示器热插拔自适应 / Display Hotplug (WM_DISPLAYCHANGE): 分辨率或显示器拓扑变化时,覆盖层自动重建各屏边框、在主屏重新居中横幅、重新应用 WDA_EXCLUDEFROMCAPTURE,并通过 hwnds_updated 同步给 OverlayClient。

  • 截屏自动隐藏 / Screenshot Exclusion: Windows 10 2004+ (build >= 19041) 使用 SetWindowDisplayAffinity(WDA_EXCLUDEFROMCAPTURE) 自动从截屏中排除覆盖层,不支持时回退至 capture_guard() 瞬间隐藏/恢复。

  • 按物理 Esc 立即暂停并收回控制权 / Press Physical Esc to Pause & Reclaim Control:

    • 通过进程内 WH_KEYBOARD_LL 监听物理 Esc(拒绝注入按键 LLKHF_INJECTED / LLKHF_LOWER_IL_INJECTED,不注入 DLL、不吞键、不记录击键),第一时间锁存 user_stopped=True,全部操作类工具返回 [BLOCKED]。

    • 横幅切换为暂停态(已暂停 · 点击此处将控制权交还 Antigravity / Paused · Click here to hand control back to Antigravity)。仅用户点击暂停横幅或重启服务端可恢复;没有任何 MCP 工具可清除 user_stopped。


单批流畅执行示例 / Single-Batch Browser URL Recipe

优先在一次 computer_batch 调用内完成多步操作(自动开启/结束覆盖层、免 IME 干扰输入并自动返回 foreground_window):

computer_batch(
    task="Open example.com",
    end_session=True,
    actions=[
        {"action": "focus_window", "handle": <hwnd>},
        {"action": "key", "combo": "ctrl+l"},
        {"action": "type_text", "text": "https://example.com", "clear_first": True, "press_enter": True},
        {"action": "wait_for_title", "handle": <hwnd>, "title_changed_from": "<old_title>", "timeout_ms": 5000},
    ],
)

急停开关与安全机制 / Kill Switches & Safety

四重急停开关 / Kill Switches

  1. 物理 Esc 键 / Physical Esc Key: 接管期间按物理 Esc 立即暂停,点击暂停横幅方可恢复。

  2. 文件开关 / File Kill Switch: 创建 %LOCALAPPDATA%\agy-computer-use\STOP(删除文件即可恢复):

    New-Item -ItemType File -Force "$env:LOCALAPPDATA\agy-computer-use\STOP"
  3. 环境变量 / Environment Variables: CU_DISABLED=1 或 CU_READONLY=1。

  4. 屏幕角落急停 / Mouse Corner Failsafe: pyautogui.FAILSAFE=True,鼠标甩至任意屏幕角落即返回 [BLOCKED] failsafe。

硬编码安全红线 / Hard-Coded Red Lines

以下保护内置于 server/safety.py 与 server/server.py,无法通过环境变量放宽(详见 SECURITY.md):

  • 禁止操作 Antigravity、宿主祖先进程、运行 agy 的终端与覆盖层自身窗口。

  • 高危系统界面与密码管理器黑名单: consent.exe (UAC)、credentialuibroker.exe、logonui.exe、lockapp.exe、smartscreen.exe、useraccountcontrolsettings.exe、Windows 安全中心/Defender UI(含 ApplicationFrameHost.exe UWP 子进程),以及 1password*.exe、keepass*.exe、keepassxc.exe、bitwarden.exe、lastpass*.exe、dashlane.exe、protonpass.exe、nordpass*.exe、keeper*.exe、enpass*.exe、roboform*.exe、authy*.exe(可通过 CU_EXTRA_BLOCKED 追加)。

  • UIPI 提权目标拦截 / UIPI Elevation Blocking: 自动对比目标进程与服务端的 Windows 完整性级别 RID;若目标运行于更高权限(如管理员窗口),直接返回 [BLOCKED]。

  • 高危快捷键拦截: 拒绝 ctrl+alt+del / ctrl+alt+delete、win+l、win+r、ctrl+shift+esc / ctrl+shift+escape。

  • 并发串行化与 TOCTOU 防护: 全部写操作经 _ACTION_LOCK 串行化;光标滑行后复检、drag 每 <=16px 插值复检、type_text 每 <=32 字符块复检前台窗口句柄。

  • 单一辅助进程例外与脱敏审计日志: 仅允许拉起 server/overlay.py;所有调用记录于 %LOCALAPPDATA%\agy-computer-use\audit.jsonl(5 MB 自动轮转,文本输入仅记长度、密码框脱敏为 ***)。


工具列表与限制 / Tools (cu, 17 Lazy Tools) & Limits

  • 会话与覆盖层 / Session & Overlay: control_session

  • 只读观察 / Read-only: screenshot(支持 handle 单窗口截图与 marks=True Set-of-Marks 编号标注)、screen_info(含 desktop_session 与 server_elevated 诊断)、list_windows、ui_tree、find_elements

  • UIA 控件操作 / UIA Actions: click_element, set_element_value

  • 键鼠与窗口控制 / Input & Window: focus_window, click, move, drag, scroll, type_text, key, wait

  • 批量执行 / Batch: computer_batch

项目 / Item

限制 / Limit

type_text 单次文本 / Max text

<= 2000 chars (interval <= 0.5s, total <= 10s)

computer_batch 单批动作 / Max batch

<= 30 actions, cumulative wait + wait_for_title <= 10s

drag 路径点数 / Max drag path

<= 200 points (interpolated every <= 16px)

wait 单次等待 / Max wait

<= 10000 ms

screenshot 建议宽度 / Default max width

<= 1280 px (JPEG quality 60)

ui_tree 默认上限 / Default cap

max_depth=6, max_nodes=250


开发与测试 / Development & Testing

# 安装开发依赖 (pytest + ruff) / Install dev dependencies
powershell -ExecutionPolicy Bypass -File .\setup.ps1 -Dev

# 代码检查 / Lint
.\.venv\Scripts\python.exe -m ruff check server tests

# 运行自动化测试 / Run automated test suite
.\.venv\Scripts\python.exe -m pytest tests -rs -q

# 在交互式桌面上运行 tkinter 端到端测试 / Interactive desktop E2E test
$env:CU_E2E = "1"; .\.venv\Scripts\python.exe -m pytest tests\test_e2e_tk.py -rs -q

tests/ 仅保留在源代码仓库中,不会被 install.ps1 复制到已安装插件目录。


常见问题排查 / Troubleshooting FAQ

1. 目标窗口提示 UIPI / 提权被拦截([BLOCKED] ... higher integrity level)

Windows UIPI(用户界面特权隔离)会阻止中等权限进程向以管理员身份运行(High Integrity)的窗口注入键鼠事件。agy-computer-use 会主动检测并直接返回 [BLOCKED](同时 screen_info() 会返回 server_elevated 状态)。请将目标应用以普通用户权限运行,或由用户手动操作管理员窗口。

2. Python 版本不匹配或 .venv 无法启动

mcp_config.json 使用 py -3 启动,若系统升级了默认 Python 次版本导致与 .venv/pyvenv.cfg 不一致,launch.py 会输出明确的重建提示。请运行:

powershell -ExecutionPolicy Bypass -File .\setup.ps1 -Recreate
# 或重新部署并重建已安装插件的 .venv / Or reinstall and rebuild:
powershell -ExecutionPolicy Bypass -File .\install.ps1 -Recreate
# 指定特定 Python 3.10+ 路径 / Or pin a specific Python 3.10+ executable:
powershell -ExecutionPolicy Bypass -File .\setup.ps1 -Recreate -Python "C:\Path\To\python.exe"

3. 中文 / CJK 输入法问题

type_text 在 Windows 上使用 SendInput KEYEVENTF_UNICODE,直接发送 Unicode 字符而不经过 IME 候选词转换;但若目标输入框(如浏览器地址栏)当前正处于未提交的 IME 组合态,随后的 Enter 可能仅确认候选词而非提交表单。建议配合 clear_first=True、press_enter=True 与 wait_for_title 确认跳转。

4. 锁屏、沙盒或非交互式桌面(desktop_session / 截屏失败)

在锁屏、远程桌面断开、UAC 安全桌面或无头沙盒(如 exebox-*)中,Windows 会拒绝截屏与输入注入。调用 screen_info() 检查 desktop_session(reason 为 "ok"、"secure_desktop_or_locked"、"non_interactive_desktop" 或 "unavailable"),并在已解锁的交互式桌面会话中使用插件。


卸载 / Uninstall

使用 uninstall.ps1 安全移除已安装插件(内置路径保护,拒绝删除磁盘根目录、用户目录或非 agy-computer-use 目录):

# 卸载插件(默认保留审计日志与状态目录 %LOCALAPPDATA%\agy-computer-use)
powershell -ExecutionPolicy Bypass -File .\uninstall.ps1

# 卸载插件并一并清除审计日志与状态目录 / Also purge state & audit logs
powershell -ExecutionPolicy Bypass -File .\uninstall.ps1 -PurgeState

文档与开源协议 / Documentation & License

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI clients to inspect and control allowlisted Windows applications using screenshots, mouse actions, Unicode keyboard input, UI Automation, and an Esc/F12 emergency stop.
      1
      Apache 2.0
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables agents to control Windows desktop applications through UI Automation and Win32, supporting window management, mouse/keyboard input, element inspection, screenshots, OCR, macro recording, and autonomous multi-app missions. It also provides an HTTP/stdio MCP interface, an operator UI, and optional telemetry and safety controls.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI clients to operate Windows desktops through native UIA control, OCR text targeting, screenshots, and 54 tools for window, process, input, clipboard, file, registry, and document tasks with pause, observe-only, and privacy safeguards.
      MIT