Skip to content

Commit ad446aa

Browse files
committed
fix: add a few more with_ mutator methods
1 parent 6f5969b commit ad446aa

2 files changed

Lines changed: 169 additions & 0 deletions

File tree

crates/rmcp/src/model.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,11 @@ impl InitializeRequestParams {
793793
client_info,
794794
}
795795
}
796+
797+
pub fn with_protocol_version(mut self, protocol_version: ProtocolVersion) -> Self {
798+
self.protocol_version = protocol_version;
799+
self
800+
}
796801
}
797802

798803
impl RequestParamsMeta for InitializeRequestParams {
@@ -978,6 +983,30 @@ impl Implementation {
978983
website_url: None,
979984
}
980985
}
986+
987+
/// Set the human-readable title.
988+
pub fn with_title(mut self, title: impl Into<String>) -> Self {
989+
self.title = Some(title.into());
990+
self
991+
}
992+
993+
/// Set the description.
994+
pub fn with_description(mut self, description: impl Into<String>) -> Self {
995+
self.description = Some(description.into());
996+
self
997+
}
998+
999+
/// Set the icons.
1000+
pub fn with_icons(mut self, icons: Vec<Icon>) -> Self {
1001+
self.icons = Some(icons);
1002+
self
1003+
}
1004+
1005+
/// Set the website URL.
1006+
pub fn with_website_url(mut self, website_url: impl Into<String>) -> Self {
1007+
self.website_url = Some(website_url.into());
1008+
self
1009+
}
9811010
}
9821011

9831012
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
@@ -992,6 +1021,13 @@ pub struct PaginatedRequestParams {
9921021
pub cursor: Option<String>,
9931022
}
9941023

1024+
impl PaginatedRequestParams {
1025+
pub fn with_cursor(mut self, cursor: Option<String>) -> Self {
1026+
self.cursor = cursor;
1027+
self
1028+
}
1029+
}
1030+
9951031
impl RequestParamsMeta for PaginatedRequestParams {
9961032
fn meta(&self) -> Option<&Meta> {
9971033
self.meta.as_ref()
@@ -1037,6 +1073,18 @@ impl ProgressNotificationParam {
10371073
message: None,
10381074
}
10391075
}
1076+
1077+
/// Set the total number of items to process.
1078+
pub fn with_total(mut self, total: f64) -> Self {
1079+
self.total = Some(total);
1080+
self
1081+
}
1082+
1083+
/// Set a message describing the current progress.
1084+
pub fn with_message(mut self, message: impl Into<String>) -> Self {
1085+
self.message = Some(message.into());
1086+
self
1087+
}
10401088
}
10411089

10421090
pub type ProgressNotification = Notification<ProgressNotificationMethod, ProgressNotificationParam>;
@@ -1116,6 +1164,12 @@ impl ReadResourceRequestParams {
11161164
uri: uri.into(),
11171165
}
11181166
}
1167+
1168+
/// Set the metadata for this request.
1169+
pub fn with_meta(mut self, meta: Meta) -> Self {
1170+
self.meta = Some(meta);
1171+
self
1172+
}
11191173
}
11201174

11211175
impl RequestParamsMeta for ReadResourceRequestParams {
@@ -1289,6 +1343,12 @@ impl GetPromptRequestParams {
12891343
self.arguments = Some(arguments);
12901344
self
12911345
}
1346+
1347+
/// Set the metadata for this request.
1348+
pub fn with_meta(mut self, meta: Meta) -> Self {
1349+
self.meta = Some(meta);
1350+
self
1351+
}
12921352
}
12931353

12941354
impl RequestParamsMeta for GetPromptRequestParams {
@@ -2835,6 +2895,12 @@ impl CreateMessageResult {
28352895
self
28362896
}
28372897

2898+
/// Set the model identifier.
2899+
pub fn with_model(mut self, model: impl Into<String>) -> Self {
2900+
self.model = model.into();
2901+
self
2902+
}
2903+
28382904
/// Validate the result per SEP-1577: role must be "assistant".
28392905
pub fn validate(&self) -> Result<(), String> {
28402906
if self.message.role != Role::Assistant {

crates/rmcp/src/model/resource.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub enum ResourceContents {
8080
}
8181

8282
impl ResourceContents {
83+
/// Create text resource contents.
8384
pub fn text(text: impl Into<String>, uri: impl Into<String>) -> Self {
8485
Self::TextResourceContents {
8586
uri: uri.into(),
@@ -88,6 +89,34 @@ impl ResourceContents {
8889
meta: None,
8990
}
9091
}
92+
93+
/// Create blob resource contents.
94+
pub fn blob(blob: impl Into<String>, uri: impl Into<String>) -> Self {
95+
Self::BlobResourceContents {
96+
uri: uri.into(),
97+
mime_type: None,
98+
blob: blob.into(),
99+
meta: None,
100+
}
101+
}
102+
103+
/// Set the MIME type on this resource contents.
104+
pub fn with_mime_type(mut self, mime_type: impl Into<String>) -> Self {
105+
match &mut self {
106+
Self::TextResourceContents { mime_type: mt, .. } => *mt = Some(mime_type.into()),
107+
Self::BlobResourceContents { mime_type: mt, .. } => *mt = Some(mime_type.into()),
108+
}
109+
self
110+
}
111+
112+
/// Set the metadata on this resource contents.
113+
pub fn with_meta(mut self, meta: Meta) -> Self {
114+
match &mut self {
115+
Self::TextResourceContents { meta: m, .. } => *m = Some(meta),
116+
Self::BlobResourceContents { meta: m, .. } => *m = Some(meta),
117+
}
118+
self
119+
}
91120
}
92121

93122
impl RawResource {
@@ -104,6 +133,80 @@ impl RawResource {
104133
meta: None,
105134
}
106135
}
136+
137+
/// Set the human-readable title.
138+
pub fn with_title(mut self, title: impl Into<String>) -> Self {
139+
self.title = Some(title.into());
140+
self
141+
}
142+
143+
/// Set the description.
144+
pub fn with_description(mut self, description: impl Into<String>) -> Self {
145+
self.description = Some(description.into());
146+
self
147+
}
148+
149+
/// Set the MIME type.
150+
pub fn with_mime_type(mut self, mime_type: impl Into<String>) -> Self {
151+
self.mime_type = Some(mime_type.into());
152+
self
153+
}
154+
155+
/// Set the size in bytes.
156+
pub fn with_size(mut self, size: u32) -> Self {
157+
self.size = Some(size);
158+
self
159+
}
160+
161+
/// Set the icons.
162+
pub fn with_icons(mut self, icons: Vec<Icon>) -> Self {
163+
self.icons = Some(icons);
164+
self
165+
}
166+
167+
/// Set the metadata.
168+
pub fn with_meta(mut self, meta: Meta) -> Self {
169+
self.meta = Some(meta);
170+
self
171+
}
172+
}
173+
174+
impl RawResourceTemplate {
175+
/// Creates a new RawResourceTemplate with a URI template and name.
176+
pub fn new(uri_template: impl Into<String>, name: impl Into<String>) -> Self {
177+
Self {
178+
uri_template: uri_template.into(),
179+
name: name.into(),
180+
title: None,
181+
description: None,
182+
mime_type: None,
183+
icons: None,
184+
}
185+
}
186+
187+
/// Set the human-readable title.
188+
pub fn with_title(mut self, title: impl Into<String>) -> Self {
189+
self.title = Some(title.into());
190+
self
191+
}
192+
193+
/// Set the description.
194+
pub fn with_description(mut self, description: impl Into<String>) -> Self {
195+
self.description = Some(description.into());
196+
self
197+
}
198+
199+
/// Set the MIME type.
200+
pub fn with_mime_type(mut self, mime_type: impl Into<String>) -> Self {
201+
self.mime_type = Some(mime_type.into());
202+
self
203+
}
204+
205+
/// Set the icons.
206+
pub fn with_icons(mut self, icons: Vec<Icon>) -> Self {
207+
self.icons = Some(icons);
208+
self
209+
}
107210
}
108211

109212
#[cfg(test)]

0 commit comments

Comments
 (0)