Feature(mcp): unify window and service controls behind one name per state

operate_window / host_control_window and control_service / host_control_service were two
implementations of the same intent. tools/list now exposes exactly one of each pair,
chosen by McpMachine: the host_control_* names when host management is enabled, the
main-connection names when it is not.

The advertised tool accepts the union of actions. host_control_window routes close/show
to the main-connection implementation, which stays the only path with close/show
semantics and requires McpManage; the machine path keeps its post-action verification
for restore/hide/maximize/minimize/activate. host_control_service routes
set_auto/set_manual the same way and rejects dry_run for them instead of pretending to
run one. Both old names remain callable aliases, and service_name is accepted as an
alias for the machine tool's name parameter.

The manifest generator treats the two main-connection tools as !machine entries, so the
two-capture union still covers both states. tools/list is 49 entries when everything is
on (was 51) and 47 when host management is off; the response shrinks from 193,008 B to
168,634 B (-12.6%), short of the 15% estimate because state-conditional tools must stay
in the manifest. The plan document records that measurement and the reason.

Verified with a dedicated two-state test: visibility matrix, close/show and
set_auto/set_manual routing through dry_run and validation paths, alias dispatch, and
-32006 for host_* names when host management is off. Step 8a/8b regressions and
verify_tools --live still pass.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-12 17:40:51 +01:00
1 parent c73db530f4
commit 5841f27df9
5 files changed
+218 -141

No files matched your search

+129 -120
View File
@@ -2672,117 +2672,6 @@
"type": "object"
}
},
{
"name": "operate_window",
"description": "对指定在线 Windows 主机的窗口执行操作:close(关闭)/show(显示)/hide(隐藏)/minimize(最小化)/maximize(最大化)/restore(还原)/activate(激活到前台)。hwnd 取 list_windows 或 host_inspect 的 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": [
"win"
],
"impl": "mfc",
"inputSchema": {
"properties": {
"action": {
"description": "操作:close(关闭) | show(显示) | hide(隐藏) | minimize(最小化) | maximize(最大化) | restore(还原) | activate(激活到前台,需新客户端)",
"type": "string"
},
"dry_run": {
"description": "true 时只校验窗口是否还存在并返回将被影响的对象,不发送任何窗口命令(默认 false)",
"type": "boolean"
},
"hwnd": {
"description": "窗口句柄,取 list_windows 返回的 hwnd 字段",
"type": "integer"
},
"id": {
"description": "主机 id,取 list_hosts 返回的 id 字段",
"type": "string"
}
},
"required": [
"id",
"hwnd",
"action"
],
"type": "object"
},
"outputSchema": {
"properties": {
"action": {
"type": "string"
},
"dry_run": {
"description": "true 表示本次只是试运行(dry_run),没有发送窗口命令",
"type": "boolean"
},
"ok": {
"description": "命令已下发(不代表窗口已按预期变化);action=activate 时为前台复核结果",
"type": "boolean"
},
"state": {
"description": "action=activate 时的复核状态:foreground / background / missing / unknown",
"type": "string"
},
"truncated": {
"description": "为 true 时表示复核用的可见窗口列表被 96 条单次上限截断,未找到目标不代表窗口不存在(此时 state=unknown)",
"type": "boolean"
},
"verifyError": {
"description": "action=activate 且前台复核请求失败时的错误说明",
"type": "string"
},
"window": {
"description": "dry_run 时的目标窗口;action=activate 时为复核到的窗口快照(hwnd/title/pid/rect/flags 等),复核未找到为 null",
"type": [
"object",
"null"
]
}
},
"type": "object"
}
},
{
"name": "control_service",
"description": "控制指定在线 Windows 主机的服务:start(启动)/stop(停止)/set_auto(设为自动)/set_manual(设为手动)。service_name 取 list_services 返回的 service_name。ok 仅表示已下发(成功与否需再查 list_services 核对状态)。",
"gate": "manage",
"write": true,
"platforms": [
"win"
],
"impl": "mfc",
"inputSchema": {
"properties": {
"action": {
"description": "操作:start(启动) | stop(停止) | set_auto(设为自动) | set_manual(设为手动)",
"type": "string"
},
"id": {
"description": "主机 id,取 list_hosts 返回的 id 字段",
"type": "string"
},
"service_name": {
"description": "服务名,取 list_services 返回的 service_name 字段",
"type": "string"
}
},
"required": [
"id",
"service_name",
"action"
],
"type": "object"
},
"outputSchema": {
"properties": {
"ok": {
"type": "boolean"
}
},
"type": "object"
}
},
{
"name": "power_action",
"description": "对指定在线 Windows 主机执行电源操作:logout(注销)/shutdown(关机)/reboot(重启)。不可撤销,主机将立即下线;需客户端管理员权限。ok/sent 只代表命令已送达,不代表真的关了机:要验证就给 wait=true,工具会等主机从在线列表消失(went_offline)、再等它重新上线(came_back),并返回 elapsed_ms;每个阶段最多等 wait_ms(默认 60000),等不到不算失败。注销后客户端一般不会自动回线。",
@@ -4419,7 +4308,7 @@
},
{
"name": "host_control_window",
"description": "对在线 Windows 主机的窗口执行可恢复操作:restore(还原)/hide(隐藏)/maximize(最大化)/minimize(最小化)/activate(激活到前台)。hwnd 取 host_inspect 的 windows 项或 list_windows 返回的 hwnd。动作后重新枚举可见窗口复核:hide 后 hwnd 应消失,其余动作后仍应存在;activate 会额外复核 GetForegroundWindow,目标未成为前台则 ok=false、reason=not_foreground。activate 需要新客户端(窗口信息能力),旧客户端返回 -32005,可退回 restore。不提供关闭窗口——需要 close / show 时改用 operate_window。dry_run=true 只核实 hwnd 并返回窗口信息。",
"description": "对在线 Windows 主机的窗口执行操作:restore(还原)/hide(隐藏)/maximize(最大化)/minimize(最小化)/activate(激活到前台)/close(关闭)/show(显示)。hwnd 取 host_inspect 的 windows 项或 list_windows 返回的 hwnd。restore 等五个动作走主机管理链路,动作后重新枚举可见窗口复核:hide 后 hwnd 应消失,其余动作后仍应存在;activate 会额外复核 GetForegroundWindow,目标未成为前台则 ok=false、reason=not_foreground,且需要新客户端(窗口信息能力),旧客户端返回 -32005,可退回 restore。close/show 没有主机管理实现,转由主连接版 operate_window 处理(因此动作后不复核,ok 只表示已下发;McpManage=0 时返回 -32006)——它们只在 McpMachine=0 时才以 operate_window 之名出现在 tools/list。dry_run=true 只核实 hwnd 并返回窗口信息,不下发动作。",
"gate": "machine",
"write": true,
"platforms": [
@@ -4429,13 +4318,15 @@
"inputSchema": {
"properties": {
"action": {
"description": "restore/hide/maximize/minimize/activate",
"description": "restore/hide/maximize/minimize/activate,以及 close/show(转主连接实现,需 McpManage=1)",
"enum": [
"restore",
"hide",
"maximize",
"minimize",
"activate"
"activate",
"close",
"show"
],
"type": "string"
},
@@ -4511,7 +4402,7 @@
},
{
"name": "host_control_service",
"description": "控制在线 Windows 主机的服务:start/stop/pause/continue/restart。客户端对每次控制都会自动回一份刷新后的服务列表,工具据此复核状态并如实返回 ok;stop 与 restart 归入危险操作,需要同时开启 McpMachineDangerous。restart 先 stop 再 start。不提供删除服务。dry_run=true 只核实服务并返回当前状态,不下发命令(是否已是目标状态由你按 state 判断)。",
"description": "控制在线 Windows 主机的服务:start/stop/pause/continue/restart/set_auto/set_manual。start 等五个动作走主机管理链路:客户端对每次控制都会自动回一份刷新后的服务列表,工具据此复核状态并如实返回 ok;stop 与 restart 归入危险操作,需要同时开启 McpMachineDangerous;restart 先 stop 再 start。set_auto/set_manual 没有主机管理实现,转由主连接版 control_service 处理(ok 只表示已下发、需另查状态;McpManage=0 时返回 -32006)——它们只在 McpMachine=0 时才以 control_service 之名出现在 tools/list。不提供删除服务。dry_run=true 只核实服务并返回当前状态,不下发命令(是否已是目标状态由你按 state 判断);set_auto/set_manual 不支持 dry_run(返回 -32602)。",
"gate": "machine",
"write": true,
"platforms": [
@@ -4521,13 +4412,15 @@
"inputSchema": {
"properties": {
"action": {
"description": "start/stop/pause/continue/restart",
"description": "start/stop/pause/continue/restart,以及 set_auto/set_manual(转主连接实现,需 McpManage=1)",
"enum": [
"start",
"stop",
"pause",
"continue",
"restart"
"restart",
"set_auto",
"set_manual"
],
"type": "string"
},
@@ -4540,14 +4433,17 @@
"type": "string"
},
"name": {
"description": "服务名(ServiceName,不是显示名),取 host_inspect 的 win32_services / driver_services 项的 name",
"description": "服务名(ServiceName,不是显示名),取 host_inspect 的 win32_services / driver_services 项的 name;与 service_name 二选一",
"type": "string"
},
"service_name": {
"description": "name 的旧参数名别名(与 name 等价,二选一)",
"type": "string"
}
},
"required": [
"id",
"action",
"name"
"action"
],
"type": "object"
},
@@ -5377,6 +5273,119 @@
],
"type": "object"
}
},
{
"name": "operate_window",
"description": "对指定在线 Windows 主机的窗口执行操作:close(关闭)/show(显示)/hide(隐藏)/minimize(最小化)/maximize(最大化)/restore(还原)/activate(激活到前台)。hwnd 取 list_windows 或 host_inspect 的 windows 项返回的 hwnd。ok 仅表示已下发(窗口句柄可能已失效);action=activate 例外:工具会在动作后用窗口信息 RPC 复核 GetForegroundWindow,返回 ok/state(foreground|background|missing)/window,旧客户端不支持时返回 -32005(可退回 show)。仅在 McpMachine=0(主机管理工具关闭)时出现在 tools/list;开启后请用 host_control_window,它也接受 close/show。dry_run=true 只校验 hwnd 是否还在可见窗口列表里并返回该窗口信息,不发送任何命令。",
"gate": "!machine",
"write": true,
"manage": true,
"platforms": [
"win"
],
"impl": "mfc",
"inputSchema": {
"properties": {
"action": {
"description": "操作:close(关闭) | show(显示) | hide(隐藏) | minimize(最小化) | maximize(最大化) | restore(还原) | activate(激活到前台,需新客户端)",
"type": "string"
},
"dry_run": {
"description": "true 时只校验窗口是否还存在并返回将被影响的对象,不发送任何窗口命令(默认 false)",
"type": "boolean"
},
"hwnd": {
"description": "窗口句柄,取 list_windows 返回的 hwnd 字段",
"type": "integer"
},
"id": {
"description": "主机 id,取 list_hosts 返回的 id 字段",
"type": "string"
}
},
"required": [
"id",
"hwnd",
"action"
],
"type": "object"
},
"outputSchema": {
"properties": {
"action": {
"type": "string"
},
"dry_run": {
"description": "true 表示本次只是试运行(dry_run),没有发送窗口命令",
"type": "boolean"
},
"ok": {
"description": "命令已下发(不代表窗口已按预期变化);action=activate 时为前台复核结果",
"type": "boolean"
},
"state": {
"description": "action=activate 时的复核状态:foreground / background / missing / unknown",
"type": "string"
},
"truncated": {
"description": "为 true 时表示复核用的可见窗口列表被 96 条单次上限截断,未找到目标不代表窗口不存在(此时 state=unknown)",
"type": "boolean"
},
"verifyError": {
"description": "action=activate 且前台复核请求失败时的错误说明",
"type": "string"
},
"window": {
"description": "dry_run 时的目标窗口;action=activate 时为复核到的窗口快照(hwnd/title/pid/rect/flags 等),复核未找到为 null",
"type": [
"object",
"null"
]
}
},
"type": "object"
}
},
{
"name": "control_service",
"description": "控制指定在线 Windows 主机的服务:start(启动)/stop(停止)/set_auto(设为自动)/set_manual(设为手动)。service_name 取 list_services 返回的 service_name。ok 仅表示已下发(成功与否需再查 list_services 核对状态)。仅在 McpMachine=0(主机管理工具关闭)时出现在 tools/list;开启后请用 host_control_service,它也接受 set_auto/set_manual。",
"gate": "!machine",
"write": true,
"manage": true,
"platforms": [
"win"
],
"impl": "mfc",
"inputSchema": {
"properties": {
"action": {
"description": "操作:start(启动) | stop(停止) | set_auto(设为自动) | set_manual(设为手动)",
"type": "string"
},
"id": {
"description": "主机 id,取 list_hosts 返回的 id 字段",
"type": "string"
},
"service_name": {
"description": "服务名,取 list_services 返回的 service_name 字段",
"type": "string"
}
},
"required": [
"id",
"service_name",
"action"
],
"type": "object"
},
"outputSchema": {
"properties": {
"ok": {
"type": "boolean"
}
},
"type": "object"
}
}
]
}