Feature: Add window info RPC for foreground checks and window activation

Add a capability-gated main-connection RPC (COMMAND_MCP_WINDOW_INFO=179 /
TOKEN_MCP_WINDOW_INFO=180) that returns visible top-level windows with UTF-8
titles, screen rectangles, foreground flag and z-order, so MCP can verify
focus before injecting input. New tool get_foreground_window; host_list_windows
switches to the richer fields; host_control_window and operate_window gain
action=activate; remote_keyboard and remote_mouse gain expect_hwnd,
require_foreground and report_foreground. Old clients keep the previous
behavior: the RPC is refused up front via CLIENT_CAP_WINDOW_INFO.

The client caps a response at 96 windows (about 101 KB, under MAX_SEND_BUFFER).
Signal the cut-off in the mode byte (0x80) instead of silently dropping windows:
host_list_windows now reports truncated=true and says the list is incomplete,
and activate verification reports state=unknown with reason=list_truncated
rather than claiming the window is gone. expect_hwnd is checked only after the
session is validated, so an invalid session_id no longer burns a window RPC and
no longer reports a window error for a session that does not exist. Nullable
output fields (foreground, window) are declared as ["object","null"] so strict
clients do not reject responses.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-10 15:09:24 +01:00
1 parent c7e23f750d
commit b2c0d81396
18 files changed
+1298 -68

No files matched your search

+228 -22
View File
@@ -15,7 +15,7 @@
],
"version": 2,
"protocolVersion": "2025-06-18",
"toolCount": 60,
"toolCount": 61,
"tools": [
{
"name": "list_online_hosts",
@@ -462,6 +462,10 @@
"screenPreview": {
"description": "能否截屏(get_screenshot 的前提)",
"type": "boolean"
},
"windowInfo": {
"description": "是否支持窗口信息(get_foreground_window、host_list_windows 的坐标/前后台字段、operate_window/host_control_window 的 activate);仅声明 CLIENT_CAP_WINDOW_INFO 的新客户端为 true",
"type": "boolean"
}
},
"type": "object"
@@ -898,10 +902,11 @@
},
{
"name": "get_activity_history",
"description": "获取指定在线主机的历史活动记录(前台窗口驻留时长,每行一条「[时间] [标题] 时长」)。主连接 RPC。结果按 limit/offset 分页(默认 100 条、上限 1000),新在前:offset=0 就是最近 limit 条,想看更早的再往后翻。total 为本机现有记录总数,hasMore 表示还有更早的记录;客户端只保留最近 500 条,所以 total 最多约 501(含进行中的当前窗口)。",
"description": "获取指定在线主机的历史活动记录。Windows 与有桌面的 Linux 客户端返回前台窗口驻留记录,每行一条「[时间] [标题] 时长」;无桌面的 Linux 客户端返回登录记录与 shell 命令历史,每行带「[登录]」或「[命令]」标签(首行为「[来源]」说明)。主连接 RPC。结果按 limit/offset 分页(默认 100 条、上限 1000),新在前:offset=0 就是最近 limit 条,想看更早的再往后翻。total 为本机现有记录总数,hasMore 表示还有更早的记录;窗口后端只保留最近 500 条,所以 total 最多约 501(含进行中的当前窗口)。",
"gate": null,
"platforms": [
"win"
"win",
"lnx"
],
"impl": "mfc",
"inputSchema": {
@@ -1088,6 +1093,89 @@
"type": "object"
}
},
{
"name": "get_foreground_window",
"description": "获取指定在线 Windows 主机当前的前台窗口(GetForegroundWindow):标题、hwnd、pid、虚拟桌面坐标矩形、是否最小化/最大化、z 序与可见窗口总数。注入键鼠前先用它确认焦点在目标窗口上(remote_keyboard / remote_mouse 的 expect_hwnd 也可做同样的前置校验)。主连接 RPC、一次性返回;要求客户端能力位 CLIENT_CAP_WINDOW_INFO(新客户端),老客户端返回 -32005。只读。",
"gate": null,
"platforms": [
"win"
],
"impl": "mfc",
"inputSchema": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "主机 id,取 list_online_hosts / search_hosts 返回的 id 字段"
}
},
"required": [
"id"
]
},
"outputSchema": {
"type": "object",
"properties": {
"window": {
"type": [
"object",
"null"
],
"properties": {
"hwnd": {
"type": "integer"
},
"pid": {
"type": "integer"
},
"left": {
"type": "integer"
},
"top": {
"type": "integer"
},
"right": {
"type": "integer"
},
"bottom": {
"type": "integer"
},
"width": {
"type": "integer"
},
"height": {
"type": "integer"
},
"zOrder": {
"type": "integer"
},
"title": {
"type": "string"
},
"visible": {
"type": "boolean"
},
"minimized": {
"type": "boolean"
},
"maximized": {
"type": "boolean"
},
"isForeground": {
"type": "boolean"
}
}
},
"windowCount": {
"type": "integer"
}
},
"required": [
"window",
"windowCount"
]
}
},
{
"name": "list_files",
"description": "列举指定在线主机的目录。省略或空 path 返回驱动器列表(drives);给定 path 返回该目录一层内的文件/子目录(files,最多 500 条,含 name/isDir/size/mtime)。只读。",
@@ -2169,7 +2257,7 @@
},
{
"name": "remote_open",
"description": "在指定在线 Windows 或 Linux 主机上建立远程控制会话(隐藏屏幕子连接)并返回 session_id 与物理屏幕分辨率(screen_w/screen_h)。后续 remote_mouse/remote_keyboard 用归一化坐标(0..1)注入输入,用毕须 remote_close。Linux 需要 X11/Xorg(或 XWayland)桌面,纯 Wayland 会话无法抓屏/注入;多显示器暂不支持。",
"description": "在指定在线 Windows 或 Linux 主机上建立远程控制会话(隐藏屏幕子连接)并返回 session_id 与抓屏帧尺寸(screen_w/screen_h,可能是等比缩放后的整屏/整虚拟桌面像素)。后续 remote_mouse/remote_keyboard 用归一化坐标(0..1)注入输入,用毕须 remote_close。Linux 需要 X11/Xorg(或 XWayland)桌面,纯 Wayland 会话无法抓屏/注入;Windows 多显示器需要新版客户端(整虚拟桌面抓屏),老客户端会被拒绝(Linux 截屏/注入天然使用整个 X root,不受此限)。",
"gate": "remote_control",
"write": true,
"platforms": [
@@ -2196,11 +2284,11 @@
"outputSchema": {
"properties": {
"screen_h": {
"description": "物理屏幕高度(虚拟桌面像素)",
"description": "抓屏帧高度(发送帧像素)",
"type": "integer"
},
"screen_w": {
"description": "物理屏幕宽度(虚拟桌面像素),用于把归一化坐标 0..1 映射为像素",
"description": "抓屏帧宽度(发送帧像素:整屏或整虚拟桌面,可能已等比缩放),用于把归一化坐标 0..1 映射为像素",
"type": "integer"
},
"session_id": {
@@ -2258,7 +2346,7 @@
},
{
"name": "remote_keyboard",
"description": "向已建立的远程控制会话注入键盘事件。action 可选 key_down / key_up / key_press / type:前三种需 key(虚拟键名,如 ENTER/TAB/F5/LEFT/CTRL/ALT/SHIFT/WIN,Linux 侧映射为 X11 keysym),type 需 text(仅 ASCII 文本;非 ASCII 请用 remote_clipboard + Ctrl+V)。modifiers 可选(CTRL/ALT/SHIFT/WIN)。",
"description": "向已建立的远程控制会话注入键盘事件。action 可选 key_down / key_up / key_press / type:前三种需 key(虚拟键名,如 ENTER/TAB/F5/LEFT/CTRL/ALT/SHIFT/WIN,Linux 侧映射为 X11 keysym),type 需 text(仅 ASCII 文本;非 ASCII 请用 remote_clipboard + Ctrl+V)。modifiers 可选(CTRL/ALT/SHIFT/WIN)。可选 expect_hwnd:注入前先确认目标窗口仍在可见列表里(整数或 0x 字符串);配合 require_foreground=true 还要求它已是前台,否则不发注入返回 -32000;同时默认在结果里回报注入后的前台窗口(structuredContent.foreground),用于确认按键真的进了目标窗口。窗口校验仅新 Windows 客户端支持,其他客户端返回 -32005。",
"gate": "remote_control",
"write": true,
"platforms": [
@@ -2294,6 +2382,21 @@
"text": {
"description": "文本(type 用,仅 ASCII;非 ASCII 请走 remote_clipboard + Ctrl+V)",
"type": "string"
},
"expect_hwnd": {
"type": [
"integer",
"string"
],
"description": "可选:注入前先确认目标窗口仍在当前可见窗口列表中(整数或 0x 前缀字符串)。顺带默认回报前台窗口;仅新 Windows 客户端支持(否则 -32005)。"
},
"require_foreground": {
"type": "boolean",
"description": "可选:配合 expect_hwnd,要求该窗口已是前台,否则不发注入并返回 -32000。默认 false"
},
"report_foreground": {
"type": "boolean",
"description": "可选:注入后回报前台窗口(structuredContent.foreground)。给了 expect_hwnd 时默认 true"
}
},
"required": [
@@ -2304,13 +2407,29 @@
"type": "object"
},
"outputSchema": {
"properties": {},
"type": "object"
"type": "object",
"properties": {
"expectedWindow": {
"type": "object",
"description": "expect_hwnd 时注入前的目标窗口快照"
},
"foreground": {
"type": [
"object",
"null"
],
"description": "注入后的前台窗口(report_foreground 时返回;无前台窗口为 null)"
},
"foregroundError": {
"type": "string",
"description": "前台回报失败的原因(注入本身已成功)"
}
}
}
},
{
"name": "remote_mouse",
"description": "向已建立的远程控制会话注入鼠标事件。action 可选 move / down / up / click / right_click / middle_click / drag / scroll;坐标 x/y(及 drag 的 x2/y2)为归一化 0..1 浮点。button 可选 left/middle/right(默认 left);click 的 clicks 可选 1/2/3(默认 1);scroll 的 delta 正=向下滚、负=向上滚。",
"description": "向已建立的远程控制会话注入鼠标事件。action 可选 move / down / up / click / right_click / middle_click / drag / scroll;坐标 x/y(及 drag 的 x2/y2)为归一化 0..1 浮点。button 可选 left/middle/right(默认 left);click 的 clicks 可选 1/2/3(默认 1);scroll 的 delta 正=向下滚、负=向上滚。可选 expect_hwnd / require_foreground / report_foreground 与 remote_keyboard 同义(新 Windows 客户端),可用它确认点击确实落在目标窗口。",
"gate": "remote_control",
"write": true,
"platforms": [
@@ -2374,6 +2493,21 @@
"y2": {
"description": "拖拽终点 Y(仅 drag)",
"type": "number"
},
"expect_hwnd": {
"type": [
"integer",
"string"
],
"description": "可选:注入前先确认目标窗口仍在当前可见窗口列表中(整数或 0x 前缀字符串)。顺带默认回报前台窗口;仅新 Windows 客户端支持(否则 -32005)。"
},
"require_foreground": {
"type": "boolean",
"description": "可选:配合 expect_hwnd,要求该窗口已是前台,否则不发注入并返回 -32000。默认 false"
},
"report_foreground": {
"type": "boolean",
"description": "可选:注入后回报前台窗口(structuredContent.foreground)。给了 expect_hwnd 时默认 true"
}
},
"required": [
@@ -2386,8 +2520,24 @@
"type": "object"
},
"outputSchema": {
"properties": {},
"type": "object"
"type": "object",
"properties": {
"expectedWindow": {
"type": "object",
"description": "expect_hwnd 时注入前的目标窗口快照"
},
"foreground": {
"type": [
"object",
"null"
],
"description": "注入后的前台窗口(report_foreground 时返回;无前台窗口为 null)"
},
"foregroundError": {
"type": "string",
"description": "前台回报失败的原因(注入本身已成功)"
}
}
}
},
{
@@ -2781,7 +2931,7 @@
},
{
"name": "operate_window",
"description": "对指定在线 Windows 主机的窗口执行操作:close(关闭)/show(显示)/hide(隐藏)/minimize(最小化)/maximize(最大化)/restore(还原)。hwnd 取 list_windows 或 host_list_windows 返回的 hwnd。ok 仅表示已下发(窗口句柄可能已失效)。关闭窗口只有本工具能做,host_control_window 不提供 close,且它会重新枚举可见窗口复核结果。dry_run=true 只校验 hwnd 是否还在可见窗口列表里并返回该窗口信息,不发送任何命令。",
"description": "对指定在线 Windows 主机的窗口执行操作:close(关闭)/show(显示)/hide(隐藏)/minimize(最小化)/maximize(最大化)/restore(还原)/activate(激活到前台)。hwnd 取 list_windows 或 host_list_windows 返回的 hwnd。ok 仅表示已下发(窗口句柄可能已失效);action=activate 例外:工具会在动作后用窗口信息 RPC 复核 GetForegroundWindow,返回 ok/state(foreground|background|missing)/window,旧客户端不支持时返回 -32005(可退回 show)。关闭窗口只有本工具能做,host_control_window 不提供 close,且它会重新枚举可见窗口复核结果。dry_run=true 只校验 hwnd 是否还在可见窗口列表里并返回该窗口信息,不发送任何命令。",
"gate": "manage",
"write": true,
"platforms": [
@@ -2791,7 +2941,7 @@
"inputSchema": {
"properties": {
"action": {
"description": "操作:close(关闭) | show(显示) | hide(隐藏) | minimize(最小化) | maximize(最大化) | restore(还原)",
"description": "操作:close(关闭) | show(显示) | hide(隐藏) | minimize(最小化) | maximize(最大化) | restore(还原) | activate(激活到前台,需新客户端)",
"type": "string"
},
"dry_run": {
@@ -2824,12 +2974,27 @@
"type": "boolean"
},
"ok": {
"description": "命令已下发(不代表窗口已按预期变化)",
"description": "命令已下发(不代表窗口已按预期变化);action=activate 时为前台复核结果",
"type": "boolean"
},
"window": {
"description": "dry_run 时的目标窗口(hwnd/title/status/pid)",
"type": "object"
"description": "dry_run 时的目标窗口;action=activate 时为复核到的窗口快照(hwnd/title/pid/rect/flags 等),复核未找到为 null",
"type": [
"object",
"null"
]
},
"state": {
"type": "string",
"description": "action=activate 时的复核状态:foreground / background / missing / unknown"
},
"verifyError": {
"type": "string",
"description": "action=activate 且前台复核请求失败时的错误说明"
},
"truncated": {
"description": "为 true 时表示复核用的可见窗口列表被 96 条单次上限截断,未找到目标不代表窗口不存在(此时 state=unknown)",
"type": "boolean"
}
},
"type": "object"
@@ -3757,7 +3922,7 @@
},
{
"name": "host_list_windows",
"description": "列出在线 Windows 主机上当前可见的顶层窗口(主机管理「窗口」标签页)。只包含可见窗口,故隐藏后窗口会从结果中消失。hwnd 可用于 host_control_window 或 operate_window。首选:支持服务端过滤(pid / title),仅在它没有出现在 tools/list 里(McpMachine=0)时退回 list_windows。",
"description": "列出在线 Windows 主机上当前可见的顶层窗口(主机管理「窗口」标签页)。只包含可见窗口,故隐藏后窗口会从结果中消失;单次最多返回 96 条,可见窗口更多时 truncated=true 且列表不完整(不能据此断定某个窗口不存在)。hwnd 可用于 host_control_window 或 operate_window。首选:支持服务端过滤(pid / title),仅在它没有出现在 tools/list 里(McpMachine=0)时退回 list_windows。",
"gate": "machine",
"platforms": [
"win"
@@ -3839,7 +4004,7 @@
"type": "integer"
},
"hwnd": {
"description": "窗口句柄(十进制)",
"description": "窗口句柄(十进制;也可用作 host_control_window / operate_window 的 hwnd)",
"type": "integer"
},
"pid": {
@@ -3850,11 +4015,51 @@
},
"width": {
"type": "integer"
},
"left": {
"type": "integer",
"description": "窗口矩形左边界(屏幕坐标,可能为负,多显示器时常见)"
},
"top": {
"type": "integer",
"description": "窗口矩形上边界(屏幕坐标)"
},
"right": {
"type": "integer",
"description": "窗口矩形右边界(屏幕坐标,不含边界);width = right - left"
},
"bottom": {
"type": "integer",
"description": "窗口矩形下边界(屏幕坐标,不含边界);height = bottom - top"
},
"visible": {
"type": "boolean",
"description": "是否可见;当前列表只含可见窗口,故恒为 true"
},
"minimized": {
"type": "boolean",
"description": "是否最小化"
},
"maximized": {
"type": "boolean",
"description": "是否最大化"
},
"isForeground": {
"type": "boolean",
"description": "是否为当前前台窗口(全表最多一个 true)"
},
"zOrder": {
"type": "integer",
"description": "z 序,0 = 最顶层;数值越小越靠前"
}
},
"type": "object"
},
"type": "array"
},
"truncated": {
"description": "为 true 时表示客户端的可见窗口多于单次返回上限(96 条),列表不完整",
"type": "boolean"
}
},
"required": [
@@ -5355,7 +5560,7 @@
},
{
"name": "host_control_window",
"description": "对在线 Windows 主机的窗口执行可恢复操作:restore(还原)/hide(隐藏)/maximize(最大化)/minimize(最小化)。hwnd 取 host_list_windows 或 list_windows 返回的 hwnd。动作后重新枚举可见窗口复核:hide 后 hwnd 应消失,其余动作后仍应存在。不提供关闭窗口——需要 close / show 时改用 operate_window。dry_run=true 只核实 hwnd 并返回窗口信息。",
"description": "对在线 Windows 主机的窗口执行可恢复操作:restore(还原)/hide(隐藏)/maximize(最大化)/minimize(最小化)/activate(激活到前台)。hwnd 取 host_list_windows 或 list_windows 返回的 hwnd。动作后重新枚举可见窗口复核:hide 后 hwnd 应消失,其余动作后仍应存在;activate 会额外复核 GetForegroundWindow,目标未成为前台则 ok=false、reason=not_foreground。activate 需要新客户端(窗口信息能力),旧客户端返回 -32005,可退回 restore。不提供关闭窗口——需要 close / show 时改用 operate_window。dry_run=true 只核实 hwnd 并返回窗口信息。",
"gate": "machine",
"write": true,
"platforms": [
@@ -5365,12 +5570,13 @@
"inputSchema": {
"properties": {
"action": {
"description": "restore/hide/maximize/minimize",
"description": "restore/hide/maximize/minimize/activate",
"enum": [
"restore",
"hide",
"maximize",
"minimize"
"minimize",
"activate"
],
"type": "string"
},