Feature(mcp): merge the ten host_list_* tools into host_inspect

The ten read-only host-management tools (host_list_processes, windows,
network_state, software, browser_history, favorites, win32_services,
driver_services, scheduled_tasks, host_get_hosts_file) each carried a
name, description and schema for what is one connection to the host,
one tab id per aspect and one paged list shape. Ten entries made
tools/list hard to scan and took a large share of the description
budget.

They are now one tool, host_inspect(aspects[], ...), where aspects is a
required, deduplicated array of the ten former names. A single aspect
returns exactly what the old tool returned (same builder, same code
path), so output is byte-identical; several aspects are fetched over
separate managed sessions and merged into results.<aspect>, with
failures isolated in errors.<aspect> and isError only when every aspect
failed. Filters (pid/name/arch/title/url/publisher/folder/status/
start_type/process/protocol/ports/state/max_bytes) are still applied
server-side before paging and are ignored by aspects they don't apply
to.

The old names stay as dispatch aliases so existing callers keep working
but no longer appear in tools/list; the platform table, batch read-only
list, tool hints, instructions, generator tables and the captured
mcp/tools.json move to the new name (63 tools -> 54).

The description also notes that win32_services / driver_services need
an elevated client: a non-elevated one cannot open SCM and never
answers, so the call times out after ~12 s.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-12 17:21:36 +01:00
1 parent cac5adaafc
commit 59f0f16f74
5 files changed
+1034 -1803

No files matched your search

+310 -122
View File
@@ -241,7 +241,7 @@ Json::Value MakeListOutputSchema(const char* arrayKey, const Json::Value& itemPr
}
Json::Value HostIdProp() {
return PropStr(u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段");
return PropStr(u8"主机 id,取 list_hosts 返回的 id 字段");
}
// 所有读工具的公共分页参数
@@ -2068,6 +2068,171 @@ static std::string BuildHostGetHostsFile(const Json::Value& id, const Json::Valu
return BuildStructuredResult(id, sc, summary, &textPayload);
}
// ============================================================================
// P2-1:host_inspect —— 10 个 host_list_* / host_get_hosts_file 合并成一个工具
// ============================================================================
// 单个 aspect 直接走原 builder,输出与旧工具逐字节一致(旧工具名保留为别名,分派到
// 同一个入口);多个 aspect 串行取,每个 aspect 一个 managed 会话,结果收进
// results.<aspect>,某个 aspect 失败只记入 errors.<aspect>,不影响其它 aspect。
namespace {
typedef std::string (*InspectBuilder)(const Json::Value&, const Json::Value&, CMy2015RemoteDlg*);
std::string BuildInspectWin32Services(const Json::Value& id, const Json::Value& args,
CMy2015RemoteDlg* parent) {
return BuildHostListServices(id, args, parent, /*drivers=*/false);
}
std::string BuildInspectDriverServices(const Json::Value& id, const Json::Value& args,
CMy2015RemoteDlg* parent) {
return BuildHostListServices(id, args, parent, /*drivers=*/true);
}
struct InspectAspect {
const char* name;
const char* what; // 摘要里的中文名
InspectBuilder build;
};
// aspects 的枚举顺序即此处顺序;schema 与校验都从这里来,避免两处漂移。
const InspectAspect kInspectAspects[] = {
{ "processes", u8"进程", BuildHostListProcesses },
{ "windows", u8"窗口", BuildHostListWindows },
{ "network", u8"网络连接", BuildHostListNetworkState },
{ "software", u8"软件", BuildHostListSoftware },
{ "browser_history", u8"浏览记录", BuildHostListBrowserHistory },
{ "favorites", u8"收藏夹", BuildHostListFavorites },
{ "win32_services", u8"Win32 服务", BuildInspectWin32Services },
{ "driver_services", u8"驱动服务", BuildInspectDriverServices },
{ "scheduled_tasks", u8"计划任务", BuildHostListScheduledTasks },
{ "hosts_file", u8"hosts 文件", BuildHostGetHostsFile },
};
std::string ValidAspectList() {
std::string s;
for (const InspectAspect& a : kInspectAspects) {
if (!s.empty()) s += ", ";
s += a.name;
}
return s;
}
bool ReadInspectAspects(const Json::Value& id, const Json::Value& args,
std::vector<const InspectAspect*>& out, std::string& errJson) {
const Json::Value& v = args["aspects"];
if (!v.isArray() || v.size() == 0) {
errJson = BuildError(id, -32602,
"Invalid aspects: must be a non-empty array; valid: " + ValidAspectList());
return false;
}
for (Json::ArrayIndex i = 0; i < v.size(); ++i) {
if (!v[i].isString()) {
errJson = BuildError(id, -32602, "Invalid aspects: every entry must be a string");
return false;
}
const std::string s = v[i].asString();
const InspectAspect* hit = nullptr;
for (const InspectAspect& a : kInspectAspects) {
if (s == a.name) { hit = &a; break; }
}
if (!hit) {
errJson = BuildError(id, -32602,
"Invalid aspect '" + s + "'; valid: " + ValidAspectList());
return false;
}
bool dup = false;
for (const InspectAspect* p : out) {
if (p == hit) { dup = true; break; }
}
if (!dup) out.push_back(hit);
}
return true;
}
// 把一个 builder 的完整 JSON-RPC 响应拆成 structuredContent + 摘要文本 / 错误码。
struct InspectRun {
int code = 0; // 0 = 成功
Json::Value sc;
std::string text;
};
bool RunInspectAspect(const InspectAspect& a, const Json::Value& id, const Json::Value& args,
CMy2015RemoteDlg* parent, InspectRun& run) {
const std::string resp = a.build(id, args, parent);
Json::Value doc;
Json::Reader reader;
if (!reader.parse(resp, doc) || !doc.isObject()) {
run.code = kErrGeneric;
run.text = "internal error: unparsable tool result";
return false;
}
if (doc.isMember("error") && doc["error"].isObject()) {
run.code = doc["error"]["code"].asInt();
run.text = doc["error"]["message"].asString();
return false;
}
const Json::Value& result = doc["result"];
if (!result.isObject()) {
run.code = kErrGeneric;
run.text = "internal error: missing result";
return false;
}
run.sc = result["structuredContent"];
if (result["content"].isArray() && result["content"].size() > 0)
run.text = JsonStrField(result["content"][0], "text");
return true;
}
std::string BuildHostInspect(const Json::Value& id, const Json::Value& args,
CMy2015RemoteDlg* parent) {
std::vector<const InspectAspect*> aspects;
std::string errJson;
if (!ReadInspectAspects(id, args, aspects, errJson)) return errJson;
// 单 aspect:原样返回旧 builder 的响应——输出与旧工具(以及旧名别名)逐字节一致。
if (aspects.size() == 1) return aspects[0]->build(id, args, parent);
Json::Value results(Json::objectValue);
Json::Value errors(Json::objectValue);
std::string summary;
int okCount = 0, failCount = 0;
for (const InspectAspect* a : aspects) {
InspectRun run;
if (!summary.empty()) summary += u8";";
if (RunInspectAspect(*a, id, args, parent, run)) {
results[a->name] = run.sc;
okCount++;
summary += std::string(a->what) + ":" + (run.text.empty() ? std::string("ok") : run.text);
} else {
Json::Value e(Json::objectValue);
if (run.code) e["code"] = run.code;
e["message"] = run.text;
errors[a->name] = e;
failCount++;
summary += std::string(a->what) + u8":失败(" +
(run.code ? std::to_string(run.code) + " " : std::string()) + run.text + ")";
}
}
Json::Value sc(Json::objectValue);
sc["results"] = results;
if (failCount) sc["errors"] = errors;
Json::Value result(Json::objectValue);
result["structuredContent"] = sc;
Json::Value content(Json::arrayValue);
Json::Value item(Json::objectValue);
item["type"] = "text";
item["text"] = summary;
content.append(item);
result["content"] = content;
result["isError"] = (okCount == 0);
return BuildResult(id, result);
}
} // namespace
// ============================================================================
// 主机管理:写工具(只读 + 可恢复操作)
// ============================================================================
@@ -2823,19 +2988,131 @@ Json::Value ReadInputSchemaBatch(Json::Value props) {
return schema;
}
// 只有 id/ids、没有分页的只读工具(host_get_hosts_file 用 max_bytes 控大小)
Json::Value IdOrIdsSchema(Json::Value props) {
AppendBatchIdsProp(props);
Json::Value schema = MakeSchema(props, {});
MakeIdOrIdsRequired(schema);
// ===== host_inspect(P2-1:10 个 host_list_* / host_get_hosts_file 合并)=====
// 过滤参数按 aspect 生效,其余 aspect 忽略;全部可选、AND 组合、子串匹配。
Json::Value BuildHostInspectInputSchema() {
Json::Value props(Json::objectValue);
props["id"] = HostIdProp();
Json::Value aspects(Json::objectValue);
aspects["type"] = "array";
aspects["minItems"] = 1;
Json::Value items(Json::objectValue);
items["type"] = "string";
Json::Value enums(Json::arrayValue);
for (const InspectAspect& a : kInspectAspects) enums.append(a.name);
items["enum"] = enums;
aspects["items"] = items;
aspects["description"] = u8"要取的方面(必填、可多选、自动去重):"
u8"processes=进程,windows=可见顶层窗口,network=网络连接(进程视角),"
u8"software=已安装软件,browser_history=IE 浏览历史,favorites=IE 收藏夹,"
u8"win32_services=Win32 服务,driver_services=驱动服务,"
u8"scheduled_tasks=计划任务,hosts_file=hosts 文件";
props["aspects"] = aspects;
props["pid"] = PropInt(u8"按 PID 过滤:processes / windows(所属进程)/ network");
props["name"] = PropStr(u8"按名称子串过滤:processes(映像名)/ software(软件名)/ "
u8"win32_services|driver_services(服务名或显示名)/ scheduled_tasks(任务名)");
props["arch"] = PropStrEnum(u8"按架构过滤:processes", { "x86", "x64" });
props["title"] = PropStr(u8"按标题子串过滤:windows(窗口标题)/ browser_history(网页标题)");
props["url"] = PropStr(u8"按 URL 子串过滤:browser_history / favorites");
props["publisher"] = PropStr(u8"按发布者子串过滤:software");
props["folder"] = PropStr(u8"按任务文件夹子串过滤(如 \\Microsoft):scheduled_tasks");
props["status"] = PropStr(u8"按状态子串过滤(如 Running / Ready):win32_services / driver_services / scheduled_tasks");
props["start_type"] = PropStr(u8"按启动类型子串过滤(如 Auto):win32_services / driver_services");
props["process"] = PropStr(u8"按进程名子串过滤:network");
props["protocol"] = PropStrEnum(u8"按协议过滤:network", { "tcp", "udp", "all" });
props["local_port"] = PropInt(u8"按本地端口精确过滤:network");
props["remote_port"] = PropInt(u8"按远端端口精确过滤:network");
props["state"] = PropStr(u8"按状态子串过滤(如 ESTABLISHED):network");
props["include_content"] = PropBool(u8"是否返回按行切分的内容,默认 true:hosts_file");
props["max_bytes"] = PropInt(u8"最多返回的原始字节数,默认 262144,上限 1048576:hosts_file");
AddPagingProps(props);
Json::Value schema = ReadInputSchemaBatch(props);
// aspects 是必填:ReadInputSchemaBatch 只留下 id/ids 的 anyOf,这里补回 required。
// 不写进 schema 的话,按 schema 校验的客户端会以为可以省略,运行时才吃到 -32602。
Json::Value req(Json::arrayValue);
req.append("aspects");
schema["required"] = req;
return schema;
}
// hosts_file 的输出 schema(原 host_get_hosts_file 的字段,一字不改)
Json::Value HostsFileOutputSchema() {
Json::Value outProps(Json::objectValue);
outProps["path"] = PropStr();
outProps["encoding"] = PropStr(u8"utf-8 / gbk(自动探测)");
outProps["bytes"] = PropInt(u8"文件原始字节数");
outProps["returnedBytes"] = PropInt();
outProps["truncated"] = PropBool();
outProps["lineCount"] = PropInt();
Json::Value lines(Json::objectValue);
lines["type"] = "array";
lines["items"] = PropStr();
outProps["lines"] = lines;
outProps["content"] = PropStr(u8"未截断时的完整文本");
Json::Value out(Json::objectValue);
out["type"] = "object";
out["properties"] = outProps;
return out;
}
Json::Value BuildHostInspectOutputSchema() {
Json::Value resultsProps(Json::objectValue);
resultsProps["processes"] = MakeListOutputSchema("processes", ProcessItemSchema());
Json::Value windows = MakeListOutputSchema("windows", WindowItemSchema());
windows["properties"]["truncated"] =
PropBool(u8"为 true 时表示客户端的可见窗口多于单次返回上限(96 条),列表不完整");
resultsProps["windows"] = windows;
resultsProps["network"] = MakeListOutputSchema("connections", NetStateItemSchema());
resultsProps["software"] = MakeListOutputSchema("software", SoftwareItemSchema());
resultsProps["browser_history"] = MakeListOutputSchema("history", HistoryItemSchema());
resultsProps["favorites"] = MakeListOutputSchema("favorites", FavoriteItemSchema());
resultsProps["win32_services"] = MakeListOutputSchema("services", ServiceItemSchema());
resultsProps["driver_services"] = MakeListOutputSchema("services", ServiceItemSchema());
resultsProps["scheduled_tasks"] = MakeListOutputSchema("tasks", TaskItemSchema());
resultsProps["hosts_file"] = HostsFileOutputSchema();
Json::Value results(Json::objectValue);
results["type"] = "object";
results["description"] = u8"按 aspect 名索引;每个值的形状与单 aspect 调用的顶层一致";
results["properties"] = resultsProps;
Json::Value errItem(Json::objectValue);
errItem["type"] = "object";
Json::Value errProps(Json::objectValue);
errProps["code"] = PropInt(u8"JSON-RPC 错误码,如 -32001 超时、-32005 平台不支持");
errProps["message"] = PropStr(u8"错误说明");
errItem["properties"] = errProps;
Json::Value errors(Json::objectValue);
errors["type"] = "object";
errors["description"] = u8"只有失败的 aspect 才会出现;不影响其它 aspect 的结果";
errors["additionalProperties"] = errItem;
Json::Value props(Json::objectValue);
props["results"] = results;
props["errors"] = errors;
Json::Value schema(Json::objectValue);
schema["type"] = "object";
schema["properties"] = props;
// 单 aspect 时顶层直接是该 aspect 的列表结果(与旧工具逐字节一致),两种形状都合法。
schema["additionalProperties"] = true;
return schema;
}
} // namespace
bool Handles(const std::string& toolName) {
// host_inspect 之后的 10 个旧名(host_list_* / host_get_hosts_file)是 P2-1 合并后
// 保留的别名:不出现在 tools/list,但调用仍按旧行为处理。新增调用方请用 host_inspect。
static const char* kTools[] = {
"list_network_connections", "kill_network_connection",
"host_inspect",
"host_list_processes", "host_list_windows", "host_list_network_state",
"host_list_software", "host_list_browser_history", "host_list_favorites",
"host_list_win32_services", "host_list_driver_services",
@@ -2887,118 +3164,28 @@ void AppendTools(Json::Value& tools) {
ActionOutputSchema());
}
// ---- 主机管理:10 个只读标签页 ----
// ---- 主机管理:host_inspect(P2-1:原 10 个 host_list_* / host_get_hosts_file 合并)----
{
Json::Value props(Json::objectValue);
props["pid"] = PropInt(u8"按 PID 过滤");
props["name"] = PropStr(u8"按进程名子串过滤");
props["arch"] = PropStrEnum(u8"按架构过滤", { "x86", "x64" });
AddTool(tools, "host_list_processes",
u8"列出在线 Windows 主机的进程(主机管理「进程」标签页)。返回 PID、架构、窗口标题、路径、优先级、线程数、用户、工作集与文件大小。首选:与 list_processes 同源但字段更全,并支持服务端过滤(pid / name / arch),仅在它没有出现在 tools/list 里(McpMachine=0)时退回 list_processes。",
ReadInputSchemaBatch(props), MakeListOutputSchema("processes", ProcessItemSchema()));
}
{
Json::Value props(Json::objectValue);
props["pid"] = PropInt(u8"按所属进程 PID 过滤");
props["title"] = PropStr(u8"按窗口标题子串过滤");
Json::Value outSchema = MakeListOutputSchema("windows", WindowItemSchema());
// 客户端单个响应包最多装 96 条窗口;超出时这里给出 true,表示 windows
// 只是可见窗口的一个前缀,翻页也取不到剩下的部分。
outSchema["properties"]["truncated"] =
PropBool(u8"为 true 时表示客户端的可见窗口多于单次返回上限(96 条),列表不完整");
AddTool(tools, "host_list_windows",
u8"列出在线 Windows 主机上当前可见的顶层窗口(主机管理「窗口」标签页)。只包含可见窗口,故隐藏后窗口会从结果中消失;单次最多返回 96 条,可见窗口更多时 truncated=true 且列表不完整(不能据此断定某个窗口不存在)。hwnd 可用于 host_control_window 或 operate_window。首选:支持服务端过滤(pid / title),仅在它没有出现在 tools/list 里(McpMachine=0)时退回 list_windows。",
ReadInputSchemaBatch(props), outSchema);
}
{
Json::Value props(Json::objectValue);
props["pid"] = PropInt();
props["process"] = PropStr(u8"按进程名子串过滤");
props["protocol"] = PropStrEnum(u8"协议过滤", { "tcp", "udp" });
props["local_port"] = PropInt();
props["remote_port"] = PropInt();
props["state"] = PropStr(u8"按状态子串过滤");
AddTool(tools, "host_list_network_state",
u8"列出在线 Windows 主机的网络连接及其所属进程(主机管理「网络状态」标签页)。数据来源与「连接管理」不同(这里是进程视角、含 UDP 的无对端标记);仅支持 IPv4 展示。",
ReadInputSchemaBatch(props), MakeListOutputSchema("connections", NetStateItemSchema()));
}
{
Json::Value props(Json::objectValue);
props["name"] = PropStr(u8"按软件名子串过滤");
props["publisher"] = PropStr(u8"按发布者子串过滤");
AddTool(tools, "host_list_software",
u8"列出在线 Windows 主机已安装的软件(主机管理「软件」标签页,来自注册表 Uninstall 项)。只读;不提供卸载能力。",
ReadInputSchemaBatch(props), MakeListOutputSchema("software", SoftwareItemSchema()));
}
{
Json::Value props(Json::objectValue);
props["title"] = PropStr(u8"按标题子串过滤");
props["url"] = PropStr(u8"按 URL 子串过滤");
AddTool(tools, "host_list_browser_history",
u8"列出在线 Windows 主机的 IE 浏览历史(主机管理「浏览记录」标签页)。隐私数据,仅在显式开启主机管理时可见。",
ReadInputSchemaBatch(props), MakeListOutputSchema("history", HistoryItemSchema()));
}
{
Json::Value props(Json::objectValue);
props["name"] = PropStr(u8"按收藏名子串过滤");
props["url"] = PropStr(u8"按 URL 子串过滤");
AddTool(tools, "host_list_favorites",
u8"列出在线 Windows 主机的 IE 收藏夹(主机管理「收藏夹」标签页)。隐私数据,仅在显式开启主机管理时可见。",
ReadInputSchemaBatch(props), MakeListOutputSchema("favorites", FavoriteItemSchema()));
}
{
Json::Value props(Json::objectValue);
props["name"] = PropStr(u8"按服务名或显示名子串过滤");
props["status"] = PropStr(u8"按状态子串过滤,如 Running");
props["start_type"] = PropStr(u8"按启动类型子串过滤,如 Auto");
AddTool(tools, "host_list_win32_services",
u8"列出在线 Windows 主机的 Win32 服务(主机管理「服务」标签页之一)。返回显示名、描述、状态、启动类型、登录身份、服务名与可执行路径;服务名可用于 host_control_service。首选:支持服务端过滤(name / status),仅在它没有出现在 tools/list 里(McpMachine=0)时退回 list_services。",
ReadInputSchemaBatch(props), MakeListOutputSchema("services", ServiceItemSchema()));
}
{
Json::Value props(Json::objectValue);
props["name"] = PropStr(u8"按服务名或显示名子串过滤");
props["status"] = PropStr(u8"按状态子串过滤");
props["start_type"] = PropStr(u8"按启动类型子串过滤");
AddTool(tools, "host_list_driver_services",
u8"列出在线 Windows 主机的驱动服务(主机管理「服务」标签页之一)。字段同 host_list_win32_services。",
ReadInputSchemaBatch(props), MakeListOutputSchema("services", ServiceItemSchema()));
}
{
Json::Value props(Json::objectValue);
props["name"] = PropStr(u8"按任务名子串过滤");
props["folder"] = PropStr(u8"按任务文件夹子串过滤,如 \\Microsoft");
props["status"] = PropStr(u8"按状态子串过滤,如 Ready / Disabled");
AddTool(tools, "host_list_scheduled_tasks",
u8"列出在线 Windows 主机的计划任务(主机管理「计划任务」标签页)。返回任务名、完整路径、所在文件夹、可执行文件、状态与上次/下次运行时间。任务名 + folder 可用于 host_control_task。",
ReadInputSchemaBatch(props), MakeListOutputSchema("tasks", TaskItemSchema()));
}
{
Json::Value props(Json::objectValue);
props["id"] = HostIdProp();
props["include_content"] = PropBool(u8"是否返回按行切分的内容,默认 true");
props["max_bytes"] = PropInt(u8"最多返回的原始字节数,默认 262144,上限 1048576");
Json::Value outProps(Json::objectValue);
outProps["path"] = PropStr();
outProps["encoding"] = PropStr(u8"utf-8 / gbk(自动探测)");
outProps["bytes"] = PropInt(u8"文件原始字节数");
outProps["returnedBytes"] = PropInt();
outProps["truncated"] = PropBool();
outProps["lineCount"] = PropInt();
Json::Value lines(Json::objectValue);
lines["type"] = "array";
lines["items"] = PropStr();
outProps["lines"] = lines;
outProps["content"] = PropStr(u8"未截断时的完整文本");
Json::Value out(Json::objectValue);
out["type"] = "object";
out["properties"] = outProps;
AddTool(tools, "host_get_hosts_file",
u8"读取在线 Windows 主机的 hosts 文件(主机管理「HOSTS」标签页),按行返回并自动识别 UTF-8/GBK。只读;不提供写入能力。",
IdOrIdsSchema(props), out);
AddTool(tools, "host_inspect",
u8"一次取回在线 Windows 主机的多类主机管理信息(原 10 个 host_list_* 工具合并)。aspects 必填、可多选:"
u8"processes(进程:PID/架构/窗口标题/路径/优先级/线程数/用户/工作集与文件大小)| "
u8"windows(当前可见顶层窗口;只含可见窗口,单次最多 96 条,超出时 truncated=true 且列表不完整,"
u8"不能据此断定某窗口不存在;hwnd 可交给 host_control_window / operate_window)| "
u8"network(网络连接,进程视角、含 UDP;与 list_network_connections 的「连接管理」数据源不同)| "
u8"software(已安装软件,来自注册表 Uninstall 项;不提供卸载)| "
u8"browser_history(IE 浏览历史,隐私数据)| favorites(IE 收藏夹,隐私数据)| "
u8"win32_services(Win32 服务;服务名可用于 host_control_service)| "
u8"driver_services(驱动服务;字段同 win32_services)| "
u8"scheduled_tasks(计划任务;任务名 + folder 可用于 host_control_task)| "
u8"hosts_file(按行返回并自动识别 UTF-8/GBK)。"
u8"注意:win32_services / driver_services 要求客户端以管理员权限运行——非提权客户端"
u8"拿不到 SCM 句柄后直接不回应,调用会在约 12 秒后超时(同等场景 list_services 会明确报 access denied)。"
u8"过滤参数按 aspect 生效、其余忽略(见各参数说明),在服务端完成且先于分页:"
u8"total 为命中数、totalAll 为该项全部条目数。"
u8"单个 aspect 时顶层就是该项的列表结果(与合并前的旧工具一致);多个 aspect 时汇总在 "
u8"results.<aspect>,某个 aspect 失败只记入 errors.<aspect>、不影响其它 aspect,全部失败才 isError=true。"
u8"每多选一个 aspect 就多一次子连接,耗时线性增长,不需要的不要选。只读。",
BuildHostInspectInputSchema(), BuildHostInspectOutputSchema());
}
// ---- 主机管理:4 个写工具(只读 + 可恢复操作) ----
@@ -3025,11 +3212,11 @@ void AppendTools(Json::Value& tools) {
types.append("integer");
types.append("string");
hwnd["type"] = types;
hwnd["description"] = u8"窗口句柄,取 host_list_windows 的 hwnd;整数或 0x 前缀字符串";
hwnd["description"] = u8"窗口句柄,取 host_inspect(aspects=[\"windows\"])或 list_windows 的 hwnd;整数或 0x 前缀字符串";
props["hwnd"] = hwnd;
props["dry_run"] = PropBool(u8"true 时只校验 hwnd 仍在可见窗口列表里并返回该窗口,不下发操作,默认 false");
AddTool(tools, "host_control_window",
u8"对在线 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 并返回窗口信息。",
u8"对在线 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 并返回窗口信息。",
MakeSchema(props, { "id", "action", "hwnd" }),
ActionOutputSchema());
}
@@ -3038,7 +3225,7 @@ void AppendTools(Json::Value& tools) {
props["id"] = HostIdProp();
props["action"] = PropStrEnum(u8"start/stop/pause/continue/restart",
{ "start", "stop", "pause", "continue", "restart" });
props["name"] = PropStr(u8"服务名(ServiceName,不是显示名),取 host_list_*_services 的 name");
props["name"] = PropStr(u8"服务名(ServiceName,不是显示名),取 host_inspect 的 win32_services / driver_services 项的 name");
props["dry_run"] = PropBool(u8"true 时只校验服务存在并返回当前状态,不下发控制命令,默认 false");
AddTool(tools, "host_control_service",
u8"控制在线 Windows 主机的服务:start/stop/pause/continue/restart。客户端对每次控制都会自动回一份刷新后的服务列表,工具据此复核状态并如实返回 ok;stop 与 restart 归入危险操作,需要同时开启 McpMachineDangerous。restart 先 stop 再 start。不提供删除服务。dry_run=true 只核实服务并返回当前状态,不下发命令(是否已是目标状态由你按 state 判断)。",
@@ -3049,7 +3236,7 @@ void AppendTools(Json::Value& tools) {
Json::Value props(Json::objectValue);
props["id"] = HostIdProp();
props["action"] = PropStrEnum(u8"run=立即运行,stop=停止正在运行的任务", { "run", "stop" });
props["name"] = PropStr(u8"任务名,取 host_list_scheduled_tasks 的 name");
props["name"] = PropStr(u8"任务名,取 host_inspect 的 scheduled_tasks 项的 name");
props["folder"] = PropStr(u8"可选:任务所在文件夹;同名任务存在多个时必填");
props["dry_run"] = PropBool(u8"true 时只校验任务存在(含同名歧义检查)并返回当前状态,不下发 run/stop,默认 false");
AddTool(tools, "host_control_task",
@@ -3077,7 +3264,8 @@ std::string Call(const Json::Value& id, const std::string& toolName,
if (toolName == "kill_network_connection")
return BuildKillNetworkConnection(id, args, parent);
// ---- 主机管理:只读 ----
// ---- 主机管理:只读(host_inspect 及合并后的旧名别名) ----
if (toolName == "host_inspect") return BuildHostInspect(id, args, parent);
if (toolName == "host_list_processes") return BuildHostListProcesses(id, args, parent);
if (toolName == "host_list_windows") return BuildHostListWindows(id, args, parent);
if (toolName == "host_list_network_state") return BuildHostListNetworkState(id, args, parent);