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:
1 parent
59f0f16f74
commit
c73db530f4
4 files changed
+543
-488
No files matched your search
@@ -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 说不清的方向性能力",
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
port 省略时自动探测 6545(明文后端)/ 6544(TLS 前端)
|
||||
|
||||
比对内容:name / description / inputSchema / outputSchema,逐字段深度比较,
|
||||
外加工具顺序。gate / write / manage / impl 是 tools.json 独有的元信息,不参与比对。
|
||||
外加工具顺序。gate / write / manage / impl 是 tools.json 独有的元信息,不参与比对;
|
||||
例外是 gate == "!machine" 的降级工具——它们只在 McpMachine=0 时出现,不进本次比对。
|
||||
"""
|
||||
import http.client
|
||||
import json
|
||||
@@ -119,14 +120,20 @@ def main():
|
||||
|
||||
doc = json.load(open(path, encoding="utf-8"))
|
||||
tools_json = doc["tools"]
|
||||
# gate == "!machine" 的工具只在 McpMachine=0 时出现,而黄金样本/活服务都是开关
|
||||
# 全开的抓取,按约定它们不该在这里出现(tools.json 是两份抓取的并集)。
|
||||
off_gated = {t["name"] for t in tools_json if t.get("gate") == "!machine"}
|
||||
tools_cmp = [t for t in tools_json if t["name"] not in off_gated]
|
||||
print(f"tools.json: {path} ({len(tools_json)} 个工具)")
|
||||
if off_gated:
|
||||
print(f" 其中 {len(off_gated)} 个 !machine 降级工具不计入本次比对: {sorted(off_gated)}")
|
||||
print(f"服务端: {len(tools_live)} 个工具")
|
||||
|
||||
if len(tools_json) != len(tools_live):
|
||||
print(f"!! 数量不一致: {len(tools_json)} vs {len(tools_live)}")
|
||||
if len(tools_cmp) != len(tools_live):
|
||||
print(f"!! 数量不一致: {len(tools_cmp)} vs {len(tools_live)}")
|
||||
|
||||
live_by_name = {t["name"]: t for t in tools_live}
|
||||
json_by_name = {t["name"]: t for t in tools_json}
|
||||
json_by_name = {t["name"]: t for t in tools_cmp}
|
||||
|
||||
only_live = sorted(set(live_by_name) - set(json_by_name))
|
||||
only_json = sorted(set(json_by_name) - set(live_by_name))
|
||||
@@ -156,7 +163,7 @@ def main():
|
||||
|
||||
# 顺序一致性:tools/list 的数组顺序会影响模型的选择倾向
|
||||
order_live = [t["name"] for t in tools_live]
|
||||
order_json = [t["name"] for t in tools_json]
|
||||
order_json = [t["name"] for t in tools_cmp]
|
||||
if order_live != order_json:
|
||||
print("!! 工具顺序不一致")
|
||||
for i, (x, y) in enumerate(zip(order_live, order_json)):
|
||||
@@ -168,7 +175,7 @@ def main():
|
||||
print("工具顺序: 一致")
|
||||
|
||||
if diffs == 0 and not only_live and not only_json:
|
||||
print(f"\nPASS: {len(tools_json)} 个工具完全一致")
|
||||
print(f"\nPASS: {len(tools_cmp)} 个工具完全一致")
|
||||
return 0
|
||||
print(f"\nFAIL: {diffs} 处差异")
|
||||
return 1
|
||||
|
||||
Reference in new issue
Block a user