Feature(mcp): merge the three host-list tools into list_hosts
list_online_hosts, search_hosts and list_all_hosts differed only in whether offline hosts were included and in which filter fields they accepted, which made the host-list surface confusing and duplicated three handlers over the same CollectAllHosts snapshot. They now share one tool, list_hosts(query?, online?=true, include_offline?=false, group?, os?, client_type?, limit?, offset?). The old names stay as aliases routed to the same handler, so existing callers keep working, but tools/list exposes only list_hosts. The legacy "offline" boolean of list_all_hosts is still honored, and list_all_hosts keeps its online+offline default. With offline history included the list is now ordered online-first: the host library holds thousands of records, so the default page of 100 would otherwise be all stale entries and the online hosts a caller can actually operate on would be buried behind paging. instructions, every id-description string, the platform table, the tools.json generator and the captured mcp/tools.json are updated to the new name (65 tools -> 63). Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
613aa7291a
commit
88269df548
3 files changed
+191
-481
No files matched your search
+143
-200
@@ -277,7 +277,7 @@ const char* kServerInstructions =
|
||||
u8"\n"
|
||||
u8"1) 主机 id\n"
|
||||
u8"id 是 64 位无符号十进制字符串,由服务端分配,无法从 IP 或计算机名推算,不要猜测、也不要把示例值当真。"
|
||||
u8"需要 id 时先用 list_online_hosts(仅在线)或 list_all_hosts(含离线)取得;离线主机除 "
|
||||
u8"需要 id 时先用 list_hosts 取得(默认只列在线;include_offline=true 连离线一起列);离线主机除 "
|
||||
u8"host_set_remark、host_set_watch_level 外都不能操作。拿不到 id 就向用户确认。\n"
|
||||
u8"\n"
|
||||
u8"2) 工具的可见性与开关\n"
|
||||
@@ -335,7 +335,7 @@ const char* kServerInstructions =
|
||||
u8"\n"
|
||||
u8"5) 客户端平台差异\n"
|
||||
u8"工具能否执行取决于目标主机的平台,这与服务端开关无关,两者是叠加关系。调用前用 "
|
||||
u8"list_online_hosts / get_host_detail 的 capabilities.platform 确认,宁可先查一次,不要先试后错。\n"
|
||||
u8"list_hosts / get_host_detail 的 capabilities.platform 确认,宁可先查一次,不要先试后错。\n"
|
||||
u8"支持面从宽到窄依次是 win > lnx > apk ≈ mac:Windows 是唯一全量支持的平台,Linux 次之,"
|
||||
u8"Android 与 macOS 只覆盖一部分(Android 偏远程控制与截屏,macOS 偏文件与进程)。拿不准时按这个顺序假设。\n"
|
||||
u8"win(EXE / DLL / MEXE / SC / MDLL):全部工具可用。\n"
|
||||
@@ -350,7 +350,7 @@ const char* kServerInstructions =
|
||||
u8"exec_command、terminal_open / terminal_exec / terminal_close"
|
||||
u8"(客户端有 PTY 实现,但服务端本轮未开放)、kill_process、http_probe;"
|
||||
u8"文件传输、进程列表、日志可用。\n"
|
||||
u8"apk(APK):支持主机列表(list_online_hosts / list_all_hosts)/ 详情 / 搜索 / "
|
||||
u8"apk(APK):支持主机列表(list_hosts)/ 详情 / 搜索 / "
|
||||
u8"审计日志 / 服务状态 / 会话管理、运行日志(get_client_log)、活动历史"
|
||||
u8"(get_activity_history,前台应用停留记录)、截屏(get_screenshot,只支持 mode=screen,"
|
||||
u8"要靠无障碍服务 takeScreenshot,Android 11+ 且开启无障碍才行),远程控制全族"
|
||||
@@ -916,8 +916,8 @@ void CollectAllHosts(CMy2015RemoteDlg* parent, Json::Value& hosts,
|
||||
LeaveCriticalSection(&parent->m_cs);
|
||||
}
|
||||
|
||||
// ===== C3:list_online_hosts / list_all_hosts 的公共过滤 =====
|
||||
// 口径与 search_hosts 一致:条件都可选、AND 组合、子串匹配、ASCII 不区分大小写。
|
||||
// ===== C3:list_hosts 的公共过滤 =====
|
||||
// 口径与 list_hosts 一致:条件都可选、AND 组合、子串匹配、ASCII 不区分大小写。
|
||||
// 只过滤已有字段,不额外拉取主机数据;离线主机没有 clientType(历史记录里不存),
|
||||
// 所以带 client_type 条件时离线主机不会命中——需要按平台筛历史主机请用 os。
|
||||
struct HostListFilter {
|
||||
@@ -1006,7 +1006,7 @@ void AppendPageOutputProps(Json::Value& props) {
|
||||
props["hasMore"] = moreProp;
|
||||
}
|
||||
|
||||
// list_online_hosts / search_hosts 的 outputSchema(hosts 数组)
|
||||
// list_hosts 的 outputSchema(hosts 数组)
|
||||
Json::Value BuildHostOutputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
|
||||
@@ -1081,40 +1081,35 @@ Json::Value BuildHostDetailOutputSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
// search_hosts 的 inputSchema(全部可选)
|
||||
Json::Value BuildSearchHostsInputSchema() {
|
||||
// list_hosts 的 inputSchema(P1-1:三个主机列表工具合并;全部可选)
|
||||
// 旧名 list_online_hosts / search_hosts / list_all_hosts 作为别名保留,参数在这里一并声明。
|
||||
Json::Value BuildListHostsInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
const char* strParams[] = { "name", "ip", "group", "os" };
|
||||
for (const char* p : strParams) {
|
||||
Json::Value s(Json::objectValue);
|
||||
s["type"] = "string";
|
||||
props[p] = s;
|
||||
}
|
||||
Json::Value onlineProp(Json::objectValue);
|
||||
onlineProp["type"] = "boolean";
|
||||
props["online"] = onlineProp;
|
||||
|
||||
AppendPagingProps(props);
|
||||
Json::Value queryProp(Json::objectValue);
|
||||
queryProp["type"] = "string";
|
||||
queryProp["description"] = u8"关键字:子串匹配计算机名、备注或 IP(ASCII 不区分大小写)。省略则不过滤。";
|
||||
props["query"] = queryProp;
|
||||
|
||||
Json::Value schema(Json::objectValue);
|
||||
schema["type"] = "object";
|
||||
schema["properties"] = props;
|
||||
return schema;
|
||||
}
|
||||
Json::Value nameProp(Json::objectValue);
|
||||
nameProp["type"] = "string";
|
||||
nameProp["description"] = u8"只按计算机名/备注过滤(search_hosts 的旧参数);与 query 同时给出时两者都需满足。";
|
||||
props["name"] = nameProp;
|
||||
|
||||
// list_all_hosts 的 inputSchema:两类开关,默认都返回
|
||||
Json::Value BuildListAllHostsInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value ipProp(Json::objectValue);
|
||||
ipProp["type"] = "string";
|
||||
ipProp["description"] = u8"只按 IP 过滤(search_hosts 的旧参数);与 query 同时给出时两者都需满足。";
|
||||
props["ip"] = ipProp;
|
||||
|
||||
Json::Value onlineProp(Json::objectValue);
|
||||
onlineProp["type"] = "boolean";
|
||||
onlineProp["description"] = u8"是否包含在线主机,默认 true";
|
||||
onlineProp["description"] = u8"true(默认)返回在线主机;false 只返回离线主机(历史连接过、当前未连接)。";
|
||||
props["online"] = onlineProp;
|
||||
|
||||
Json::Value offlineProp(Json::objectValue);
|
||||
offlineProp["type"] = "boolean";
|
||||
offlineProp["description"] = u8"是否包含离线主机(历史连接过、当前未连接的),默认 true";
|
||||
props["offline"] = offlineProp;
|
||||
Json::Value includeOfflineProp(Json::objectValue);
|
||||
includeOfflineProp["type"] = "boolean";
|
||||
includeOfflineProp["description"] = u8"是否把离线主机一起返回,默认 false(只给在线);online=false 时无意义。list_all_hosts 别名默认 true。";
|
||||
props["include_offline"] = includeOfflineProp;
|
||||
|
||||
AppendHostListFilterProps(props);
|
||||
AppendPagingProps(props);
|
||||
@@ -1131,7 +1126,7 @@ Json::Value BuildGetHostDetailInputSchema() {
|
||||
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段;与 ids 二选一";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段;与 ids 二选一";
|
||||
props["id"] = idProp;
|
||||
|
||||
AppendBatchIdsProp(props);
|
||||
@@ -1299,7 +1294,7 @@ Json::Value BuildServiceListOutputSchema() {
|
||||
static void AddIdRequiredProp(Json::Value& props) {
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
}
|
||||
|
||||
@@ -1533,7 +1528,7 @@ Json::Value BuildListRegistryInputSchema() {
|
||||
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段;与 ids 二选一";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段;与 ids 二选一";
|
||||
props["id"] = idProp;
|
||||
|
||||
AppendBatchIdsProp(props);
|
||||
@@ -1599,7 +1594,7 @@ Json::Value BuildExecCommandInputSchema() {
|
||||
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value cmdProp(Json::objectValue);
|
||||
@@ -1656,7 +1651,7 @@ Json::Value BuildClientLogInputSchema() {
|
||||
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段;与 ids 二选一";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段;与 ids 二选一";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value limitProp(Json::objectValue);
|
||||
@@ -1872,7 +1867,7 @@ Json::Value BuildGetScreenshotInputSchema() {
|
||||
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value modeProp(Json::objectValue);
|
||||
@@ -1939,7 +1934,7 @@ Json::Value BuildGetForegroundWindowInputSchema() {
|
||||
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value schema(Json::objectValue);
|
||||
@@ -1957,7 +1952,7 @@ Json::Value BuildListFilesInputSchema() {
|
||||
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value pathProp(Json::objectValue);
|
||||
@@ -2127,49 +2122,14 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
Json::Value result(Json::objectValue);
|
||||
Json::Value tools(Json::arrayValue);
|
||||
|
||||
// 1) list_online_hosts
|
||||
// 1) list_hosts(P1-1:合并 list_online_hosts / search_hosts / list_all_hosts;
|
||||
// 旧名作为别名保留在分发处,不出现在 tools/list)
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "list_online_hosts";
|
||||
// 说明文字为 UTF-8:项目 /execution-charset:.936 会把普通窄字面量编译成 GBK,
|
||||
// 故用 u8 前缀确保输出到 JSON 的字节是 UTF-8。
|
||||
tool["description"] = u8"获取当前所有在线主机的列表,包含计算机名、IP、操作系统、版本、备注、分组、活动窗口、延迟等实时信息。可选 group / os / client_type 三个过滤条件(均可选、AND 组合、子串匹配、ASCII 不区分大小写),过滤在分页之前生效:total 为命中台数,totalAll 为全部在线台数。结果按 limit/offset 分页(默认 100 条,上限 1000),hasMore 表示还有下一页。tls=true 表示该客户端登录时使用了 TLS 加密传输(登录时上报,非实时探测;老客户端恒为 false)。";
|
||||
|
||||
Json::Value inputSchema(Json::objectValue);
|
||||
inputSchema["type"] = "object";
|
||||
Json::Value props(Json::objectValue);
|
||||
AppendHostListFilterProps(props);
|
||||
AppendPagingProps(props);
|
||||
inputSchema["properties"] = props;
|
||||
inputSchema["required"] = Json::Value(Json::arrayValue);
|
||||
tool["inputSchema"] = inputSchema;
|
||||
|
||||
tool["name"] = "list_hosts";
|
||||
tool["description"] = u8"列主机:默认只返回在线主机(含计算机名、IP、操作系统、版本、备注、分组、活动窗口、延迟等实时信息),include_offline=true 时连离线主机(历史连接过、当前未连接,来自主机列表记录)一起返回,在线主机排在最前面。query 子串匹配计算机名/备注/IP;group / os / client_type 为附加过滤条件(均可选、AND 组合、子串匹配、ASCII 不区分大小写);online=false 只看离线主机。过滤在分页之前生效:total 为命中台数,totalAll 为过滤前的主机库台数。结果按 limit/offset 分页(默认 100 条,上限 1000),hasMore 表示还有下一页。离线主机另有 last_seen(最后一次登录时间)、install_time 字段,但没有 rtt/version/activeWindow 等实时字段,也没有 clientType(按平台筛历史主机请用 os),group 恒为 default。authStatus 为主机授权状态(unauthorized/authorized_by_super/authorized_by_admin/forbidden)。tls=true 表示该客户端登录时使用了 TLS 加密传输(登录时上报,老客户端恒为 false)。";
|
||||
tool["inputSchema"] = BuildListHostsInputSchema();
|
||||
tool["outputSchema"] = BuildHostOutputSchema();
|
||||
|
||||
tools.append(tool);
|
||||
}
|
||||
|
||||
// 2) search_hosts(P2a:纯内存过滤,无子链接)
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "search_hosts";
|
||||
tool["description"] = u8"按计算机名/备注、IP、分组、操作系统过滤主机。所有条件均可选、按 AND 组合;子串匹配(ASCII 不区分大小写)。online=true 只返回在线主机,online=false 只返回离线主机(曾连接过、当前未连接),省略时只返回在线主机。离线主机的 group 恒为 default,last_seen 为最后一次登录时间;两类都要请用 list_all_hosts。结果按 limit/offset 分页(默认 100 条,上限 1000),total 为匹配总数。tls=true 表示该客户端登录时使用了 TLS 加密传输(登录时上报,老客户端恒为 false)。";
|
||||
|
||||
tool["inputSchema"] = BuildSearchHostsInputSchema();
|
||||
tool["outputSchema"] = BuildHostOutputSchema();
|
||||
|
||||
tools.append(tool);
|
||||
}
|
||||
|
||||
// 2b) list_all_hosts(P2a+:在线 + 离线主机全量枚举,纯内存)
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "list_all_hosts";
|
||||
tool["description"] = u8"列出服务端已知的全部主机:在线主机(实时信息)与离线主机(历史连接过、当前未连接,来自主机列表记录)。在线主机字段同 list_online_hosts;离线主机另有 last_seen(最后一次登录时间)、install_time 字段,但没有 rtt/version/activeWindow 等实时字段,也没有 clientType。authStatus 为主机授权状态(unauthorized/authorized_by_super/authorized_by_admin/forbidden)。默认两类都返回;可选 group / os / client_type 过滤(AND 组合、子串匹配、ASCII 不区分大小写),过滤在分页之前生效:total 为命中台数,totalAll 为主机库总数。结果按 limit/offset 分页(默认 100 条,上限 1000)。";
|
||||
|
||||
tool["inputSchema"] = BuildListAllHostsInputSchema();
|
||||
tool["outputSchema"] = BuildHostOutputSchema();
|
||||
|
||||
tools.append(tool);
|
||||
}
|
||||
|
||||
@@ -2294,7 +2254,7 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value durProp(Json::objectValue);
|
||||
@@ -2787,57 +2747,84 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
return BuildResult(id, result);
|
||||
}
|
||||
|
||||
// tools/call:list_online_hosts
|
||||
std::string BuildListOnlineHosts(const Json::Value& id, const Json::Value& args, CMy2015RemoteDlg* parent) {
|
||||
Json::Value all(Json::arrayValue);
|
||||
CollectOnlineHosts(parent, all);
|
||||
// ===== P1-1:list_hosts(合并 list_online_hosts / search_hosts / list_all_hosts)=====
|
||||
// 三个旧工具的差异只在「要不要离线主机」和几个过滤字段,统一成一个 handler:
|
||||
// list_hosts(及别名 list_online_hosts / search_hosts)→ 默认只看在线(defaultAll=false)
|
||||
// list_all_hosts → 默认在线 + 离线(defaultAll=true)
|
||||
// 过滤口径与旧实现一致:条件都可选、AND 组合、子串匹配、ASCII 不区分大小写。
|
||||
// query 一次性匹配 name/remark/ip;name、ip 保留给 search_hosts 的旧调用方。
|
||||
struct HostQueryFilter {
|
||||
HostListFilter base; // group / os / client_type
|
||||
std::string query, name, ip;
|
||||
bool Any() const {
|
||||
return base.Any() || !query.empty() || !name.empty() || !ip.empty();
|
||||
}
|
||||
};
|
||||
|
||||
// 过滤在分页之前:total 是命中数,totalAll 是全部在线数(与 get_audit_log 同口径)。
|
||||
HostListFilter filter = ReadHostListFilter(args);
|
||||
Json::Value matched;
|
||||
ApplyHostListFilter(all, filter, matched);
|
||||
|
||||
PageWindow page = ResolvePageWindow(args);
|
||||
Json::Value hosts;
|
||||
ApplyPageWindow(matched, page, hosts);
|
||||
if (filter.Any()) page.totalAll = (int)all.size();
|
||||
|
||||
Json::Value result(Json::objectValue);
|
||||
Json::Value structuredContent(Json::objectValue);
|
||||
structuredContent["hosts"] = hosts;
|
||||
WritePageFields(structuredContent, page);
|
||||
result["structuredContent"] = structuredContent;
|
||||
|
||||
std::string text = PageSummary(page, filter.Any() ? u8"台主机匹配" : u8"台主机在线");
|
||||
if (filter.Any())
|
||||
text += std::string(u8"在线共 ") + std::to_string((int)all.size()) + std::string(u8" 台。");
|
||||
|
||||
Json::Value content(Json::arrayValue);
|
||||
Json::Value item(Json::objectValue);
|
||||
item["type"] = "text";
|
||||
item["text"] = text;
|
||||
content.append(item);
|
||||
result["content"] = content;
|
||||
result["isError"] = false;
|
||||
|
||||
return BuildResult(id, result);
|
||||
HostQueryFilter ReadHostQueryFilter(const Json::Value& args) {
|
||||
HostQueryFilter f;
|
||||
f.base = ReadHostListFilter(args);
|
||||
f.query = GetStringArg(args, "query");
|
||||
f.name = GetStringArg(args, "name");
|
||||
f.ip = GetStringArg(args, "ip");
|
||||
return f;
|
||||
}
|
||||
|
||||
// tools/call:list_all_hosts(在线 + 离线,纯内存,不建子连接)
|
||||
std::string BuildListAllHosts(const Json::Value& id, const Json::Value& args, CMy2015RemoteDlg* parent) {
|
||||
bool includeOnline = !(args.isObject() && args.isMember("online") && args["online"].isBool()) || args["online"].asBool();
|
||||
bool includeOffline = !(args.isObject() && args.isMember("offline") && args["offline"].isBool()) || args["offline"].asBool();
|
||||
void ApplyHostQueryFilter(const Json::Value& in, const HostQueryFilter& f, Json::Value& out) {
|
||||
ApplyHostListFilter(in, f.base, out);
|
||||
if (f.query.empty() && f.name.empty() && f.ip.empty()) return;
|
||||
|
||||
Json::Value narrowed(Json::arrayValue);
|
||||
for (Json::Value::ArrayIndex i = 0; i < out.size(); ++i) {
|
||||
const Json::Value& h = out[i];
|
||||
if (!f.query.empty()) {
|
||||
if (!ContainsCI(JsonStrField(h, "name"), f.query) &&
|
||||
!ContainsCI(JsonStrField(h, "remark"), f.query) &&
|
||||
!ContainsCI(JsonStrField(h, "ip"), f.query)) continue;
|
||||
}
|
||||
if (!f.name.empty() &&
|
||||
!ContainsCI(JsonStrField(h, "name"), f.name) &&
|
||||
!ContainsCI(JsonStrField(h, "remark"), f.name)) continue;
|
||||
if (!f.ip.empty() && !ContainsCI(JsonStrField(h, "ip"), f.ip)) continue;
|
||||
narrowed.append(h);
|
||||
}
|
||||
out = narrowed;
|
||||
}
|
||||
|
||||
// tools/call:list_hosts 及三个旧别名
|
||||
std::string BuildListHosts(const Json::Value& id, const Json::Value& args,
|
||||
CMy2015RemoteDlg* parent, bool defaultAll) {
|
||||
const bool hasOnline = args.isObject() && args.isMember("online") && args["online"].isBool();
|
||||
const bool hasInclude = args.isObject() && args.isMember("include_offline") &&
|
||||
args["include_offline"].isBool();
|
||||
const bool hasLegacy = args.isObject() && args.isMember("offline") && args["offline"].isBool();
|
||||
|
||||
bool includeOnline = hasOnline ? args["online"].asBool() : true;
|
||||
bool includeOffline = hasInclude ? args["include_offline"].asBool()
|
||||
: hasLegacy ? args["offline"].asBool()
|
||||
: defaultAll;
|
||||
// online=false 且没给任何「包含离线」开关:按 search_hosts 的旧语义只返回离线主机。
|
||||
if (!includeOnline && !hasInclude && !hasLegacy) includeOffline = true;
|
||||
|
||||
Json::Value hosts(Json::arrayValue);
|
||||
CollectAllHosts(parent, hosts, includeOnline, includeOffline);
|
||||
// 在线主机排前面:主机库可能有几千台历史记录,include_offline 默认只取第一页,
|
||||
// 若沿用 m_ClientMap 的键序,真正能操作的在线主机会被埋进离线堆里,翻页才能看到。
|
||||
if (includeOnline && includeOffline && hosts.size() > 1) {
|
||||
Json::Value ordered(Json::arrayValue);
|
||||
for (Json::Value::ArrayIndex i = 0; i < hosts.size(); ++i)
|
||||
if (hosts[i]["online"].asBool()) ordered.append(hosts[i]);
|
||||
for (Json::Value::ArrayIndex i = 0; i < hosts.size(); ++i)
|
||||
if (!hosts[i]["online"].asBool()) ordered.append(hosts[i]);
|
||||
hosts = ordered;
|
||||
}
|
||||
|
||||
// 过滤先于统计与分页:total/totalAll 与摘要里的在线/离线数都按命中条目算。
|
||||
HostListFilter filter = ReadHostListFilter(args);
|
||||
HostQueryFilter filter = ReadHostQueryFilter(args);
|
||||
Json::Value matched;
|
||||
ApplyHostListFilter(hosts, filter, matched);
|
||||
ApplyHostQueryFilter(hosts, filter, matched);
|
||||
|
||||
int onlineCount = 0;
|
||||
for (unsigned int i = 0; i < matched.size(); ++i) {
|
||||
for (Json::Value::ArrayIndex i = 0; i < matched.size(); ++i) {
|
||||
if (matched[i]["online"].asBool()) onlineCount++;
|
||||
}
|
||||
|
||||
@@ -2852,64 +2839,19 @@ std::string BuildListAllHosts(const Json::Value& id, const Json::Value& args, CM
|
||||
WritePageFields(structuredContent, page);
|
||||
result["structuredContent"] = structuredContent;
|
||||
|
||||
Json::Value content(Json::arrayValue);
|
||||
Json::Value item(Json::objectValue);
|
||||
item["type"] = "text";
|
||||
std::string text = PageSummary(page, filter.Any() ? u8"台主机匹配" : u8"台主机");
|
||||
text += std::string(u8"其中在线 ") + std::to_string(onlineCount) +
|
||||
std::string(u8",离线 ") + std::to_string(page.total - onlineCount) + std::string(u8"。");
|
||||
const char* unit = filter.Any() ? u8"台主机匹配"
|
||||
: (includeOffline ? u8"台主机" : u8"台在线主机");
|
||||
std::string text = PageSummary(page, unit);
|
||||
if (includeOffline)
|
||||
text += std::string(u8"其中在线 ") + std::to_string(onlineCount) +
|
||||
std::string(u8",离线 ") + std::to_string(page.total - onlineCount) + std::string(u8"。");
|
||||
if (filter.Any())
|
||||
text += std::string(u8"主机库共 ") + std::to_string((int)hosts.size()) + std::string(u8" 台。");
|
||||
item["text"] = text;
|
||||
content.append(item);
|
||||
result["content"] = content;
|
||||
result["isError"] = false;
|
||||
|
||||
return BuildResult(id, result);
|
||||
}
|
||||
|
||||
// tools/call:search_hosts
|
||||
std::string BuildSearchHosts(const Json::Value& id, const Json::Value& args, CMy2015RemoteDlg* parent) {
|
||||
Json::Value all(Json::arrayValue);
|
||||
|
||||
std::string fName = GetStringArg(args, "name");
|
||||
std::string fIp = GetStringArg(args, "ip");
|
||||
std::string fGroup = GetStringArg(args, "group");
|
||||
std::string fOs = GetStringArg(args, "os");
|
||||
// online=true → 仅在线;online=false → 仅离线(历史主机);省略 → 仅在线(保持本工具原有行为,
|
||||
// 想要两类都要请用 list_all_hosts)。
|
||||
bool hasOnline = args.isObject() && args.isMember("online") && args["online"].isBool();
|
||||
bool wantOnline = hasOnline ? args["online"].asBool() : true;
|
||||
CollectAllHosts(parent, all, wantOnline, hasOnline && !wantOnline);
|
||||
|
||||
Json::Value hosts(Json::arrayValue);
|
||||
for (unsigned int i = 0; i < all.size(); ++i) {
|
||||
const Json::Value& h = all[i];
|
||||
if (!fName.empty()) {
|
||||
std::string name = JsonStrField(h, "name");
|
||||
std::string remark = JsonStrField(h, "remark");
|
||||
if (!ContainsCI(name, fName) && !ContainsCI(remark, fName)) continue;
|
||||
}
|
||||
if (!fIp.empty() && !ContainsCI(JsonStrField(h, "ip"), fIp)) continue;
|
||||
if (!fGroup.empty() && !ContainsCI(JsonStrField(h, "group"), fGroup)) continue;
|
||||
if (!fOs.empty() && !ContainsCI(JsonStrField(h, "os"), fOs)) continue;
|
||||
hosts.append(h);
|
||||
}
|
||||
|
||||
PageWindow page = ResolvePageWindow(args);
|
||||
Json::Value pageItems;
|
||||
ApplyPageWindow(hosts, page, pageItems);
|
||||
|
||||
Json::Value result(Json::objectValue);
|
||||
Json::Value structuredContent(Json::objectValue);
|
||||
structuredContent["hosts"] = pageItems;
|
||||
WritePageFields(structuredContent, page);
|
||||
result["structuredContent"] = structuredContent;
|
||||
|
||||
Json::Value content(Json::arrayValue);
|
||||
Json::Value item(Json::objectValue);
|
||||
item["type"] = "text";
|
||||
item["text"] = PageSummary(page, u8"台主机匹配");
|
||||
item["text"] = text;
|
||||
content.append(item);
|
||||
result["content"] = content;
|
||||
result["isError"] = false;
|
||||
@@ -2920,7 +2862,7 @@ std::string BuildSearchHosts(const Json::Value& id, const Json::Value& args, CMy
|
||||
// tools/call:get_host_detail
|
||||
//
|
||||
// 登录时上报的 RES_* 技术字段(CPU 核数/内存/系统位数/账号/安装时间/分辨率…)只在
|
||||
// get_host_detail 里补充,不改 BuildHostJson —— 那是 Web UI 与 list_online_hosts 共用的
|
||||
// get_host_detail 里补充,不改 BuildHostJson —— 那是 Web UI 与 list_hosts 共用的
|
||||
// 序列化函数,动它会改变已有调用方的输出形状。
|
||||
std::string ResFieldUtf8(context* ctx, UINT cp, int idx) {
|
||||
CString v = ctx->GetAdditionalData(idx);
|
||||
@@ -3026,7 +2968,7 @@ std::string BuildGetHostDetail(const Json::Value& id, const Json::Value& args, C
|
||||
const Json::Value& h = all[i];
|
||||
if (JsonStrField(h, "id") == sid) {
|
||||
// 复制后再补充技术字段:all[] 里的是本次调用内的临时对象,补字段不影响
|
||||
// BuildHostJson 本身(list_online_hosts 用同一份序列化,输出形状不变)。
|
||||
// BuildHostJson 本身(list_hosts 用同一份序列化,输出形状不变)。
|
||||
Json::Value host = h;
|
||||
AppendHostTechnicalDetail(parent, strtoull(sid.c_str(), nullptr, 10), host);
|
||||
|
||||
@@ -3091,7 +3033,7 @@ std::string BuildGetHostDetail(const Json::Value& id, const Json::Value& args, C
|
||||
}
|
||||
|
||||
// list_processes / list_windows 的服务端过滤:name 是子串匹配(ASCII 不区分大小写,
|
||||
// 口径同 list_online_hosts 的过滤),pid 是精确匹配;nameField 指定被匹配的字段
|
||||
// 口径同 list_hosts 的过滤),pid 是精确匹配;nameField 指定被匹配的字段
|
||||
// (进程看映像名 "name",窗口看标题 "title")。两个条件都没给就原样返回。
|
||||
Json::Value FilterByPidAndName(const Json::Value& items, const Json::Value& args,
|
||||
const char* nameField) {
|
||||
@@ -3143,7 +3085,7 @@ std::string BuildListProcesses(const Json::Value& id, const Json::Value& args, C
|
||||
|
||||
Json::Value procs = ParseProcessList(data, cp);
|
||||
|
||||
// 过滤先于分页:total 是命中数,totalAll 是过滤前的总数(口径同 search_hosts)。
|
||||
// 过滤先于分页:total 是命中数,totalAll 是过滤前的总数(口径同 list_hosts)。
|
||||
Json::Value matched = FilterByPidAndName(procs, args, "name");
|
||||
PageWindow page = ResolvePageWindow(args);
|
||||
Json::Value pageItems;
|
||||
@@ -3196,7 +3138,7 @@ std::string BuildListWindows(const Json::Value& id, const Json::Value& args, CMy
|
||||
UINT cp = GetClientEncoding(ctx);
|
||||
Json::Value wins = ParseWindowList(data, cp);
|
||||
|
||||
// 过滤先于分页:total 是命中数,totalAll 是过滤前的总数(口径同 search_hosts)。
|
||||
// 过滤先于分页:total 是命中数,totalAll 是过滤前的总数(口径同 list_hosts)。
|
||||
Json::Value matched = FilterByPidAndName(wins, args, "title");
|
||||
PageWindow page = ResolvePageWindow(args);
|
||||
Json::Value pageItems;
|
||||
@@ -4786,7 +4728,7 @@ Json::Value BuildTerminalOpenInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
Json::Value timeoutProp(Json::objectValue);
|
||||
timeoutProp["type"] = "integer";
|
||||
@@ -4829,7 +4771,7 @@ Json::Value BuildTerminalExecInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
Json::Value sid(Json::objectValue);
|
||||
sid["type"] = "string";
|
||||
@@ -4909,7 +4851,7 @@ Json::Value BuildTerminalCloseInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
Json::Value sid(Json::objectValue);
|
||||
sid["type"] = "string";
|
||||
@@ -5298,7 +5240,7 @@ Json::Value BuildRemoteOpenInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
Json::Value timeoutProp(Json::objectValue);
|
||||
timeoutProp["type"] = "integer";
|
||||
@@ -5398,7 +5340,7 @@ Json::Value BuildRemoteCloseInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
Json::Value sid(Json::objectValue);
|
||||
sid["type"] = "string";
|
||||
@@ -5878,7 +5820,7 @@ Json::Value BuildRemoteKeyboardInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value sid(Json::objectValue);
|
||||
@@ -6312,7 +6254,7 @@ Json::Value BuildRemoteMouseInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value sid(Json::objectValue);
|
||||
@@ -6741,7 +6683,7 @@ Json::Value BuildRemoteClipboardInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value sid(Json::objectValue);
|
||||
@@ -6857,7 +6799,7 @@ Json::Value BuildRemoteLockScreenInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
Json::Value sid(Json::objectValue);
|
||||
sid["type"] = "string";
|
||||
@@ -6967,7 +6909,7 @@ Json::Value BuildRemoteBlockInputInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value sid(Json::objectValue);
|
||||
@@ -7195,7 +7137,7 @@ Json::Value BuildDownloadFileInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value rp(Json::objectValue);
|
||||
@@ -7609,7 +7551,7 @@ Json::Value BuildReadFileInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value pathProp(Json::objectValue);
|
||||
@@ -8431,7 +8373,7 @@ Json::Value BuildHttpProbeInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
Json::Value urlProp(Json::objectValue);
|
||||
urlProp["type"] = "string";
|
||||
@@ -8875,7 +8817,7 @@ Json::Value BuildUploadFileInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
idProp["description"] = u8"主机 id,取 list_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
|
||||
Json::Value lp(Json::objectValue);
|
||||
@@ -9242,7 +9184,7 @@ Json::Value BuildCopyFilesC2CInputSchema() {
|
||||
|
||||
Json::Value src(Json::objectValue);
|
||||
src["type"] = "string";
|
||||
src["description"] = u8"源主机 id(文件从这里发出),取 list_online_hosts / search_hosts 返回的 id";
|
||||
src["description"] = u8"源主机 id(文件从这里发出),取 list_hosts 返回的 id";
|
||||
props["src_id"] = src;
|
||||
|
||||
Json::Value dst(Json::objectValue);
|
||||
@@ -11660,7 +11602,7 @@ Json::Value BuildHostSetRemarkInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id(list_online_hosts / list_all_hosts 返回的十进制字符串)。";
|
||||
idProp["description"] = u8"主机 id(list_hosts 返回的十进制字符串)。";
|
||||
props["id"] = idProp;
|
||||
Json::Value remarkProp(Json::objectValue);
|
||||
remarkProp["type"] = "string";
|
||||
@@ -11768,9 +11710,8 @@ struct ToolPlatform {
|
||||
// 遗漏由 check_platform_table.py 的工具数比对发现。
|
||||
const ToolPlatform kToolPlatforms[] = {
|
||||
// ---- win+lnx+mac+apk ---- 只读写服务端本地数据,与客户端平台无关
|
||||
{ "list_online_hosts", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
{ "search_hosts", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
{ "list_all_hosts", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
// P1-1:主机列表三合一。旧名保留为别名(不进 tools/list,也不进平台表)。
|
||||
{ "list_hosts", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
{ "get_host_detail", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
{ "get_audit_log", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
{ "get_server_status", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
@@ -12148,9 +12089,11 @@ std::string DispatchSingleHostTool(const Json::Value& id, const std::string& too
|
||||
// P9:远程交谈工具族(独立开关 McpChat;门控在 McpChat::Call 内复核)。
|
||||
if (McpChat::Handles(toolName)) return McpChat::Call(id, toolName, args, parent);
|
||||
|
||||
if (toolName == "list_online_hosts") return BuildListOnlineHosts(id, args, parent);
|
||||
if (toolName == "list_all_hosts") return BuildListAllHosts(id, args, parent);
|
||||
if (toolName == "search_hosts") return BuildSearchHosts(id, args, parent);
|
||||
// P1-1:list_hosts 与三个旧别名共用一个 handler;list_all_hosts 默认为「在线 + 离线」。
|
||||
if (toolName == "list_hosts") return BuildListHosts(id, args, parent, false);
|
||||
if (toolName == "list_online_hosts") return BuildListHosts(id, args, parent, false);
|
||||
if (toolName == "search_hosts") return BuildListHosts(id, args, parent, false);
|
||||
if (toolName == "list_all_hosts") return BuildListHosts(id, args, parent, true);
|
||||
if (toolName == "get_host_detail") return BuildGetHostDetail(id, args, parent);
|
||||
if (toolName == "list_processes") return BuildListProcesses(id, args, parent);
|
||||
if (toolName == "list_windows") return BuildListWindows(id, args, parent);
|
||||
|
||||
Reference in new issue
Block a user