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:
yuanyuanxianganddeepseek-flash committed 2026-11-13 13:12:10 +01:00
1 parent 31883edc09
commit a818ace83c
5 files changed
+257 -1

No files matched your search

+117
View File
@@ -515,6 +515,47 @@
],
"impl": "mfc",
"inputSchema": {
"allOf": [
{
"if": {
"properties": {
"mode": {
"enum": [
"region"
]
}
},
"required": [
"mode"
]
},
"then": {
"required": [
"width",
"height"
]
}
},
{
"if": {
"properties": {
"mode": {
"enum": [
"window"
]
}
},
"required": [
"mode"
]
},
"then": {
"required": [
"hwnd"
]
}
}
],
"properties": {
"height": {
"description": "region 模式必填:矩形高度(像素,1~8192)。超出虚拟桌面的部分会被裁剪。",
@@ -1575,6 +1616,18 @@
],
"impl": "mfc",
"inputSchema": {
"anyOf": [
{
"required": [
"command"
]
},
{
"required": [
"session_id"
]
}
],
"properties": {
"command": {
"description": "要执行的命令(完整 shell,不受白名单约束)。省略时进入轮询模式:不执行新命令,只等待并取回当前会话的增量输出(上一条命令超时后用这个方式继续取)。PTY 会话(Windows ConPTY / Linux PTY)下可用管道 | 与 && / || 串联,退出码取整条管道/串联;不要用后台执行符 &(POSIX)或换行。老非 PTY 客户端仍不支持 & 与 |,请拆成多条调用。Linux 下通过 POSIX shell 执行,可用 ; 串联且退出码取最后一条命令",
@@ -1853,6 +1906,48 @@
],
"impl": "mfc",
"inputSchema": {
"allOf": [
{
"if": {
"properties": {
"action": {
"enum": [
"type"
]
}
},
"required": [
"action"
]
},
"then": {
"required": [
"text"
]
}
},
{
"if": {
"properties": {
"action": {
"enum": [
"key_down",
"key_up",
"key_press"
]
}
},
"required": [
"action"
]
},
"then": {
"required": [
"key"
]
}
}
],
"properties": {
"action": {
"description": "动作:key_down / key_up / key_press / type",
@@ -1937,6 +2032,28 @@
],
"impl": "mfc",
"inputSchema": {
"allOf": [
{
"if": {
"properties": {
"action": {
"enum": [
"drag"
]
}
},
"required": [
"action"
]
},
"then": {
"required": [
"x2",
"y2"
]
}
}
],
"properties": {
"action": {
"description": "动作:move / down / up / click / right_click / middle_click / drag / scroll",
+33
View File
@@ -446,6 +446,39 @@ void MakeIdOrIdsRequired(Json::Value& schema) {
schema["anyOf"] = anyOf;
}
void AppendConditionalRequired(Json::Value& schema, const char* prop,
std::initializer_list<const char*> values,
std::initializer_list<const char*> fields) {
Json::Value cond(Json::objectValue);
Json::Value ifSchema(Json::objectValue);
Json::Value reqProp(Json::arrayValue);
reqProp.append(prop);
ifSchema["required"] = reqProp;
if (values.size() > 0) {
Json::Value enums(Json::arrayValue);
for (const char* v : values)
enums.append(v);
Json::Value when(Json::objectValue);
when["enum"] = enums;
Json::Value props(Json::objectValue);
props[prop] = when;
ifSchema["properties"] = props;
}
cond["if"] = ifSchema;
Json::Value thenSchema(Json::objectValue);
Json::Value reqFields(Json::arrayValue);
for (const char* f : fields)
reqFields.append(f);
thenSchema["required"] = reqFields;
cond["then"] = thenSchema;
if (!schema.isMember("allOf") || !schema["allOf"].isArray())
schema["allOf"] = Json::Value(Json::arrayValue);
schema["allOf"].append(cond);
}
std::string PageSummary(const PageWindow& w, const char* unit) {
std::string s = std::string(u8"共 ") + std::to_string(w.total) + std::string(u8" ") + unit;
if (w.total == 0) return s + std::string(u8"。");
+9
View File
@@ -14,6 +14,7 @@
#include <string>
#include <cstdint>
#include <initializer_list>
#include <vector>
class CMy2015RemoteDlg;
@@ -178,6 +179,14 @@ void AppendBatchIdsProp(Json::Value& props);
// 把 inputSchema 的必填约束改成「id 或 ids 二选一」。
void MakeIdOrIdsRequired(Json::Value& schema);
// 往 inputSchema 追加一条条件必填:当 prop 出现且取值在 values 里(values 为空表示
// 只要出现就生效)时,fields 里的字段也必须提供。实现形态是 allOf 里的一条
// {"if":{"properties":{prop:{"enum":[...]}},"required":[prop]},"then":{"required":fields}},
// 从 schema 层面表达只写在描述里的条件约束,模型发参数前就能看到。
void AppendConditionalRequired(Json::Value& schema, const char* prop,
std::initializer_list<const char*> values,
std::initializer_list<const char*> fields);
// 统一的提示文字,例如「共 283 个进程,本次返回第 1-100 条(还有更多,可用 offset 继续取)。」
std::string PageSummary(const PageWindow& w, const char* unit);
+45 -1
View File
@@ -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);
+53
View File
@@ -328,6 +328,47 @@
"name": "get_screenshot",
"description": "截取指定在线主机的一帧画面,返回 base64 编码的 JPEG 图片:图片在 content 的 image 块(data 为 base64,mimeType=image/jpeg);structuredContent.image 只有 mimeType/width/height/bytes 元数据,不含图片数据。支持 Windows 与带 X11 桌面的 Linux 客户端(能力位 CLIENT_CAP_SCREEN_PREVIEW),主连接 RPC、一次性返回。Android 客户端用无障碍服务 takeScreenshot 抓屏(Android 11+ 且开启无障碍服务,此时登录会声明该能力位;只支持 mode=screen)。mode 可选 screen(默认,整虚拟桌面)/region(指定矩形)/window(指定 hwnd)/monitor(指定显示器);后三种默认按源尺寸 1:1 原生分辨率抓取(适合 OCR/视觉读字),需要较新的 Windows 客户端(CLIENT_CAP_SCREEN_REGION,否则 -32005),结果在 structuredContent.capture 里回报实际源矩形与缩放比例。",
"inputSchema": {
"allOf": [
{
"if": {
"properties": {
"mode": {
"enum": [
"region"
]
}
},
"required": [
"mode"
]
},
"then": {
"required": [
"width",
"height"
]
}
},
{
"if": {
"properties": {
"mode": {
"enum": [
"window"
]
}
},
"required": [
"mode"
]
},
"then": {
"required": [
"hwnd"
]
}
}
],
"properties": {
"height": {
"description": "region 模式必填:矩形高度(像素,1~8192)。超出虚拟桌面的部分会被裁剪。",
@@ -722,6 +763,18 @@
"name": "terminal_exec",
"description": "在已打开的持久会话中执行一条命令,或轮询取回正在运行的命令输出。带 command 时执行并在 timeout_ms 内等待;等待超时返回 done:false 与已产生的部分输出,会话不销毁(命令仍在远端运行)。session_id 可省略:自动复用该主机已有的持久会话,没有就隐式打开一个(结果里有 session_id 与 reused),不必先 terminal_open。不带 command、只传 session_id 时进入轮询模式:继续等待并取回增量输出,直到 done:true(此时有 exit_code)。命令不受白名单约束。PTY 会话(新 Windows 客户端 ConPTY / Linux 与新版 Android 的 POSIX PTY)下可用管道 | 与 && / || 串联,退出码取整条管道/串联,适合「ls -1 | wc -l」这类先过滤再回传的用法;不要用后台执行符 &(POSIX)或换行。老非 PTY Windows 客户端仍不支持 & 与 |,请拆成多条调用。",
"inputSchema": {
"anyOf": [
{
"required": [
"command"
]
},
{
"required": [
"session_id"
]
}
],
"properties": {
"command": {
"description": "要执行的命令(完整 shell,不受白名单约束)。省略时进入轮询模式:不执行新命令,只等待并取回当前会话的增量输出(上一条命令超时后用这个方式继续取)。PTY 会话(Windows ConPTY / Linux PTY)下可用管道 | 与 && / || 串联,退出码取整条管道/串联;不要用后台执行符 &(POSIX)或换行。老非 PTY 客户端仍不支持 & 与 |,请拆成多条调用。Linux 下通过 POSIX shell 执行,可用 ; 串联且退出码取最后一条命令",