Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/src/types/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions test/types_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -494,17 +494,20 @@ 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',
theme: 'dark',
);

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'));
});

Expand Down