Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python/packages/core/agent_framework/_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,10 @@ def _parse_tool_result_from_mcp(
case _:
result.append(Content.from_text(str(item), **additional_kwargs))

if mcp_type.structuredContent is not None:
# Prefer content blocks for the model-visible result. structuredContent is
# still retained on the Host payload; appending it again here duplicates
# what many servers already serialize into content (#7866).
if mcp_type.structuredContent is not None and not result:
result.append(Content.from_text(json.dumps(mcp_type.structuredContent, default=str), **additional_kwargs))
Comment thread
ktz03 marked this conversation as resolved.
Resolved

if not result:
Expand Down
8 changes: 2 additions & 6 deletions python/packages/core/tests/core/test_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,21 +546,17 @@ def test_parse_tool_result_from_mcp_structured_content_only():


def test_parse_tool_result_from_mcp_structured_content_with_text():
"""Test that structuredContent is appended alongside regular content items."""
"""When content is present, do not also dump structuredContent into model text (#7866)."""
mcp_result = types.CallToolResult(
content=[types.TextContent(type="text", text="Summary")],
structuredContent={"data": [1, 2, 3]},
)
result = _HELPER_MCP_TOOL._parse_tool_result_from_mcp(mcp_result)

assert isinstance(result, list)
assert len(result) == 2
assert len(result) == 1
assert result[0].type == "text"
assert result[0].text == "Summary"
assert result[1].type == "text"
assert result[1].text is not None
parsed = json.loads(result[1].text)
assert parsed == {"data": [1, 2, 3]}


async def test_generated_mcp_tool_preserves_complete_host_payload_once() -> None:
Expand Down
Loading