Fix(mcp): bound host_inspect, precheck remote_open, name the busy holder
Three smaller contract fixes that remove ways for an agent call to hang or fail without an explanation: - host_inspect with several aspects opens one sub-connection per aspect (5s ready + 12s list each), so all ten could run ~170s and outlive the caller's HTTP timeout. After 60s no new aspect is started; the running one finishes on its own timeout and the skipped ones land in errors.<aspect> with code -32001 and a "skipped:" message, so the model can retry with fewer aspects. - remote_open checked nothing before opening the hidden screen session. A Linux host that declares capability bits but not CLIENT_CAP_SCREEN_PREVIEW has no X11 display, so capture and injection cannot work: return -32005 immediately instead of waiting out timeout_ms and then reporting a sub-connection timeout. Android is deliberately excluded -- its SCREEN_PREVIEW bit tracks accessibility (API 30+ takeScreenshot for get_screenshot), while remote control uses MediaProjection capture and dispatchGesture, which can work without it. Old hosts with empty caps are still let through. - The -32003 busy errors in remote_open now append the DescribeBusy suffix (tool, elapsed), matching the other busy paths. tools.json descriptions are kept byte-identical to the C++ literals. Debug build green; check_platform_table, gen_go_tools --check and go test ./... pass. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
d49ebe521d
commit
61b9031269
3 files changed
+46
-7
No files matched your search
@@ -2579,7 +2579,7 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "remote_open";
|
||||
tool["description"] = u8"在指定在线 Windows、Linux 或 Android 主机上建立远程控制会话(隐藏屏幕子连接)并返回 session_id、抓屏帧尺寸(screen_w/screen_h)与目标(target)。默认推整屏/整虚拟桌面(可能等比缩放);可用 window_hwnd 只推一个窗口,或用 region 只推一个矩形区域,带宽、延迟和点击精度都更好,此时归一化坐标 0..1 相对该目标帧。后续 remote_mouse/remote_keyboard 用归一化坐标(0..1)注入输入,用毕须 remote_close。Linux 需要 X11/Xorg(或 XWayland)桌面,纯 Wayland 会话无法抓屏/注入;window_hwnd/region 仅支持声明 CLIENT_CAP_WINDOW_INFO 的新 Windows 客户端。Windows 多显示器下整屏目标需要新版客户端(整虚拟桌面抓屏),老客户端会被拒绝;window 目标不依赖虚拟桌面抓屏,不受此限。Android 主机只支持整屏目标,输入被翻译成触摸手势与全局动作(见 remote_mouse / remote_keyboard);抓屏依赖客户端已授权录屏(MediaProjection),未授权时 remote_open 会一直等不到屏幕子连接,注入还依赖无障碍服务在跑(未开启时命令照样下发但不生效,且没有回执)。";
|
||||
tool["description"] = u8"在指定在线 Windows、Linux 或 Android 主机上建立远程控制会话(隐藏屏幕子连接)并返回 session_id、抓屏帧尺寸(screen_w/screen_h)与目标(target)。默认推整屏/整虚拟桌面(可能等比缩放);可用 window_hwnd 只推一个窗口,或用 region 只推一个矩形区域,带宽、延迟和点击精度都更好,此时归一化坐标 0..1 相对该目标帧。后续 remote_mouse/remote_keyboard 用归一化坐标(0..1)注入输入,用毕须 remote_close。Linux 需要 X11/Xorg(或 XWayland)桌面,纯 Wayland 会话无法抓屏/注入(这类主机直接返回 -32005);window_hwnd/region 仅支持声明 CLIENT_CAP_WINDOW_INFO 的新 Windows 客户端。Windows 多显示器下整屏目标需要新版客户端(整虚拟桌面抓屏),老客户端会被拒绝;window 目标不依赖虚拟桌面抓屏,不受此限。Android 主机只支持整屏目标,输入被翻译成触摸手势与全局动作(见 remote_mouse / remote_keyboard);抓屏依赖客户端已授权录屏(MediaProjection),未授权时 remote_open 会一直等不到屏幕子连接,注入还依赖无障碍服务在跑(未开启时命令照样下发但不生效,且没有回执)。";
|
||||
tool["inputSchema"] = BuildRemoteOpenInputSchema();
|
||||
tool["outputSchema"] = BuildRemoteOpenOutputSchema();
|
||||
tools.append(tool);
|
||||
@@ -5578,6 +5578,21 @@ std::string BuildRemoteOpen(const Json::Value& id, const Json::Value& args, CMy2
|
||||
if (!ResolveScreenCtrlSessionHost(id, args, parent, devId, ctx, errJson))
|
||||
return errJson;
|
||||
|
||||
// 能力位前置:Linux 的抓屏与注入都走 X11(Xorg/XWayland),客户端只在 DISPLAY 可用时
|
||||
// 才在登录里声明 CLIENT_CAP_SCREEN_PREVIEW;声明了能力位(非空 caps)却没有这一位,
|
||||
// 说明是纯 Wayland/无 X11 的会话,抓不到帧也注入不了——提前返回 -32005,免得白等
|
||||
// timeout_ms 再报「子连接超时」,还留下一次 web-triggered 标记的清理。老客户端
|
||||
// (caps 为空)无从判定,与多显示器门一样按放行处理(老的 COMMAND_SCREEN_SPY 链路仍可用)。
|
||||
// Android 不能套这个门:APK 的 SCREEN_PREVIEW 位只代表 API 30+ 且无障碍在运行(用于
|
||||
// get_screenshot 的 takeScreenshot),而远程控制抓屏走 MediaProjection、注入走
|
||||
// dispatchGesture——没有这一位的主机远程控制仍可能可用。
|
||||
CString hostClientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
|
||||
const bool declaresCaps = !ctx->GetClientData(ONLINELIST_CAPABILITIES).IsEmpty();
|
||||
if (declaresCaps && hostClientType == "LNX" && !ctx->SupportsScreenPreview())
|
||||
return BuildError(id, -32005,
|
||||
"Remote control requires screen preview capability (X11/Xorg desktop on Linux); "
|
||||
"this host does not declare it");
|
||||
|
||||
// ---- 帧目标(可选):window_hwnd 只推窗口,region 只推矩形;缺省推整屏/整虚拟桌面 ----
|
||||
uint32_t windowHwnd = 0;
|
||||
bool hasWindow = false;
|
||||
@@ -5675,7 +5690,8 @@ std::string BuildRemoteOpen(const Json::Value& id, const Json::Value& args, CMy2
|
||||
|
||||
// 与人类远程桌面观看互斥:已有屏幕子连接(web 观看)→ 拒绝,避免向人类正在看的画面注入。
|
||||
if (WebService().HasActiveSession(devId))
|
||||
return BuildError(id, -32003, "Device busy: a remote desktop session is already active for this host");
|
||||
return BuildError(id, -32003, BusyMessage(
|
||||
"Device busy: a remote desktop session is already active for this host", devId));
|
||||
|
||||
int timeoutMs = CMcpServer::Instance().ToolTimeoutMs();
|
||||
int v = 0;
|
||||
@@ -5683,7 +5699,8 @@ std::string BuildRemoteOpen(const Json::Value& id, const Json::Value& args, CMy2
|
||||
|
||||
std::string sessionId = GenerateRandomToken();
|
||||
if (!mcp.BeginScreenCtrlOpen(devId, sessionId))
|
||||
return BuildError(id, -32003, "Device busy: a remote control session is already active for this host");
|
||||
return BuildError(id, -32003, BusyMessage(
|
||||
"Device busy: a remote control session is already active for this host", devId));
|
||||
|
||||
// 失败清理:会话 + 隐藏对话框 + web-triggered 标记(StartRemoteDesktop 先置标记再发送)。
|
||||
auto abortOpen = [&]() {
|
||||
|
||||
Reference in new issue
Block a user