From 2ad769487492ba53e6c986df5b8e387761a83926 Mon Sep 17 00:00:00 2001 From: r266-tech Date: Wed, 8 Apr 2026 02:15:37 +0800 Subject: [PATCH] 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 --- tools/mcp_tool.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/mcp_tool.py b/tools/mcp_tool.py index 1ff42e77b2..c055e44f90 100644 --- a/tools/mcp_tool.py +++ b/tools/mcp_tool.py @@ -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)