Skip to content

Commit 76dee33

Browse files
committed
feat: add SEP-2322 MRTR model types
1 parent 4fd4986 commit 76dee33

12 files changed

Lines changed: 739 additions & 2 deletions

crates/rmcp/src/handler/client.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ impl<H: ClientHandler> Service<RoleClient> for H {
6464
ServerNotification::PromptListChangedNotification(_notification_no_param) => {
6565
self.on_prompt_list_changed(context).await
6666
}
67-
ServerNotification::ElicitationCompletionNotification(notification) => {
67+
ServerNotification::ElicitationCompletionNotification(notification) =>
68+
{
69+
#[allow(deprecated)]
6870
self.on_url_elicitation_notification_complete(notification.params, context)
6971
.await
7072
}
@@ -238,6 +240,10 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
238240
std::future::ready(())
239241
}
240242

243+
#[deprecated(
244+
since = "1.8.0",
245+
note = "URL elicitation is removed by SEP-2322 (Multi Round-Trip Requests). Use InputRequiredResult-based MRTR flow instead."
246+
)]
241247
fn on_url_elicitation_notification_complete(
242248
&self,
243249
params: ElicitationResponseNotificationParam,

crates/rmcp/src/handler/server/router/tool.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,8 @@ mod tests {
667667
name: Cow::Borrowed("requires_params"),
668668
arguments: Some(Default::default()),
669669
task: None,
670+
input_responses: None,
671+
request_state: None,
670672
},
671673
RequestContext::new(NumberOrString::Number(1), peer),
672674
);
@@ -706,6 +708,8 @@ mod tests {
706708
name: Cow::Borrowed("test_tool"),
707709
arguments: None,
708710
task: None,
711+
input_responses: None,
712+
request_state: None,
709713
},
710714
RequestContext::new(NumberOrString::Number(1), peer),
711715
);

crates/rmcp/src/handler/server/tool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl<'s, S> ToolCallContext<'s, S> {
4646
name,
4747
arguments,
4848
task,
49+
..
4950
}: CallToolRequestParams,
5051
request_context: RequestContext<RoleServer>,
5152
) -> Self {

crates/rmcp/src/model.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod content;
55
mod elicitation_schema;
66
mod extension;
77
mod meta;
8+
mod mrtr;
89
mod prompt;
910
mod resource;
1011
mod serde_impl;
@@ -16,6 +17,7 @@ pub use content::*;
1617
pub use elicitation_schema::*;
1718
pub use extension::*;
1819
pub use meta::*;
20+
pub use mrtr::*;
1921
pub use prompt::*;
2022
pub use resource::*;
2123
use serde::{Deserialize, Serialize, de::DeserializeOwned};
@@ -509,6 +511,10 @@ impl ErrorCode {
509511
pub const INVALID_PARAMS: Self = Self(-32602);
510512
pub const INTERNAL_ERROR: Self = Self(-32603);
511513
pub const PARSE_ERROR: Self = Self(-32700);
514+
#[deprecated(
515+
since = "1.8.0",
516+
note = "URLElicitationRequiredError is removed by SEP-2322 (Multi Round-Trip Requests). Use InputRequiredResult instead."
517+
)]
512518
pub const URL_ELICITATION_REQUIRED: Self = Self(-32042);
513519
}
514520

@@ -565,6 +571,11 @@ impl ErrorData {
565571
pub fn internal_error(message: impl Into<Cow<'static, str>>, data: Option<Value>) -> Self {
566572
Self::new(ErrorCode::INTERNAL_ERROR, message, data)
567573
}
574+
#[deprecated(
575+
since = "1.8.0",
576+
note = "URLElicitationRequiredError is removed by SEP-2322 (Multi Round-Trip Requests). Use InputRequiredResult instead."
577+
)]
578+
#[allow(deprecated)]
568579
pub fn url_elicitation_required(
569580
message: impl Into<Cow<'static, str>>,
570581
data: Option<Value>,
@@ -1212,6 +1223,13 @@ pub struct ReadResourceRequestParams {
12121223
pub meta: Option<Meta>,
12131224
/// The URI of the resource to read
12141225
pub uri: String,
1226+
/// Client responses to server-initiated input requests from a previous
1227+
/// `InputRequiredResult` (SEP-2322 Multi Round-Trip Requests).
1228+
#[serde(skip_serializing_if = "Option::is_none")]
1229+
pub input_responses: Option<InputResponses>,
1230+
/// Opaque request state echoed back from a previous `InputRequiredResult` (SEP-2322).
1231+
#[serde(skip_serializing_if = "Option::is_none")]
1232+
pub request_state: Option<String>,
12151233
}
12161234

12171235
impl ReadResourceRequestParams {
@@ -1220,6 +1238,8 @@ impl ReadResourceRequestParams {
12201238
Self {
12211239
meta: None,
12221240
uri: uri.into(),
1241+
input_responses: None,
1242+
request_state: None,
12231243
}
12241244
}
12251245

@@ -1228,6 +1248,18 @@ impl ReadResourceRequestParams {
12281248
self.meta = Some(meta);
12291249
self
12301250
}
1251+
1252+
/// Sets the input responses for an MRTR retry (SEP-2322).
1253+
pub fn with_input_responses(mut self, input_responses: InputResponses) -> Self {
1254+
self.input_responses = Some(input_responses);
1255+
self
1256+
}
1257+
1258+
/// Sets the request state for an MRTR retry (SEP-2322).
1259+
pub fn with_request_state(mut self, request_state: impl Into<String>) -> Self {
1260+
self.request_state = Some(request_state.into());
1261+
self
1262+
}
12311263
}
12321264

12331265
impl RequestParamsMeta for ReadResourceRequestParams {
@@ -1395,6 +1427,13 @@ pub struct GetPromptRequestParams {
13951427
pub name: String,
13961428
#[serde(skip_serializing_if = "Option::is_none")]
13971429
pub arguments: Option<JsonObject>,
1430+
/// Client responses to server-initiated input requests from a previous
1431+
/// `InputRequiredResult` (SEP-2322 Multi Round-Trip Requests).
1432+
#[serde(skip_serializing_if = "Option::is_none")]
1433+
pub input_responses: Option<InputResponses>,
1434+
/// Opaque request state echoed back from a previous `InputRequiredResult` (SEP-2322).
1435+
#[serde(skip_serializing_if = "Option::is_none")]
1436+
pub request_state: Option<String>,
13981437
}
13991438

14001439
impl GetPromptRequestParams {
@@ -1404,6 +1443,8 @@ impl GetPromptRequestParams {
14041443
meta: None,
14051444
name: name.into(),
14061445
arguments: None,
1446+
input_responses: None,
1447+
request_state: None,
14071448
}
14081449
}
14091450

@@ -1418,6 +1459,18 @@ impl GetPromptRequestParams {
14181459
self.meta = Some(meta);
14191460
self
14201461
}
1462+
1463+
/// Sets the input responses for an MRTR retry (SEP-2322).
1464+
pub fn with_input_responses(mut self, input_responses: InputResponses) -> Self {
1465+
self.input_responses = Some(input_responses);
1466+
self
1467+
}
1468+
1469+
/// Sets the request state for an MRTR retry (SEP-2322).
1470+
pub fn with_request_state(mut self, request_state: impl Into<String>) -> Self {
1471+
self.request_state = Some(request_state.into());
1472+
self
1473+
}
14211474
}
14221475

14231476
impl RequestParamsMeta for GetPromptRequestParams {
@@ -3019,6 +3072,17 @@ pub struct CallToolRequestParams {
30193072
/// Task metadata for async task management (SEP-1319)
30203073
#[serde(skip_serializing_if = "Option::is_none")]
30213074
pub task: Option<JsonObject>,
3075+
/// Client responses to server-initiated input requests from a previous
3076+
/// `InputRequiredResult`. Present only when retrying after an incomplete result.
3077+
/// (SEP-2322 Multi Round-Trip Requests)
3078+
#[serde(skip_serializing_if = "Option::is_none")]
3079+
pub input_responses: Option<InputResponses>,
3080+
/// Opaque request state echoed back from a previous `InputRequiredResult`.
3081+
/// Clients MUST return this value exactly as received. Present only when
3082+
/// retrying a request after receiving an incomplete result that included
3083+
/// a `requestState` field. (SEP-2322)
3084+
#[serde(skip_serializing_if = "Option::is_none")]
3085+
pub request_state: Option<String>,
30223086
}
30233087

30243088
impl CallToolRequestParams {
@@ -3029,6 +3093,8 @@ impl CallToolRequestParams {
30293093
name: name.into(),
30303094
arguments: None,
30313095
task: None,
3096+
input_responses: None,
3097+
request_state: None,
30323098
}
30333099
}
30343100

@@ -3043,6 +3109,18 @@ impl CallToolRequestParams {
30433109
self.task = Some(task);
30443110
self
30453111
}
3112+
3113+
/// Sets the input responses for an MRTR retry (SEP-2322).
3114+
pub fn with_input_responses(mut self, input_responses: InputResponses) -> Self {
3115+
self.input_responses = Some(input_responses);
3116+
self
3117+
}
3118+
3119+
/// Sets the request state for an MRTR retry (SEP-2322).
3120+
pub fn with_request_state(mut self, request_state: impl Into<String>) -> Self {
3121+
self.request_state = Some(request_state.into());
3122+
self
3123+
}
30463124
}
30473125

30483126
impl RequestParamsMeta for CallToolRequestParams {
@@ -3431,6 +3509,7 @@ ts_union!(
34313509
| GetTaskResult
34323510
| CancelTaskResult
34333511
| CallToolResult
3512+
| InputRequiredResult
34343513
| GetTaskPayloadResult
34353514
| EmptyResult
34363515
| CustomResult

0 commit comments

Comments
 (0)