Python: fix(mcp): do not duplicate structuredContent when content present - #8274
Python: fix(mcp): do not duplicate structuredContent when content present#8274LI (ktz03) wants to merge 2 commits into
Conversation
Fixes microsoft#7866. Prefer content blocks for model-visible tool results; structuredContent remains on the Host payload. Serialize structuredContent only when content is empty.
|
Fork CI for this PR may need a maintainer to Approve workflows before Python tests run (same as other community PRs). Happy to address review feedback once checks appear. |
There was a problem hiding this comment.
🟡 Changes recommended
Existing test expectations still require the old duplicate-output behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes duplicate MCP tool output when both content and structuredContent are present.
Changes:
- Use
structuredContentas model-visible content only when regular content is empty. - Preserve the complete structured payload for host transports.
- Update parser regression coverage.
File summaries
| File | Summary |
|---|---|
python/packages/core/agent_framework/_mcp.py |
Prevents duplicate structured content. Moderate finding (3 votes): remaining test expectations must be updated. |
python/packages/core/tests/core/test_mcp.py |
Updates structured-content parsing expectations; several existing expectations still require the old duplicate behavior. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
Address Copilot review on microsoft#8274: update suites that still expected the old duplicated model-visible content shape.
|
Follow-up for Copilot review: aligned the three suites that still expected duplicated |
|
CI is green on this branch. The scoped MCP change (skip dumping Happy to help with any follow-up nits if maintainers want a second look. |
Ricky-7-Yan
left a comment
There was a problem hiding this comment.
I don't think this should hard-code content-first behavior yet.
The issue discussion identified two distinct cases: servers that duplicate the same value in content and structuredContent, and servers where the two fields are complementary. This implementation fixes the former by dropping structuredContent whenever any content block exists, but it also silently removes complementary structured data from the model-visible result.
That is the ambiguity maintainers called out in #7866, where the direction discussed was an explicit selection policy (structured first, content first, content only, structured only, or both), likely with a documented default. Could this expose that policy instead of choosing content-first globally? The tests should cover structured-only, content-only, equivalent-both, complementary-both, and retention of the full payload in HostMessageContent.
Description
Fixes #7866. MCP
CallToolResultoften returns bothcontentandstructuredContent._parse_tool_result_from_mcppreviously appended a JSON dump ofstructuredContenteven whencontentalready had items, so the model saw duplicated tool output.Change: only serialize
structuredContentinto model-visibleContentwhencontentproduced no items. Host transports still retain completestructuredContenton the existing Host payload marker.Validation
test_parse_tool_result_from_mcp_structured_content_with_texttest_parse_tool_result_from_mcp_structured_content_onlystill covers the empty-content fallback