fix: surface MCP structuredContent-only results#8695
Open
Success6666 wants to merge 1 commit into
Open
Conversation
Signed-off-by: 李政达 <1242427577@qq.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes how MCP tool results are surfaced through Agno’s standard tool-result → model-message pipeline when an MCP server returns a successful response with an empty content array but a populated structuredContent. In that structured-only case, the structured payload is now serialized to JSON and placed into ToolResult.content while still preserving the original object in ToolResult.metadata["structured_content"].
Changes:
- Serialize
structuredContentintoToolResult.contentwhen no text output is produced from the MCPcontentarray. - Add a helper (
_structured_content_as_tool_output) to perform safe JSON serialization with fallbacks. - Add/extend unit tests to cover both the text-content and structured-only success cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| libs/agno/agno/utils/mcp.py | Adds structuredContent-to-JSON fallback so structured-only MCP successes become visible in ToolResult.content. |
| libs/agno/tests/unit/tools/test_mcp.py | Adds a regression test ensuring structured-only results serialize into content and remain preserved in metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
Beautiful, thank you @Success6666 |
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.
Summary
MCP tool results that only return
structuredContentnow surface that payload throughToolResult.contentwhen the normalcontentarray produces no text output.This keeps the existing metadata preservation from #8580, while making structured-only successful MCP responses visible to the standard tool-result -> model-message flow.
Fixes #8653
Type of change
Details
contentalready contains text, that text remains the primary tool output.contentis empty andstructuredContentis present, the structured payload is serialized as JSON forToolResult.content.metadata[structured_content]still preserves the original structured object.Tests