fix(mcp): preserve structured_content in tool call results

MCP CallToolResult may include structured_content (a JSON object) alongside
content blocks. The tool handler previously only forwarded concatenated text
from content blocks, silently dropping the structured payload.

This breaks MCP tools that return a minimal human text in content while
putting the actual machine-usable payload in structured_content.

Now, when structured_content is present, it is included in the returned
JSON under the 'structuredContent' key.

Fixes NousResearch/hermes-agent#5874
This commit is contained in:
r266-tech 2026-04-08 02:15:37 +08:00 committed by Teknium
parent cbf1f15cfe
commit 2ad7694874

View file

@ -1253,7 +1253,16 @@ def _make_tool_handler(server_name: str, tool_name: str, tool_timeout: float):
for block in (result.content or []):
if hasattr(block, "text"):
parts.append(block.text)
return json.dumps({"result": "\n".join(parts) if parts else ""})
text_result = "\n".join(parts) if parts else ""
# Preserve structured_content (structuredContent) if present
structured = getattr(result, "structured_content", None)
if structured is not None:
return json.dumps({
"result": text_result,
"structuredContent": structured,
})
return json.dumps({"result": text_result})
try:
return _run_on_mcp_loop(_call(), timeout=tool_timeout)