Skip to content

Commit 411d5a0

Browse files
authored
mcp: switch icon theme to named string type (#733)
To be consistent with logging level, use a named string type for icon themes. This improves readability / discoverability, and is more consistent. Updates #552 For #725
1 parent 76e6854 commit 411d5a0

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

examples/server/everything/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,6 @@ func mcpIcons() []mcp.Icon {
291291
Source: "data:image/png;base64," + base64.StdEncoding.EncodeToString(mcpIconData),
292292
MIMEType: "image/png",
293293
Sizes: []string{"48x48"},
294-
Theme: "light", // or "dark" or empty
294+
Theme: mcp.IconThemeLight,
295295
}}
296296
}

mcp/conformance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ var iconObj = Icon{
152152
Source: "foobar",
153153
MIMEType: "image/png",
154154
Sizes: []string{"48x48", "96x96"},
155-
Theme: "light",
155+
Theme: IconThemeLight,
156156
}
157157

158158
// runServerTest runs the server conformance test.

mcp/content_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestContent(t *testing.T) {
121121
Description: "This resource demonstrates all fields",
122122
MIMEType: "text/plain",
123123
Meta: mcp.Meta{"custom": "metadata"},
124-
Icons: []mcp.Icon{{Source: "foobar", MIMEType: "image/png", Sizes: []string{"48x48"}, Theme: "light"}},
124+
Icons: []mcp.Icon{{Source: "foobar", MIMEType: "image/png", Sizes: []string{"48x48"}, Theme: mcp.IconThemeLight}},
125125
},
126126
`{"type":"resource_link","mimeType":"text/plain","uri":"https://example.com/resource","name":"Example Resource","title":"A comprehensive example resource","description":"This resource demonstrates all fields","_meta":{"custom":"metadata"},"icons":[{"src":"foobar","mimeType":"image/png","sizes":["48x48"],"theme":"light"}]}`,
127127
},
@@ -217,7 +217,7 @@ func TestContentUnmarshal(t *testing.T) {
217217
// Meta: mcp.Meta{"custom": "metadata"},
218218
Size: &valInt64,
219219
Annotations: &mcp.Annotations{Audience: []mcp.Role{"user", "assistant"}, LastModified: "2025-01-12T15:00:58Z", Priority: 0.5},
220-
Icons: []mcp.Icon{{Source: "foobar", MIMEType: "image/png", Sizes: []string{"48x48"}, Theme: "light"}},
220+
Icons: []mcp.Icon{{Source: "foobar", MIMEType: "image/png", Sizes: []string{"48x48"}, Theme: mcp.IconThemeLight}},
221221
},
222222
},
223223
}

mcp/protocol.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,16 @@ type ProgressNotificationParams struct {
750750

751751
func (*ProgressNotificationParams) isParams() {}
752752

753+
// IconTheme specifies the theme an icon is designed for.
754+
type IconTheme string
755+
756+
const (
757+
// IconThemeLight indicates the icon is designed for a light background.
758+
IconThemeLight IconTheme = "light"
759+
// IconThemeDark indicates the icon is designed for a dark background.
760+
IconThemeDark IconTheme = "dark"
761+
)
762+
753763
// Icon provides visual identifiers for their resources, tools, prompts, and implementations
754764
// See [/specification/draft/basic/index#icons] for notes on icons
755765
//
@@ -763,8 +773,9 @@ type Icon struct {
763773
MIMEType string `json:"mimeType,omitempty"`
764774
// Optional size specification (e.g., ["48x48"], ["any"] for scalable formats like SVG, or ["48x48", "96x96"] for multiple sizes)
765775
Sizes []string `json:"sizes,omitempty"`
766-
// Optional Theme of the icon, e.g., "light" or "dark"
767-
Theme string `json:"theme,omitempty"`
776+
// Optional theme specifier. "light" indicates the icon is designed for a light
777+
// background, "dark" indicates the icon is designed for a dark background.
778+
Theme IconTheme `json:"theme,omitempty"`
768779
}
769780

770781
// A prompt or prompt template that the server offers.

0 commit comments

Comments
 (0)