Fix(mcp): make declared schemas match what the handlers return
Several tool contracts disagreed with the runtime shape, which forces an
agent to guess instead of following outputSchema:
- get_server_status returned {"status": {...}} while outputSchema has the
fields at top level; return the status object directly.
- get_screenshot description claimed structuredContent.image carries the
base64 data; it only carries mimeType/width/height/bytes, the bytes are
in the content image block.
- host_control_service accepted service_name silently, but not in schema;
document the alias and add anyOf [{required:[name]},{required:[service_name]}]
so a call missing both fails at validation, not at execution.
- kill_network_connection dry_run invented dryRun/connection fields absent
from ActionOutputSchema; use the shared BuildDryRunResult shape.
- search_file outputSchema left files.items untyped; declare
path/name/modified/dir/size and the paging fields it already emits.
- chat_* id hints still named the removed list_online_hosts/search_hosts.
tools.json hunks keep the live-dump key order (alphabetical inside schemas),
tools_minimal.json is regenerated, and mcp_smoke.ps1 now reads the flat
structuredContent. Debug build green; check_platform_table, gen_go_tools
--check and go test ./... pass.
Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
5e012019ba
commit
292c3191dc
7 files changed
+93
-23
No files matched your search
@@ -1537,14 +1537,11 @@ std::string BuildKillNetworkConnection(const Json::Value& id, const Json::Value&
|
||||
if (pidFilter < 0) pidFilter = (int)found->pid;
|
||||
|
||||
if (dryRun) {
|
||||
Json::Value sc(Json::objectValue);
|
||||
sc["ok"] = true;
|
||||
sc["dryRun"] = true;
|
||||
sc["target"] = target;
|
||||
sc["connection"] = targetJson;
|
||||
AuditManageAction(parent, ht.dev, toolName, target + " pid=" + std::to_string(pidFilter) +
|
||||
" result=dry_run");
|
||||
return BuildStructuredResult(id, sc, "Dry run: target found, nothing was sent");
|
||||
// 与其它动作工具的 dry_run 同一个形状:ok/dry_run/action/target/state/detail,
|
||||
// 不再自造 dryRun/target/connection 字段(schema 里没有,模型也得猜)。
|
||||
return BuildDryRunResult(id, "kill", target, "present", targetJson);
|
||||
}
|
||||
|
||||
// 会话保持:取列表用的是第一条 255,断开后客户端会自动再回一条 255。
|
||||
@@ -2581,8 +2578,9 @@ static std::string BuildHostControlService(const Json::Value& id, const Json::Va
|
||||
if (dangerous && !RequireDangerous(id, errJson)) return errJson;
|
||||
|
||||
std::string serviceName = Trim(GetStringArg(args, "name"));
|
||||
if (serviceName.empty()) serviceName = Trim(GetStringArg(args, "service_name"));
|
||||
if (serviceName.empty())
|
||||
return BuildError(id, -32602, "Missing required parameter: name (service name)");
|
||||
return BuildError(id, -32602, "Missing required parameter: name (service name; service_name is an accepted alias)");
|
||||
|
||||
HostTool ht;
|
||||
if (!ResolveHost(id, args, parent, ht, true, errJson)) return errJson;
|
||||
@@ -3238,9 +3236,21 @@ void AppendTools(Json::Value& tools) {
|
||||
props["name"] = PropStr(u8"服务名(ServiceName,不是显示名),取 host_inspect 的 win32_services / driver_services 项的 name;与 service_name 二选一");
|
||||
props["service_name"] = PropStr(u8"name 的旧参数名别名(与 name 等价,二选一)");
|
||||
props["dry_run"] = PropBool(u8"true 时只校验服务存在并返回当前状态,不下发控制命令,默认 false");
|
||||
// name 与 service_name 等价、二选一:只在 required 里写 id/action 会让两者都缺的
|
||||
// 调用也“符合 schema”,到执行期才报错;anyOf 让契约与实现一致。
|
||||
Json::Value schema = MakeSchema(props, { "id", "action" });
|
||||
Json::Value anyOf(Json::arrayValue);
|
||||
for (const char* key : { "name", "service_name" }) {
|
||||
Json::Value alt(Json::objectValue);
|
||||
Json::Value req(Json::arrayValue);
|
||||
req.append(key);
|
||||
alt["required"] = req;
|
||||
anyOf.append(alt);
|
||||
}
|
||||
schema["anyOf"] = anyOf;
|
||||
AddTool(tools, "host_control_service",
|
||||
u8"控制在线 Windows 主机的服务:start/stop/pause/continue/restart/set_auto/set_manual。start 等五个动作走主机管理链路:客户端对每次控制都会自动回一份刷新后的服务列表,工具据此复核状态并如实返回 ok;stop 与 restart 归入危险操作,需要同时开启 McpMachineDangerous;restart 先 stop 再 start。set_auto/set_manual 没有主机管理实现,转由主连接版 control_service 处理(ok 只表示已下发、需另查状态;McpManage=0 时返回 -32006)——它们只在 McpMachine=0 时才以 control_service 之名出现在 tools/list。不提供删除服务。dry_run=true 只核实服务并返回当前状态,不下发命令(是否已是目标状态由你按 state 判断);set_auto/set_manual 不支持 dry_run(返回 -32602)。",
|
||||
MakeSchema(props, { "id", "action" }),
|
||||
schema,
|
||||
ActionOutputSchema());
|
||||
}
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user