Fix(mcp): declare conditional tool arguments and surface probe headers
Several tools enforced argument requirements that existed only in prose, so a model had to send a bad call to learn them. A new AppendConditionalRequired helper emits allOf/if/then entries, and the schemas now say: - get_screenshot: mode=region needs width and height; mode=window needs hwnd. monitor keeps its default of 0. - remote_keyboard: action=type needs text; key_down/key_up/key_press need key. - remote_mouse: action=drag needs x2 and y2. - terminal_exec: command or session_id, at least one (anyOf), matching the handler's -32602 when both are missing. http_probe put the response headers only in structuredContent, which a client that reads the text block never sees; Location, Set-Cookie and Content-Type are exactly what a redirect or auth decision needs. The text block now starts with a headers section, bounded to 4096 bytes and 1200 bytes per line, backing off to a UTF-8 boundary when a line has to be cut. The full set stays in structuredContent.headers. mcp/tools.json mirrors the schemas and tools_minimal.json is regenerated. Verified against a fresh Debug build: verify_tools --live reports 49 tools identical. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
31883edc09
commit
a818ace83c
5 files changed
+257
-1
No files matched your search
@@ -1971,6 +1971,10 @@ Json::Value BuildGetScreenshotInputSchema() {
|
||||
Json::Value required(Json::arrayValue);
|
||||
required.append("id");
|
||||
schema["required"] = required;
|
||||
// region 需 width/height、window 需 hwnd(handler 会以 -32602 拒);monitor 有默认 0,
|
||||
// 无需条件。x/y 在 region 下可省略(按 0),故不进 then。
|
||||
AppendConditionalRequired(schema, "mode", { "region" }, { "width", "height" });
|
||||
AppendConditionalRequired(schema, "mode", { "window" }, { "hwnd" });
|
||||
return schema;
|
||||
}
|
||||
|
||||
@@ -4963,6 +4967,17 @@ Json::Value BuildTerminalExecInputSchema() {
|
||||
Json::Value required(Json::arrayValue);
|
||||
required.append("id");
|
||||
schema["required"] = required;
|
||||
// 执行(带 command)可省略 session_id,轮询(不带 command)必须带 session_id;
|
||||
// 两者都没有时 handler 直接 -32602。用 anyOf 把这条只写在描述里的约束落到 schema。
|
||||
Json::Value anyOf(Json::arrayValue);
|
||||
for (const char* key : { "command", "session_id" }) {
|
||||
Json::Value alt(Json::objectValue);
|
||||
Json::Value req(Json::arrayValue);
|
||||
req.append(key);
|
||||
alt["required"] = req;
|
||||
anyOf.append(alt);
|
||||
}
|
||||
schema["anyOf"] = anyOf;
|
||||
return schema;
|
||||
}
|
||||
|
||||
@@ -6067,6 +6082,10 @@ Json::Value BuildRemoteKeyboardInputSchema() {
|
||||
required.append("session_id");
|
||||
required.append("action");
|
||||
schema["required"] = required;
|
||||
// 描述里写明「type 用 text、按键动作用 key」,但 schema 只要求 id/session_id/action,
|
||||
// 漏字段要到 handler 才报错。条件必填让模型在发参数前就看到。
|
||||
AppendConditionalRequired(schema, "action", { "type" }, { "text" });
|
||||
AppendConditionalRequired(schema, "action", { "key_down", "key_up", "key_press" }, { "key" });
|
||||
return schema;
|
||||
}
|
||||
|
||||
@@ -6541,6 +6560,8 @@ Json::Value BuildRemoteMouseInputSchema() {
|
||||
required.append("x");
|
||||
required.append("y");
|
||||
schema["required"] = required;
|
||||
// drag 的终点坐标 x2/y2 在描述里标了「仅 drag」,schema 里补成条件必填。
|
||||
AppendConditionalRequired(schema, "action", { "drag" }, { "x2", "y2" });
|
||||
return schema;
|
||||
}
|
||||
|
||||
@@ -8879,9 +8900,32 @@ std::string BuildHttpProbe(const Json::Value& id, const Json::Value& args, CMy20
|
||||
+ " | " + std::to_string(rawBody.size()) + " bytes"
|
||||
+ (p.truncated ? " (truncated)" : "")
|
||||
+ " | " + std::to_string(p.elapsedMs) + " ms";
|
||||
// 响应头也写进 text:只读 content 文本的客户端看不到 structuredContent.headers,
|
||||
// 而 Location/Set-Cookie/Content-Type 正是判断重定向与鉴权状态要用的。整体限长
|
||||
// (单个值也限长),完整响应头仍在 structuredContent.headers 里。
|
||||
const size_t kMaxHeaderTextBytes = 4096;
|
||||
const size_t kMaxHeaderLineBytes = 1200;
|
||||
std::string headerText;
|
||||
for (const std::string& key : hdrs.getMemberNames()) {
|
||||
if (headerText.size() >= kMaxHeaderTextBytes) {
|
||||
headerText += "(truncated; full response headers are in structuredContent.headers)\n";
|
||||
break;
|
||||
}
|
||||
std::string line = key + ": " + hdrs[key].asString();
|
||||
if (line.size() > kMaxHeaderLineBytes) {
|
||||
// 按字节截断可能切在多字节 UTF-8 字符中间:回退到该字符的首字节。
|
||||
size_t cut = kMaxHeaderLineBytes;
|
||||
while (cut > 0 && ((unsigned char)line[cut] & 0xC0) == 0x80)
|
||||
--cut;
|
||||
line = line.substr(0, cut) + "...";
|
||||
}
|
||||
headerText += line + "\n";
|
||||
}
|
||||
std::string text = head;
|
||||
if (!headerText.empty())
|
||||
text += "\nheaders:\n" + headerText;
|
||||
if (!rawBody.empty())
|
||||
text += "\n" + (bodyUtf8 ? rawBody : std::string("(base64) ") + sc["body_base64"].asString());
|
||||
text += "\nbody:\n" + (bodyUtf8 ? rawBody : std::string("(base64) ") + sc["body_base64"].asString());
|
||||
|
||||
Json::Value content(Json::arrayValue);
|
||||
Json::Value item(Json::objectValue);
|
||||
|
||||
Reference in new issue
Block a user