Repository navigation
Conversation
SingleItemOrListConverter<T> serialized each item via GetTypeInfo(typeof(object)), which resolves the derived type's default contract (e.g. ImageContentBlock) and bypasses ContentBlock.Converter. The default contract base64-encodes the ReadOnlyMemory<byte> Data property, which already holds base64 UTF-8 bytes, so image and audio data in SamplingMessage.Content and CreateMessageResult.Content were encoded twice on the wire. Serialize items via GetTypeInfo(typeof(T)) instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #2033
SingleItemOrListConverter<T>.Writeserialized items viaGetTypeInfo(typeof(object)), which uses the derived type's default contract and bypassesContentBlock.Converter. ForImageContentBlock/AudioContentBlockthis base64-encoded the already-encodedDataa second time, so images/audio inSamplingMessage.ContentandCreateMessageResult.Contentwere corrupted on the wire.Items are now serialized via
GetTypeInfo(typeof(T)), matching howReadalready deserializes them.Tests
Added tests in
SamplingMessageTestsasserting that thedatafield equals the single base64 encoding and round-trips to the original bytes, for a single image, an image in a multi-block message, andCreateMessageResult. They fail before the change and pass after.ModelContextProtocol.Tests(excluding stdio integration tests that need external servers) andModelContextProtocol.AspNetCore.Testspass on net10.0.🤖 Generated with Claude Code