Skip to content

Python: fix(mcp): do not duplicate structuredContent when content present - #8274

Open
LI (ktz03) wants to merge 2 commits into
microsoft:mainfrom
ktz03:fix/mcp-no-duplicate-structured-content
Open

Python: fix(mcp): do not duplicate structuredContent when content present#8274
LI (ktz03) wants to merge 2 commits into
microsoft:mainfrom
ktz03:fix/mcp-no-duplicate-structured-content

Conversation

@ktz03

Copy link
Copy Markdown

Description

Fixes #7866. MCP CallToolResult often returns both content and structuredContent. _parse_tool_result_from_mcp previously appended a JSON dump of structuredContent even when content already had items, so the model saw duplicated tool output.

Change: only serialize structuredContent into model-visible Content when content produced no items. Host transports still retain complete structuredContent on the existing Host payload marker.

Validation

  • Updated test_parse_tool_result_from_mcp_structured_content_with_text
  • Existing test_parse_tool_result_from_mcp_structured_content_only still covers the empty-content fallback

Fixes microsoft#7866. Prefer content blocks for model-visible tool results; structuredContent remains on the Host payload. Serialize structuredContent only when content is empty.
@ktz03

Copy link
Copy Markdown
Author

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.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Sep 10, 2026
@ktz03
LI (ktz03) deployed to github-app-auth September 10, 2026 23:27 — with GitHub Actions Active

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 structuredContent as 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

Comment thread python/packages/core/agent_framework/_mcp.py
Address Copilot review on microsoft#8274: update suites that still expected the old duplicated model-visible content shape.
@ktz03
LI (ktz03) deployed to github-app-auth September 11, 2026 05:10 — with GitHub Actions Active
@ktz03

Copy link
Copy Markdown
Author

Follow-up for Copilot review: aligned the three suites that still expected duplicated content+structuredContent items with the single-item contract. See 6d58210.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: MCP tools return double output if CallToolResult contains both content and structuredContent

2 participants