Skip to content
Merged
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
39 changes: 39 additions & 0 deletions crates/rmcp/src/model/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ pub struct RawResourceTemplate {
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>,
/// Optional list of icons for the resource template
#[serde(skip_serializing_if = "Option::is_none")]
pub icons: Option<Vec<Icon>>,
}

pub type ResourceTemplate = Annotated<RawResourceTemplate>;
Expand Down Expand Up @@ -146,4 +149,40 @@ mod tests {
assert!(json.contains("mimeType"));
assert!(!json.contains("mime_type"));
}

#[test]
fn test_resource_template_with_icons() {
let resource_template = RawResourceTemplate {
uri_template: "file:///{path}".to_string(),
name: "template".to_string(),
title: Some("Test Template".to_string()),
description: Some("A test resource template".to_string()),
mime_type: Some("text/plain".to_string()),
icons: Some(vec![Icon {
src: "https://example.com/icon.png".to_string(),
mime_type: Some("image/png".to_string()),
sizes: Some(vec!["48x48".to_string()]),
}]),
};

let json = serde_json::to_value(&resource_template).unwrap();
assert!(json["icons"].is_array());
assert_eq!(json["icons"][0]["src"], "https://example.com/icon.png");
assert_eq!(json["icons"][0]["sizes"][0], "48x48");
}

#[test]
fn test_resource_template_without_icons() {
let resource_template = RawResourceTemplate {
uri_template: "file:///{path}".to_string(),
name: "template".to_string(),
title: None,
description: None,
mime_type: None,
icons: None,
};

let json = serde_json::to_value(&resource_template).unwrap();
assert!(json.get("icons").is_none());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@
"null"
]
},
"icons": {
"description": "Optional list of icons for the resource template",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/Icon"
}
},
"mimeType": {
"type": [
"string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@
"null"
]
},
"icons": {
"description": "Optional list of icons for the resource template",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/Icon"
}
},
"mimeType": {
"type": [
"string",
Expand Down