Fix: Expose tool payloads in the content text block
List and query tools put only a human summary in content and kept the real payload in structuredContent. Clients that hand just content to the model (WorkBuddy does) therefore never saw a host id: search_hosts answered "1 host matched" and every follow-up tool was out of reach, and guessed ids 1-3100 could never work because host ids are 64-bit snowflake values. BuildResult now appends the serialized structuredContent as a second text block, as the MCP spec recommends for tools with structured output. The append sits in the single result choke point, so every tool in McpServer, McpMachine and McpChat gains it, including future ones; empty action results such as remote_mouse keep their bare "ok". Tools whose text already carries the payload expose only the difference: exec_command and terminal_exec add exit_code, get_keylog adds counters, get_activity_history exposes records without the duplicated raw dump, and the hosts file reader drops its copy of the content. The override rides in a $ key that BuildResult consumes and removes, so responses change only by the extra block. Verified on a Debug instance: list_all_hosts, search_hosts, get_server_status and list_registry return parseable JSON in content[1] with ids intact, and tools/mcp_smoke.ps1 -SkipHost passes 27/27 with four new assertions. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
a7dd86ff0f
commit
27d40f5678
6 files changed
+153
-5
No files matched your search
@@ -276,9 +276,13 @@ Json::Value ActionOutputSchema() {
|
||||
}
|
||||
|
||||
std::string BuildStructuredResult(const Json::Value& id, const Json::Value& sc,
|
||||
const std::string& text) {
|
||||
const std::string& text,
|
||||
const Json::Value* textPayload = nullptr) {
|
||||
Json::Value result(Json::objectValue);
|
||||
result["structuredContent"] = sc;
|
||||
// 默认由 BuildResult 把 structuredContent 原样外露到 content;工具可指定更小的
|
||||
// 载荷(例如 hosts 文件只外露 lines,不再重复 content 原文)。
|
||||
if (textPayload) SetStructuredTextPayload(result, *textPayload);
|
||||
|
||||
Json::Value content(Json::arrayValue);
|
||||
Json::Value item(Json::objectValue);
|
||||
@@ -2000,7 +2004,10 @@ static std::string BuildHostGetHostsFile(const Json::Value& id, const Json::Valu
|
||||
|
||||
std::string summary = std::string(u8"hosts 文件 ") + std::to_string(contentLen) + u8" 字节" +
|
||||
(truncated ? u8"(已截断)" : "");
|
||||
return BuildStructuredResult(id, sc, summary);
|
||||
// 正文外露 lines + 元数据即可;sc 里的 content 是同一份原文,别再重复一遍。
|
||||
Json::Value textPayload = sc;
|
||||
textPayload.removeMember("content");
|
||||
return BuildStructuredResult(id, sc, summary, &textPayload);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in new issue
Block a user