Title
0.9.0-preview.1: ImageContentBlock throws "invalid base64" when consuming CallToolResult (works in 0.8.0-preview.1)
Description
After upgrading from ModelContextProtocol 0.8.0-preview.1 to 0.9.0-preview.1, consuming an MCP server CallToolResult that includes an ImageContentBlock now throws an "invalid base64" exception.
The exact same MCP server response works correctly in:
- 0.8.0-preview.1
- Postman (image renders correctly)
This appears to be a regression introduced in 0.9.0-preview.1, possibly related to the change of ImageContentBlock.Data from string to ReadOnlyMemory<byte> and how JSON deserialization handles base64 content.
Expected Behavior
CallToolResult containing an ImageContentBlock should deserialize successfully and allow access to the image data (via DecodedData or Data) without throwing.
This worked correctly in 0.8.0-preview.1.
Actual Behavior
When consuming the tool result:
- Accessing
ImageContentBlock causes an "invalid base64" exception.
- In some cases, accessing
DecodedData triggers the exception.
- The same payload renders correctly in Postman.
- The server response contains valid base64 (confirmed visually and by rendering in Postman).
Repro Steps
- Use ModelContextProtocol 0.9.0-preview.1
- Connect to MCP server
- Invoke a tool that returns an
ImageContentBlock
- Receive
CallToolResult
- Access image content (e.g.,
DecodedData)
Result: FormatException / invalid base64 error
Reverting to 0.8.0-preview.1 resolves the issue immediately.
Sample Tool Result Payload (Redacted)
{
"content": [
{
"type": "image",
"mimeType": "image/png",
"data": "<valid base64 string>"
}
]
}
Notes:
- No
data:image/... prefix
- Standard base64 alphabet
- Image renders correctly in Postman
Environment
- ModelContextProtocol: 0.9.0-preview.1
- .NET: (e.g. .NET 10)
- OS: (Windows)
Additional Context
This appears to be related to the 0.9 change where ImageContentBlock.Data is now ReadOnlyMemory<byte>. It may be caused by stricter base64 handling during JSON deserialization or a double-decode scenario.
Title
0.9.0-preview.1:
ImageContentBlockthrows "invalid base64" when consumingCallToolResult(works in 0.8.0-preview.1)Description
After upgrading from ModelContextProtocol 0.8.0-preview.1 to 0.9.0-preview.1, consuming an MCP server
CallToolResultthat includes anImageContentBlocknow throws an "invalid base64" exception.The exact same MCP server response works correctly in:
This appears to be a regression introduced in 0.9.0-preview.1, possibly related to the change of
ImageContentBlock.DatafromstringtoReadOnlyMemory<byte>and how JSON deserialization handles base64 content.Expected Behavior
CallToolResultcontaining anImageContentBlockshould deserialize successfully and allow access to the image data (viaDecodedDataorData) without throwing.This worked correctly in 0.8.0-preview.1.
Actual Behavior
When consuming the tool result:
ImageContentBlockcauses an "invalid base64" exception.DecodedDatatriggers the exception.Repro Steps
ImageContentBlockCallToolResultDecodedData)Result:
FormatException/ invalid base64 errorReverting to 0.8.0-preview.1 resolves the issue immediately.
Sample Tool Result Payload (Redacted)
{ "content": [ { "type": "image", "mimeType": "image/png", "data": "<valid base64 string>" } ] }Notes:
data:image/...prefixEnvironment
Additional Context
This appears to be related to the 0.9 change where
ImageContentBlock.Datais nowReadOnlyMemory<byte>. It may be caused by stricter base64 handling during JSON deserialization or a double-decode scenario.