From 6357227f7f47d9725d29eeefc81d28b878b4adac Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Mon, 1 Jun 2026 03:48:30 -0400 Subject: [PATCH] Keep image content theme parse-only --- lib/src/types/content.dart | 5 ++++- test/types_test.dart | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/src/types/content.dart b/lib/src/types/content.dart index 42c612b5..cb22fbf1 100644 --- a/lib/src/types/content.dart +++ b/lib/src/types/content.dart @@ -267,7 +267,6 @@ sealed class Content { final ImageContent c => { 'data': c.data, 'mimeType': c.mimeType, - if (c.theme != null) 'theme': c.theme, if (c.annotations != null) 'annotations': c.annotations!.toJson(), if (c.meta != null) '_meta': readJsonObject(c.meta, 'ImageContent._meta'), @@ -346,6 +345,10 @@ class ImageContent extends Content { final String mimeType; /// Optional theme hint for legacy icon usage (`light` | `dark`). + /// + /// This field is parsed for backwards compatibility with older icon-shaped + /// payloads. MCP ImageContent content blocks do not serialize `theme`; use + /// [McpIcon.theme] for advertised icons. final String? theme; /// Optional annotations for the content block. diff --git a/test/types_test.dart b/test/types_test.dart index 250258ee..23679064 100644 --- a/test/types_test.dart +++ b/test/types_test.dart @@ -494,7 +494,7 @@ void main() { expect(deserialized.mimeType, equals('image/png')); }); - test('ImageContent supports optional theme', () { + test('ImageContent parses legacy theme without serializing it', () { final content = const ImageContent( data: 'base64data', mimeType: 'image/png', @@ -502,9 +502,12 @@ void main() { ); final json = content.toJson(); - expect(json['theme'], equals('dark')); + expect(json, isNot(contains('theme'))); - final deserialized = ImageContent.fromJson(json); + final deserialized = ImageContent.fromJson({ + ...json, + 'theme': 'dark', + }); expect(deserialized.theme, equals('dark')); });