Python: Return MCP tool-use sampling results#7189
Open
scarab-systems wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Python MCP sampling so that structured model outputs returned as Agent Framework function_call content are converted back into MCP ToolUseContent, allowing structured sampling clients to receive tool-use results instead of an internal error.
Changes:
- Add Agent Framework
function_call→ MCPToolUseContentconversion in_prepare_content_for_mcp(). - Update
sampling_callback()to aggregate content across all response messages and returnCreateMessageResultWithTools(stopReason="toolUse")when tool-use content is present. - Add a regression test covering multiple tool-use calls returned from a sampling response.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_mcp.py | Converts function_call content into MCP ToolUseContent and returns CreateMessageResultWithTools when tool-use content is produced during sampling. |
| python/packages/core/tests/core/test_mcp.py | Adds regression coverage ensuring multiple function calls are preserved and returned as MCP tool-use sampling results. |
scarab-systems
marked this pull request as ready for review
July 18, 2026 22:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
MCP sampling requests can forward tool schemas to the configured chat client, but structured responses that come back as Agent Framework function-call content were not converted back to MCP tool-use content. This caused structured sampling clients to receive an internal error instead of the tool-use result.
Fixes #7160
Description & Review Guide
What are the major changes?
function_callcontent into MCPToolUseContent.CreateMessageResultWithToolswithstopReason="toolUse"when sampling produces tool-use content.What is the impact of these changes?
What do you want reviewers to focus on?
ToolUseContentmapping and the precedence of structured tool-use responses over plain text/image selection.Related Issue
Fixes #7160
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.