-
Notifications
You must be signed in to change notification settings - Fork 486
feat: add "theme" to Icon #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
glicht
wants to merge
1
commit into
modelcontextprotocol:main
Choose a base branch
from
binahm:feat/icon-theme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+108
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -889,6 +889,15 @@ impl Default for ClientInfo { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /// Icon themes supported by the MCP specification | ||||||||
| #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Copy)] | ||||||||
| #[serde(rename_all = "lowercase")] //match spec | ||||||||
| #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] | ||||||||
| pub enum IconTheme { | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The MCP spec could add more themes in the future (e.g.,
Suggested change
|
||||||||
| Light, | ||||||||
| Dark, | ||||||||
| } | ||||||||
|
|
||||||||
| /// A URL pointing to an icon resource or a base64-encoded data URI. | ||||||||
| /// | ||||||||
| /// Clients that support rendering icons MUST support at least the following MIME types: | ||||||||
|
|
@@ -911,6 +920,9 @@ pub struct Icon { | |||||||
| /// Size specification, each string should be in WxH format (e.g., `\"48x48\"`, `\"96x96\"`) or `\"any\"` for scalable formats like SVG | ||||||||
| #[serde(skip_serializing_if = "Option::is_none")] | ||||||||
| pub sizes: Option<Vec<String>>, | ||||||||
| /// Optional specifier for the theme this icon is designed for | ||||||||
| #[serde(skip_serializing_if = "Option::is_none")] | ||||||||
| pub theme: Option<IconTheme>, | ||||||||
| } | ||||||||
|
|
||||||||
| impl Icon { | ||||||||
|
|
@@ -920,6 +932,7 @@ impl Icon { | |||||||
| src: src.into(), | ||||||||
| mime_type: None, | ||||||||
| sizes: None, | ||||||||
| theme: None, | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -934,6 +947,12 @@ impl Icon { | |||||||
| self.sizes = Some(sizes); | ||||||||
| self | ||||||||
| } | ||||||||
|
|
||||||||
| /// Set the theme. | ||||||||
| pub fn with_theme(mut self, theme: IconTheme) -> Self { | ||||||||
| self.theme = Some(theme); | ||||||||
| self | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] | ||||||||
|
|
@@ -3642,12 +3661,14 @@ mod tests { | |||||||
| src: "https://example.com/icon.png".to_string(), | ||||||||
| mime_type: Some("image/png".to_string()), | ||||||||
| sizes: Some(vec!["48x48".to_string()]), | ||||||||
| theme: Some(IconTheme::Light), | ||||||||
| }; | ||||||||
|
|
||||||||
| let json = serde_json::to_value(&icon).unwrap(); | ||||||||
| assert_eq!(json["src"], "https://example.com/icon.png"); | ||||||||
| assert_eq!(json["mimeType"], "image/png"); | ||||||||
| assert_eq!(json["sizes"][0], "48x48"); | ||||||||
| assert_eq!(json["theme"], "light"); | ||||||||
|
|
||||||||
| // Test deserialization | ||||||||
| let deserialized: Icon = serde_json::from_value(json).unwrap(); | ||||||||
|
|
@@ -3660,12 +3681,14 @@ mod tests { | |||||||
| src: "data:image/svg+xml;base64,PHN2Zy8+".to_string(), | ||||||||
| mime_type: None, | ||||||||
| sizes: None, | ||||||||
| theme: None, | ||||||||
| }; | ||||||||
|
|
||||||||
| let json = serde_json::to_value(&icon).unwrap(); | ||||||||
| assert_eq!(json["src"], "data:image/svg+xml;base64,PHN2Zy8+"); | ||||||||
| assert!(json.get("mimeType").is_none()); | ||||||||
| assert!(json.get("sizes").is_none()); | ||||||||
| assert!(json.get("theme").is_none()); | ||||||||
| } | ||||||||
|
|
||||||||
| #[test] | ||||||||
|
|
@@ -3680,11 +3703,13 @@ mod tests { | |||||||
| src: "https://example.com/icon.png".to_string(), | ||||||||
| mime_type: Some("image/png".to_string()), | ||||||||
| sizes: Some(vec!["48x48".to_string()]), | ||||||||
| theme: Some(IconTheme::Dark), | ||||||||
| }, | ||||||||
| Icon { | ||||||||
| src: "https://example.com/icon.svg".to_string(), | ||||||||
| mime_type: Some("image/svg+xml".to_string()), | ||||||||
| sizes: Some(vec!["any".to_string()]), | ||||||||
| theme: Some(IconTheme::Light), | ||||||||
| }, | ||||||||
| ]), | ||||||||
| website_url: Some("https://example.com".to_string()), | ||||||||
|
|
@@ -3699,6 +3724,8 @@ mod tests { | |||||||
| assert_eq!(json["icons"][0]["sizes"][0], "48x48"); | ||||||||
| assert_eq!(json["icons"][1]["mimeType"], "image/svg+xml"); | ||||||||
| assert_eq!(json["icons"][1]["sizes"][0], "any"); | ||||||||
| assert_eq!(json["icons"][0]["theme"], "dark"); | ||||||||
| assert_eq!(json["icons"][1]["theme"], "light"); | ||||||||
| } | ||||||||
|
|
||||||||
| #[test] | ||||||||
|
|
@@ -3731,6 +3758,7 @@ mod tests { | |||||||
| src: "https://example.com/server.png".to_string(), | ||||||||
| mime_type: Some("image/png".to_string()), | ||||||||
| sizes: Some(vec!["48x48".to_string()]), | ||||||||
| theme: Some(IconTheme::Light), | ||||||||
| }]), | ||||||||
| website_url: Some("https://docs.example.com".to_string()), | ||||||||
| }, | ||||||||
|
|
@@ -3744,6 +3772,7 @@ mod tests { | |||||||
| "https://example.com/server.png" | ||||||||
| ); | ||||||||
| assert_eq!(json["serverInfo"]["icons"][0]["sizes"][0], "48x48"); | ||||||||
| assert_eq!(json["serverInfo"]["icons"][0]["theme"], "light"); | ||||||||
| assert_eq!(json["serverInfo"]["websiteUrl"], "https://docs.example.com"); | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding these would let consumers use it as a
HashMapkey or inHashSetwithout friction.