feat(SEP-973): following change Icon.sizes from string to string array (#479)

Ref:
https://github.com/modelcontextprotocol/modelcontextprotocol/pull/1531
This commit is contained in:
Honsun Zhu 2025-10-10 19:23:04 +08:00 • committed by GitHub
commit b749e3c9b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 35 additions and 20 deletions

View file

@ -713,9 +713,9 @@ pub struct Icon {
/// Optional override if the server's MIME type is missing or generic /// Optional override if the server's MIME type is missing or generic
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>, pub mime_type: Option<String>,
/// Size specification (e.g., "48x48", "any" for SVG, or "48x48 96x96") /// 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")] #[serde(skip_serializing_if = "Option::is_none")]
pub sizes: Option<String>, pub sizes: Option<Vec<String>>,
} }
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
@ -2060,13 +2060,13 @@ mod tests {
let icon = Icon { let icon = Icon {
src: "https://example.com/icon.png".to_string(), src: "https://example.com/icon.png".to_string(),
mime_type: Some("image/png".to_string()), mime_type: Some("image/png".to_string()),
sizes: Some("48x48".to_string()), sizes: Some(vec!["48x48".to_string()]),
}; };
let json = serde_json::to_value(&icon).unwrap(); let json = serde_json::to_value(&icon).unwrap();
assert_eq!(json["src"], "https://example.com/icon.png"); assert_eq!(json["src"], "https://example.com/icon.png");
assert_eq!(json["mimeType"], "image/png"); assert_eq!(json["mimeType"], "image/png");
assert_eq!(json["sizes"], "48x48"); assert_eq!(json["sizes"][0], "48x48");
// Test deserialization // Test deserialization
let deserialized: Icon = serde_json::from_value(json).unwrap(); let deserialized: Icon = serde_json::from_value(json).unwrap();
@ -2097,12 +2097,12 @@ mod tests {
Icon { Icon {
src: "https://example.com/icon.png".to_string(), src: "https://example.com/icon.png".to_string(),
mime_type: Some("image/png".to_string()), mime_type: Some("image/png".to_string()),
sizes: Some("48x48".to_string()), sizes: Some(vec!["48x48".to_string()]),
}, },
Icon { Icon {
src: "https://example.com/icon.svg".to_string(), src: "https://example.com/icon.svg".to_string(),
mime_type: Some("image/svg+xml".to_string()), mime_type: Some("image/svg+xml".to_string()),
sizes: Some("any".to_string()), sizes: Some(vec!["any".to_string()]),
}, },
]), ]),
website_url: Some("https://example.com".to_string()), website_url: Some("https://example.com".to_string()),
@ -2113,7 +2113,9 @@ mod tests {
assert_eq!(json["websiteUrl"], "https://example.com"); assert_eq!(json["websiteUrl"], "https://example.com");
assert!(json["icons"].is_array()); assert!(json["icons"].is_array());
assert_eq!(json["icons"][0]["src"], "https://example.com/icon.png"); assert_eq!(json["icons"][0]["src"], "https://example.com/icon.png");
assert_eq!(json["icons"][0]["sizes"][0], "48x48");
assert_eq!(json["icons"][1]["mimeType"], "image/svg+xml"); assert_eq!(json["icons"][1]["mimeType"], "image/svg+xml");
assert_eq!(json["icons"][1]["sizes"][0], "any");
} }
#[test] #[test]
@ -2143,7 +2145,7 @@ mod tests {
icons: Some(vec![Icon { icons: Some(vec![Icon {
src: "https://example.com/server.png".to_string(), src: "https://example.com/server.png".to_string(),
mime_type: Some("image/png".to_string()), mime_type: Some("image/png".to_string()),
sizes: None, sizes: Some(vec!["48x48".to_string()]),
}]), }]),
website_url: Some("https://docs.example.com".to_string()), website_url: Some("https://docs.example.com".to_string()),
}, },
@ -2156,6 +2158,7 @@ mod tests {
json["serverInfo"]["icons"][0]["src"], json["serverInfo"]["icons"][0]["src"],
"https://example.com/server.png" "https://example.com/server.png"
); );
assert_eq!(json["serverInfo"]["icons"][0]["sizes"][0], "48x48");
assert_eq!(json["serverInfo"]["websiteUrl"], "https://docs.example.com"); assert_eq!(json["serverInfo"]["websiteUrl"], "https://docs.example.com");
} }
} }

View file

@ -499,11 +499,14 @@
] ]
}, },
"sizes": { "sizes": {
"description": "Size specification (e.g., \"48x48\", \"any\" for SVG, or \"48x48 96x96\")", "description": "Size specification, each string should be in WxH format (e.g., `\\\"48x48\\\"`, `\\\"96x96\\\"`) or `\\\"any\\\"` for scalable formats like SVG",
"type": [ "type": [
"string", "array",
"null" "null"
] ],
"items": {
"type": "string"
}
}, },
"src": { "src": {
"description": "A standard URI pointing to an icon resource", "description": "A standard URI pointing to an icon resource",

View file

@ -499,11 +499,14 @@
] ]
}, },
"sizes": { "sizes": {
"description": "Size specification (e.g., \"48x48\", \"any\" for SVG, or \"48x48 96x96\")", "description": "Size specification, each string should be in WxH format (e.g., `\\\"48x48\\\"`, `\\\"96x96\\\"`) or `\\\"any\\\"` for scalable formats like SVG",
"type": [ "type": [
"string", "array",
"null" "null"
] ],
"items": {
"type": "string"
}
}, },
"src": { "src": {
"description": "A standard URI pointing to an icon resource", "description": "A standard URI pointing to an icon resource",

View file

@ -630,11 +630,14 @@
] ]
}, },
"sizes": { "sizes": {
"description": "Size specification (e.g., \"48x48\", \"any\" for SVG, or \"48x48 96x96\")", "description": "Size specification, each string should be in WxH format (e.g., `\\\"48x48\\\"`, `\\\"96x96\\\"`) or `\\\"any\\\"` for scalable formats like SVG",
"type": [ "type": [
"string", "array",
"null" "null"
] ],
"items": {
"type": "string"
}
}, },
"src": { "src": {
"description": "A standard URI pointing to an icon resource", "description": "A standard URI pointing to an icon resource",

View file

@ -630,11 +630,14 @@
] ]
}, },
"sizes": { "sizes": {
"description": "Size specification (e.g., \"48x48\", \"any\" for SVG, or \"48x48 96x96\")", "description": "Size specification, each string should be in WxH format (e.g., `\\\"48x48\\\"`, `\\\"96x96\\\"`) or `\\\"any\\\"` for scalable formats like SVG",
"type": [ "type": [
"string", "array",
"null" "null"
] ],
"items": {
"type": "string"
}
}, },
"src": { "src": {
"description": "A standard URI pointing to an icon resource", "description": "A standard URI pointing to an icon resource",

View file

@ -19,5 +19,5 @@ rmcp = { workspace = true, features = [
"transport-child-process", "transport-child-process",
"transport-sse-client-reqwest", "transport-sse-client-reqwest",
"transport-streamable-http-client-reqwest" "transport-streamable-http-client-reqwest"
], no-default-features = true } ] }
clap = { version = "4.0", features = ["derive"] } clap = { version = "4.0", features = ["derive"] }