Conversation
When the MCP SDK returns a successful multi-content result as in-memory AIContent objects, Format() no longer falls through to ToString() (which surfaced the literal type name). Text blocks are joined readably and image attachments are projected as MIME markers without embedding bytes. Fixes netclaw-dev#2051
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
Fix MCP tool result formatting when the SDK returns a successful multi-content result as in-memory
AIContent[]objects (nostructuredContent). The model now sees readable text and MIME markers instead of the literal type nameMicrosoft.Extensions.AI.AIContent[].Fixes #2051
Motivation
For successful multi-content tool results (e.g. image + text chart payloads),
McpToolResultFormatter.Format()only handled serializedJsonElementCallToolResultshapes. CleanAIContent[]values fell through toToString(), which surfaces the collection type name and hides all tool output from the model.Changes
AIContent,AIContent[], andIEnumerable<AIContent>before theToString()fallbackTextContentblocks as readable text, joined with newlines in orderDataContentimage blocks as[image: <mime>]markers (no base64 bytes)DataContentas[attachment: <mime>]TextContent, and non-image attachmentsTests
dotnet test src/Netclaw.Actors.Tests/Netclaw.Actors.Tests.csproj --filter FullyQualifiedName~McpToolResultFormatterTests— 15 passedNotes
JsonElementerror andstructuredContentformatting paths are unchanged