Skip to content

fix(mcp): project multi-content AIContent[] tool results for models - #2180

Open
syf2211 wants to merge 1 commit into
netclaw-dev:devfrom
syf2211:fix/mcp-multi-content-formatter-2051
Open

syf2211 wants to merge 1 commit into
netclaw-dev:devfrom
syf2211:fix/mcp-multi-content-formatter-2051

Conversation

@syf2211

@syf2211 syf2211 commented Sep 15, 2026

Copy link
Copy Markdown

Summary

Fix MCP tool result formatting when the SDK returns a successful multi-content result as in-memory AIContent[] objects (no structuredContent). The model now sees readable text and MIME markers instead of the literal type name Microsoft.Extensions.AI.AIContent[].

Fixes #2051

Motivation

For successful multi-content tool results (e.g. image + text chart payloads), McpToolResultFormatter.Format() only handled serialized JsonElement CallToolResult shapes. Clean AIContent[] values fell through to ToString(), which surfaces the collection type name and hides all tool output from the model.

Changes

  • Handle AIContent, AIContent[], and IEnumerable<AIContent> before the ToString() fallback
  • Project TextContent blocks as readable text, joined with newlines in order
  • Project DataContent image blocks as [image: <mime>] markers (no base64 bytes)
  • Project non-image DataContent as [attachment: <mime>]
  • Add regression tests for image+text, image-only, text-only, single TextContent, and non-image attachments

Tests

  • dotnet test src/Netclaw.Actors.Tests/Netclaw.Actors.Tests.csproj --filter FullyQualifiedName~McpToolResultFormatterTests — 15 passed
  • Reviewed with composer-2.5: APPROVE

Notes

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP multi-content tool result renders as literal type name (AIContent[]) instead of its content

1 participant