Feature(mcp): allow sc qc/enumdepend/sdshow in default command whitelist

exec_command's read-only default whitelist only listed `sc query`, so service
configuration inspection was rejected even though `sc qc` is a read. Add
`sc qc`, `sc enumdepend` and `sc sdshow`; `sc start/stop/config/create/delete`
stay rejected because matching is prefix based, and a comment says so.

verify_tools.py --live now prints the tools/list response size plus the
description / inputSchema / outputSchema breakdown, so shrinking tools/list can
be measured against a running server.

Verified on an isolated Debug instance (port 6555, local test client): sc
qc/enumdepend/sdshow/query succeed; powershell, icacls, net user, net
localgroup, sc start and `&` chaining still return -32007/-32012; tools.json
still matches the live tools/list (63 tools, PASS).

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-12 15:41:23 +01:00
1 parent f5ac7ba45f
commit b63c97c5eb
2 files changed
+21 -3

No files matched your search

+2 -1
View File
@@ -3814,9 +3814,10 @@ std::string BuildListRegistry(const Json::Value& id, const Json::Value& args, CM
// exec_command 默认白名单:只读命令前缀(逗号分隔,前缀匹配,大小写不敏感)。
// 只放查询/只读类命令;写命令(del/copy/move/reg add/sc stop/...)一律不在列。
// sc 只放查询类子命令(qc/enumdepend/sdshow);sc start/stop/config/create/delete 都是写。
static const char* kDefaultCmdWhitelist =
"dir,type,cd,chdir,ver,hostname,whoami,where,tasklist,systeminfo,ipconfig,netstat,"
"path,set,find,findstr,reg query,sc query,"
"path,set,find,findstr,reg query,sc query,sc qc,sc enumdepend,sc sdshow,"
"ping,tracert,nslookup,getmac,driverquery,query,gpresult,"
"arp -a,route print,schtasks /query";
+19 -2
View File
@@ -69,7 +69,21 @@ def fetch_live(token, port=None):
conn.close()
if resp.status == 200:
print(f"连接 127.0.0.1:{p} ({'TLS' if tls else 'plain'})")
return json.loads(raw.decode("utf-8"))["result"]["tools"]
obj = json.loads(raw.decode("utf-8"))
tools = obj["result"]["tools"]
stats = {
"response_bytes": len(raw),
"tools_array_bytes": len(
json.dumps(tools, ensure_ascii=False, separators=(",", ":")).encode("utf-8")),
"description_bytes": sum(len(t.get("description", "").encode("utf-8")) for t in tools),
"input_schema_bytes": sum(
len(json.dumps(t.get("inputSchema", {}), ensure_ascii=False, separators=(",", ":")).encode("utf-8"))
for t in tools),
"output_schema_bytes": sum(
len(json.dumps(t.get("outputSchema", {}), ensure_ascii=False, separators=(",", ":")).encode("utf-8"))
for t in tools),
}
return tools, stats
last = f"{p}: HTTP {resp.status} {raw[:200].decode('utf-8', 'replace')}"
except Exception as e:
last = f"{p}: {e}"
@@ -95,8 +109,11 @@ def main():
port = int(args[3]) if len(args) > 3 else None
if not token:
sys.exit("未找到 McpToken(参数 / YAMA_MCP_TOKEN / 注册表 均无)")
tools_live = fetch_live(token, port)
tools_live, live_stats = fetch_live(token, port)
print(f"活服务: 127.0.0.1:{port if port else 'auto'}")
print(f"体积: 响应 {live_stats['response_bytes']} B / tools 数组 {live_stats['tools_array_bytes']} B"
f"(description {live_stats['description_bytes']} / inputSchema {live_stats['input_schema_bytes']}"
f" / outputSchema {live_stats['output_schema_bytes']})")
else:
sys.exit(__doc__)