Feature(mcp): hide the degraded list_* tools when host management is on

host_inspect now covers processes, windows and services, so with
McpMachine=1 the older list_processes / list_windows / list_services
entries only competed with it: same intent, two names, two long
descriptions to read before choosing. They no longer appear in
tools/list while host management is enabled, but their names still
dispatch, so callers that cached them keep working.

They must stay visible when McpMachine=0: that is the default state and
the only way such a server can list processes, windows or services, so
the entries sit behind !IsMachineEnabled() rather than being removed.
list_network_connections is deliberately not folded in: it reads the
connection-manager view (IPv6 rows, killable flag, numeric state) which
host_inspect's IPv4-only network aspect does not provide.

tools.json is now generated from two captures, all-switches-on plus
McpMachine=0, because neither state contains the whole surface; the
off-state entries are marked gate "!machine" and verify_tools.py skips
them when comparing against an all-on server. tools/list went from 54
to 51 entries and from 183,336 B to 171,929 B (-6.2%).

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-12 17:28:28 +01:00
1 parent 59f0f16f74
commit c73db530f4
4 files changed
+543 -488

No files matched your search

+44 -5
View File
@@ -11,10 +11,17 @@ import json
import sys
if len(sys.argv) < 3:
sys.exit("用法: python make_tools_json.py <tools_raw.json> <mcp/tools.json>")
sys.exit("用法: python make_tools_json.py <tools_raw.json> <mcp/tools.json> [tools_raw_machine_off.json]")
SRC = sys.argv[1]
DST = sys.argv[2]
# 可选:McpMachine=0 状态下的抓取。开启态的抓取里没有降级工具(P2-2),
# 而它们仍是真实工具,必须进清单——所以清单 = 两份抓取的并集。
OFF_SRC = sys.argv[3] if len(sys.argv) > 3 else None
# 只在 McpMachine=0 时出现的降级工具(gate = "!machine")。改动这个集合要同步更新
# McpServer.cpp 里 showDegradedLists 那段。
MACHINE_OFF_FALLBACKS = {"list_processes", "list_windows", "list_services"}
# gate: 该工具要求哪个服务端开关为开(null = 无条件出现)
# write: 需要 !McpReadonly
@@ -24,13 +31,16 @@ GATE = {
# P1-1:list_online_hosts / search_hosts / list_all_hosts 三合一(旧名为别名,不出现在 tools/list)
"list_hosts": (None, False, False),
"get_host_detail": (None, False, False),
"list_processes": (None, False, False),
"list_windows": (None, False, False),
# ---- McpMachine=0 时的降级路径(P2-2)----
# 开启主机管理后它们由 host_inspect 的 processes / windows / win32_services 项取代,
# 所以只在开关关闭时进 tools/list(名字仍可作为别名调用)。
"list_processes": ("!machine", False, False),
"list_windows": ("!machine", False, False),
"list_services": ("!machine", False, False),
"get_activity_history": (None, False, False),
"get_screenshot": (None, False, False),
"get_foreground_window": (None, False, False),
"list_files": (None, False, False),
"list_services": (None, False, False),
"get_client_log": (None, False, False),
"get_audit_log": (None, False, False),
"get_server_status": (None, False, False),
@@ -239,7 +249,33 @@ ROLES = {
}
raw = json.load(open(SRC, encoding="utf-8"))
tools_in = raw["result"]["tools"]
tools_on = raw["result"]["tools"]
# 并集:开启态抓取 + 关闭态抓取里独有的降级工具。关闭态工具的描述/schema 也必须来自
# 活服务端,不能沿用旧清单,否则清单会和二进制悄悄漂移。
if OFF_SRC:
tools_off = json.load(open(OFF_SRC, encoding="utf-8"))["result"]["tools"]
on_names = {t["name"] for t in tools_on}
off_names = {t["name"] for t in tools_off}
off_only = [t for t in tools_off if t["name"] not in on_names]
bad = [t["name"] for t in off_only if GATE.get(t["name"], (None,))[0] != "!machine"]
if bad:
print(f"!! 关闭态抓取里有未声明为 !machine 的工具: {bad}", file=sys.stderr)
sys.exit(1)
absent = sorted(MACHINE_OFF_FALLBACKS - off_names)
if absent:
print(f"!! 关闭态抓取里缺少降级工具: {absent}", file=sys.stderr)
sys.exit(1)
leaked = sorted(n for n in MACHINE_OFF_FALLBACKS if n in on_names)
if leaked:
print(f"!! 开启态抓取里出现了降级工具(应已隐藏): {leaked}", file=sys.stderr)
sys.exit(1)
tools_on = tools_on + off_only
elif MACHINE_OFF_FALLBACKS & {t["name"] for t in tools_on}:
print("!! 未提供关闭态抓取,但开启态里有降级工具——清单会丢工具", file=sys.stderr)
sys.exit(1)
tools_in = tools_on
missing = [t["name"] for t in tools_in if t["name"] not in GATE]
if missing:
@@ -301,6 +337,9 @@ doc = {
"由 tools/mcp_tools/dump_tools.py 抓取、make_tools_json.py 生成,勿手工编辑。",
"gate: 该工具出现的开关条件(null = 无条件);write: 需 !McpReadonly;",
"manage: 额外需 McpManage。这三项从 C++ 注册点的 if 条件解析而来,运行时不可见。",
"gate 为 \"!machine\" 表示该降级工具只在 McpMachine=0 时出现(开启主机管理后",
"由 host_inspect 的对应 aspect 取代,名字仍可作为别名调用);清单是开启态与",
"关闭态两份抓取的并集。",
"platforms: 该工具涉及的任一主机都必须落在此集合内(win/lnx/mac/apk),依据各平台",
"客户端对相应 COMMAND_ 的处理实现。apk 上 COMMAND_SYSTEM 与 COMMAND_SHELL 均为空实现。",
"roles: 仅多主机工具才有。按参数名细分平台,表达 platforms 说不清的方向性能力",