Feature: Support remote clipboard and input on Android hosts
The MCP remote-control family (remote_open / remote_close / remote_mouse / remote_keyboard / remote_clipboard) previously stopped at Windows and Linux, even though the Android client already translated injected events into touch gestures and global actions. This wires up the missing piece and opens the five tools to APK hosts. Client side, the screen sub-connection now handles COMMAND_SCREEN_SET_CLIPBOARD: the native handler forwards the raw GBK bytes to CaptureService.onClipboardText, which decodes them, strips the trailing NUL that the human clipboard-sync senders append, and writes the system clipboard from a background app (allowed on Android 10+, only reads are restricted). Pasting cannot be a Ctrl+V combo, so VK_V is mapped to ACTION_PASTE on the focused node, falling back to the accessibility focus and then to the first editable node, since WebView and self-drawn inputs often do not flag FOCUS_INPUT or isEditable. A new capability bit CLIENT_CAP_SCREEN_CLIPBOARD (0x0800) tells the server the APK understands both paths, so builds without the handler get an explicit -32005 instead of a package that is silently dropped. action=type is rejected outright for APK hosts - physical key events would only turn 'v' into a paste - and the error points at remote_clipboard + key=V. The platform table, server instructions and the five tool descriptions now describe Android support, which keys actually act as global actions (ESC, HOME, APPS, PRINTSCREEN), and that injection needs the accessibility service while capture needs an authorized MediaProjection session, both without receipts. Verified on the API 35 emulator against a Debug server: ASCII and GBK Chinese text round-tripped through the clipboard into a focused Settings search field, type / expect_hwnd / window_hwnd returned -32005, and PRINTSCREEN produced a saved screenshot. check_platform_table.py and verify_tools.py --offline pass. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
ac43ad92ef
commit
0a0b709e8a
9 files changed
+351
-179
No files matched your search
@@ -329,8 +329,8 @@ const char* kServerInstructions =
|
||||
u8"5) 客户端平台差异\n"
|
||||
u8"工具能否执行取决于目标主机的平台,这与服务端开关无关,两者是叠加关系。调用前用 "
|
||||
u8"list_online_hosts / get_host_detail 的 capabilities.platform 确认,宁可先查一次,不要先试后错。\n"
|
||||
u8"支持面从宽到窄依次是 win > lnx > mac ≈ apk:Windows 是唯一全量支持的平台,Linux 次之,"
|
||||
u8"macOS 与 Android 只覆盖一部分。拿不准时按这个顺序假设。\n"
|
||||
u8"支持面从宽到窄依次是 win > lnx > apk ≈ mac:Windows 是唯一全量支持的平台,Linux 次之,"
|
||||
u8"Android 与 macOS 只覆盖一部分(Android 偏远程控制与截屏,macOS 偏文件与进程)。拿不准时按这个顺序假设。\n"
|
||||
u8"win(EXE / DLL / MEXE / SC / MDLL):全部工具可用。\n"
|
||||
u8"lnx(LNX):不支持服务、注册表、键日志、文件搜索/删除/移动/建目录、"
|
||||
u8"窗口列表(list_windows)与窗口信息(get_foreground_window)、网络连接列表与断开"
|
||||
@@ -346,7 +346,11 @@ const char* kServerInstructions =
|
||||
u8"apk(APK):支持主机列表(list_online_hosts / list_all_hosts)/ 详情 / 搜索 / "
|
||||
u8"审计日志 / 服务状态 / 会话管理、运行日志(get_client_log)、活动历史"
|
||||
u8"(get_activity_history,前台应用停留记录)、截屏(get_screenshot,只支持 mode=screen,"
|
||||
u8"要靠无障碍服务 takeScreenshot,Android 11+ 且开启无障碍才行),以及 "
|
||||
u8"要靠无障碍服务 takeScreenshot,Android 11+ 且开启无障碍才行),远程控制全族"
|
||||
u8"(remote_open / remote_close / remote_mouse / remote_keyboard / remote_clipboard,"
|
||||
u8"输入被翻译成触摸手势与 ESC(返回)/ HOME(桌面)/ APPS(任务列表)/ PRINTSCREEN(截屏)"
|
||||
u8"等全局动作,只支持整屏目标;注入依赖"
|
||||
u8"无障碍服务、抓屏依赖已授权录屏,两者都没有能力位可查,命令下发成功不代表生效),以及 "
|
||||
u8"host_set_remark / host_set_watch_level 这两个只改服务端本地数据的工具。其余一律不支持"
|
||||
u8"(客户端未实现 SYSTEM 与 SHELL)。\n"
|
||||
u8"copy_files_c2c 是唯一有方向性的工具:源端 src_id 必须是 win,目标端 dst_id 可以是 "
|
||||
@@ -1037,6 +1041,7 @@ Json::Value BuildHostDetailOutputSchema() {
|
||||
u8"仅声明 CLIENT_CAP_SCREEN_REGION 的新 Windows 客户端为 true");
|
||||
capProps["remoteControl"] = boolProp(
|
||||
u8"能否建立远程控制会话(remote_open/remote_mouse/remote_keyboard 的前提);"
|
||||
u8"Android 客户端只支持整屏目标,且需要已授权录屏与无障碍服务;"
|
||||
u8"还要求服务端 Web 远程服务已启动(WebSvrPort>0)");
|
||||
capProps["fileTransferV2"] = boolProp(u8"是否支持 V2 文件传输(download_file / upload_file 的前提)");
|
||||
capProps["c2cPaths"] = boolProp(u8"能否按路径清单接收另一台主机的文件(copy_files_c2c 源端的前提)");
|
||||
@@ -2509,13 +2514,14 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
}
|
||||
|
||||
// 15) remote_open / remote_close / remote_keyboard / remote_mouse / remote_clipboard
|
||||
// (P5:MCP 远程控制,Windows/Linux;Linux 需 X11 桌面,Wayland 纯会话不支持)
|
||||
// (P5:MCP 远程控制,Windows/Linux/Android;Linux 需 X11 桌面,Wayland 纯会话不支持;
|
||||
// Android 注入翻译成触摸手势与全局动作,只支持整屏目标)
|
||||
// 安全门:McpRemoteControl=1 且 McpReadonly=0;全程审计 + idle 回收)
|
||||
if (CMcpServer::Instance().IsRemoteControlEnabled() && !CMcpServer::Instance().IsReadonly()) {
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "remote_open";
|
||||
tool["description"] = u8"在指定在线 Windows 或 Linux 主机上建立远程控制会话(隐藏屏幕子连接)并返回 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 目标不依赖虚拟桌面抓屏,不受此限。";
|
||||
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["inputSchema"] = BuildRemoteOpenInputSchema();
|
||||
tool["outputSchema"] = BuildRemoteOpenOutputSchema();
|
||||
tools.append(tool);
|
||||
@@ -2531,7 +2537,7 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "remote_keyboard";
|
||||
tool["description"] = u8"向已建立的远程控制会话注入键盘事件。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。";
|
||||
tool["description"] = u8"向已建立的远程控制会话注入键盘事件。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。Android 主机没有键盘注入:只有 ESC(返回)/HOME(桌面)/APPS(任务列表)/PRINTSCREEN(截屏)这类全局动作、方向键(TV 主机)以及 key=V(粘贴当前剪贴板,需要新版 APK)生效,action=type 对 Android 直接返回 -32005,expect_hwnd 系列参数也返回 -32005;注入需要客户端开启无障碍服务,且没有回执(ok 只代表已下发)。";
|
||||
tool["inputSchema"] = BuildRemoteKeyboardInputSchema();
|
||||
tool["outputSchema"] = BuildRemoteKeyboardOutputSchema();
|
||||
tools.append(tool);
|
||||
@@ -2539,7 +2545,7 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "remote_mouse";
|
||||
tool["description"] = u8"向已建立的远程控制会话注入鼠标事件。action 可选 move / down / up / click / right_click / middle_click / drag / scroll;坐标 x/y(及 drag 的 x2/y2)为归一化 0..1 浮点,默认相对整屏/整虚拟桌面(remote_open 用 window_hwnd/region 时相对该目标帧)。给 window_hwnd 时改为相对「该窗口与虚拟桌面的交集」(窗口完整可见时即窗口本身;0=左/上边缘,1=右/下边缘),可直接照 get_screenshot mode=window 的图量比例:服务端用该交集与虚拟桌面矩形换算成屏幕坐标,并默认要求该窗口在前台(require_foreground=false 可显式关闭;与 expect_hwnd 同时给出时须指向同一窗口);会话本身已锁定窗口/区域时不要再传 window_hwnd。button 可选 left/middle/right(默认 left);click 的 clicks 可选 1/2/3(默认 1);scroll 的 delta 正=向下滚、负=向上滚。可选 expect_hwnd / require_foreground / report_foreground 与 remote_keyboard 同义(新 Windows 客户端),可用它确认点击确实落在目标窗口。";
|
||||
tool["description"] = u8"向已建立的远程控制会话注入鼠标事件。action 可选 move / down / up / click / right_click / middle_click / drag / scroll;坐标 x/y(及 drag 的 x2/y2)为归一化 0..1 浮点,默认相对整屏/整虚拟桌面(remote_open 用 window_hwnd/region 时相对该目标帧)。给 window_hwnd 时改为相对「该窗口与虚拟桌面的交集」(窗口完整可见时即窗口本身;0=左/上边缘,1=右/下边缘),可直接照 get_screenshot mode=window 的图量比例:服务端用该交集与虚拟桌面矩形换算成屏幕坐标,并默认要求该窗口在前台(require_foreground=false 可显式关闭;与 expect_hwnd 同时给出时须指向同一窗口);会话本身已锁定窗口/区域时不要再传 window_hwnd。button 可选 left/middle/right(默认 left);click 的 clicks 可选 1/2/3(默认 1);scroll 的 delta 正=向下滚、负=向上滚。可选 expect_hwnd / require_foreground / report_foreground 与 remote_keyboard 同义(新 Windows 客户端),可用它确认点击确实落在目标窗口。Android 主机把事件翻译成触摸:click=点按、right_click=长按、drag=滑动、scroll=上下滑,middle_click 无效果,down/up 单独使用无意义;window_hwnd 系列参数返回 -32005,注入需要客户端开启无障碍服务且没有回执(ok 只代表已下发)。";
|
||||
tool["inputSchema"] = BuildRemoteMouseInputSchema();
|
||||
tool["outputSchema"] = BuildRemoteMouseOutputSchema();
|
||||
tools.append(tool);
|
||||
@@ -2547,7 +2553,7 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "remote_clipboard";
|
||||
tool["description"] = u8"把文本写入远程主机的剪贴板(服务端按 GBK/ANSI 下发,Linux 客户端自动转回 UTF-8;非 GBK 字符如 emoji 会丢失)。仅设置剪贴板,粘贴需随后用 remote_keyboard 注入 Ctrl+V;Linux 需要 X11 桌面与 xclip/xsel。";
|
||||
tool["description"] = u8"把文本写入远程主机的剪贴板(服务端按 GBK/ANSI 下发,Linux 客户端自动转回 UTF-8,Android 客户端按 GBK 解码;非 GBK 字符如 emoji 会丢失)。仅设置剪贴板,粘贴需随后用 remote_keyboard 注入 Ctrl+V;Linux 需要 X11 桌面与 xclip/xsel,Android 用 remote_keyboard 的 key=V(粘贴到当前焦点输入框,需要新版 APK;粘贴依赖无障碍服务)。";
|
||||
tool["inputSchema"] = BuildRemoteClipboardInputSchema();
|
||||
tool["outputSchema"] = BuildRemoteClipboardOutputSchema();
|
||||
tools.append(tool);
|
||||
@@ -2924,11 +2930,12 @@ void AppendHostTechnicalDetail(CMy2015RemoteDlg* parent, uint64_t devId, Json::V
|
||||
caps["screenPreview"] = ctx->SupportsScreenPreview();
|
||||
// screenRegion → get_screenshot 的 region/window/monitor 模式(SupportsScreenCapture)
|
||||
caps["screenRegion"] = ctx->SupportsScreenCapture();
|
||||
// 远程控制只实现于 Windows / Linux;多显示器还要求观察与注入同源:
|
||||
// Windows 需声明整虚拟桌面抓屏能力,Linux 的 root 抓屏/注入天然一致。
|
||||
// 远程控制:Windows / Linux / Android 客户端都实现了注入(Android 把事件翻译成触摸
|
||||
// 手势与全局动作);多显示器还要求观察与注入同源:Windows 需声明整虚拟桌面抓屏能力,
|
||||
// Linux 的 root 抓屏/注入天然一致,Android 抓屏与注入都用整屏坐标。
|
||||
// monitorCount=0(老客户端没报格式)无法判定,与 remote_open 一样按放行处理。
|
||||
bool virtDesktopOk = monitorCount <= 1 || !IsWindowsClient(ctx) || ctx->SupportsVirtualDesktop();
|
||||
caps["remoteControl"] = (IsWindowsClient(ctx) || clientType == "LNX") && virtDesktopOk;
|
||||
caps["remoteControl"] = (IsWindowsClient(ctx) || clientType == "LNX" || clientType == "APK") && virtDesktopOk;
|
||||
caps["fileTransferV2"] = ctx->SupportsFileV2();
|
||||
caps["c2cPaths"] = ctx->SupportsC2CPaths();
|
||||
caps["registry"] = IsWindowsClient(ctx);
|
||||
@@ -5056,7 +5063,7 @@ static bool ResolveScreenCtrlSessionHost(const Json::Value& id, const Json::Valu
|
||||
|
||||
CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
|
||||
if (clientType == "MAC") {
|
||||
errJson = BuildError(id, -32005, "Remote control is only supported on Windows and Linux hosts");
|
||||
errJson = BuildError(id, -32005, "Remote control is only supported on Windows, Linux and Android hosts");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -5911,6 +5918,11 @@ std::string BuildRemoteKeyboard(const Json::Value& id, const Json::Value& args,
|
||||
// 组装注入批次(按发送顺序)
|
||||
std::vector<MSG64> batch;
|
||||
if (action == "type") {
|
||||
// Android 没有文本注入:type 发的是物理键事件,字符 'v' 会变成 VK_V(本客户端
|
||||
// 映射为「粘贴」),其余字符无动作。整条拒绝,别让调用方以为文本被敲进去了。
|
||||
if (ctx->GetAdditionalData(RES_CLIENT_TYPE) == "APK")
|
||||
return BuildError(id, -32005, "Android clients cannot type text; "
|
||||
"use remote_clipboard + key=V, or the global-action keys (ESC/HOME/APPS/PRINTSCREEN)");
|
||||
if (text.empty())
|
||||
return BuildError(id, -32602, "Missing required parameter: text");
|
||||
if (!IsAscii(text))
|
||||
@@ -5924,6 +5936,10 @@ std::string BuildRemoteKeyboard(const Json::Value& id, const Json::Value& args,
|
||||
int keyVk = MapKeyNameToVk(keyName);
|
||||
if (keyVk == 0)
|
||||
return BuildError(id, -32602, "Unknown key: " + keyName);
|
||||
// key=V 的粘贴映射只有新版 APK 才有;老 APK 收到 VK_V 不会动作
|
||||
if (keyVk == 'V' && ctx->GetAdditionalData(RES_CLIENT_TYPE) == "APK" && !ctx->SupportsScreenClipboard())
|
||||
return BuildError(id, -32005, "Android client is too old for key=V paste: the APK has no paste mapping, "
|
||||
"upgrade the client first");
|
||||
bool doDown = (action != "key_up");
|
||||
bool doUp = (action != "key_down");
|
||||
if (doDown) {
|
||||
@@ -6548,6 +6564,12 @@ std::string BuildRemoteClipboard(const Json::Value& id, const Json::Value& args,
|
||||
if (sessionId.empty())
|
||||
return BuildError(id, -32602, "Missing required parameter: session_id");
|
||||
|
||||
// 老 APK 的屏幕子连接没有 COMMAND_SCREEN_SET_CLIPBOARD 分支,包会被静默丢弃;
|
||||
// 用它声明的能力位提前拒绝,避免调用方把「已下发」当成「已写入」。
|
||||
if (ctx->GetAdditionalData(RES_CLIENT_TYPE) == "APK" && !ctx->SupportsScreenClipboard())
|
||||
return BuildError(id, -32005, "Android client is too old for remote_clipboard: "
|
||||
"the APK has no clipboard handler, upgrade the client first");
|
||||
|
||||
std::string text = GetStringArg(args, "text");
|
||||
if (text.empty())
|
||||
return BuildError(id, -32602, "Missing required parameter: text");
|
||||
@@ -9951,16 +9973,18 @@ const ToolPlatform kToolPlatforms[] = {
|
||||
{ "get_client_log", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
{ "download_file", kPlatWin|kPlatLnx|kPlatMac },
|
||||
{ "upload_file", kPlatWin|kPlatLnx|kPlatMac },
|
||||
// ---- win+lnx ---- 远程控制全族 + 需 SCREEN_PREVIEW 的截屏 + macOS 未开放项
|
||||
// ---- win+lnx(+apk) ---- 远程控制全族 + 需 SCREEN_PREVIEW 的截屏 + macOS 未开放项
|
||||
// Android 用无障碍 takeScreenshot(API 30+,需开无障碍服务),只支持 mode=screen
|
||||
{ "get_screenshot", kPlatWin|kPlatLnx|kPlatApk },
|
||||
// 窗口信息 RPC 只在 Windows 客户端实现(CLIENT_CAP_WINDOW_INFO)
|
||||
{ "get_foreground_window", kPlatWin },
|
||||
{ "remote_open", kPlatWin|kPlatLnx },
|
||||
{ "remote_close", kPlatWin|kPlatLnx },
|
||||
{ "remote_keyboard", kPlatWin|kPlatLnx },
|
||||
{ "remote_mouse", kPlatWin|kPlatLnx },
|
||||
{ "remote_clipboard", kPlatWin|kPlatLnx },
|
||||
// Android 客户端把注入翻译成触摸手势 / 全局动作(android/.../ControlService.kt),
|
||||
// 剪贴板走 CaptureService.onClipboardText;window_hwnd/region 目标仍只有 Windows 支持
|
||||
{ "remote_open", kPlatWin|kPlatLnx|kPlatApk },
|
||||
{ "remote_close", kPlatWin|kPlatLnx|kPlatApk },
|
||||
{ "remote_keyboard", kPlatWin|kPlatLnx|kPlatApk },
|
||||
{ "remote_mouse", kPlatWin|kPlatLnx|kPlatApk },
|
||||
{ "remote_clipboard", kPlatWin|kPlatLnx|kPlatApk },
|
||||
// macOS 客户端有 PTY 实现(macos/main.mm:753),但服务端刻意不开放
|
||||
// (McpServer.cpp:3652「macOS 本轮不开放」),故实际不可用
|
||||
{ "exec_command", kPlatWin|kPlatLnx },
|
||||
|
||||
Reference in new issue
Block a user