Skip to content

Commit f381c2b

Browse files
authored
fix: remove batched json rpc support (#408)
* fix: remove batched json rpc support * fix(test): fix schema
1 parent 7d46b39 commit f381c2b

File tree

9 files changed

+2
-3497
lines changed

9 files changed

+2
-3497
lines changed

crates/rmcp/src/model.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -490,40 +490,6 @@ impl ErrorData {
490490
}
491491
}
492492

493-
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
494-
#[serde(untagged)]
495-
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
496-
pub enum JsonRpcBatchRequestItem<Req, Not> {
497-
Request(JsonRpcRequest<Req>),
498-
Notification(JsonRpcNotification<Not>),
499-
}
500-
501-
impl<Req, Not> JsonRpcBatchRequestItem<Req, Not> {
502-
pub fn into_non_batch_message<Resp>(self) -> JsonRpcMessage<Req, Resp, Not> {
503-
match self {
504-
JsonRpcBatchRequestItem::Request(r) => JsonRpcMessage::Request(r),
505-
JsonRpcBatchRequestItem::Notification(n) => JsonRpcMessage::Notification(n),
506-
}
507-
}
508-
}
509-
510-
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
511-
#[serde(untagged)]
512-
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
513-
pub enum JsonRpcBatchResponseItem<Resp> {
514-
Response(JsonRpcResponse<Resp>),
515-
Error(JsonRpcError),
516-
}
517-
518-
impl<Resp> JsonRpcBatchResponseItem<Resp> {
519-
pub fn into_non_batch_message<Req, Not>(self) -> JsonRpcMessage<Req, Resp, Not> {
520-
match self {
521-
JsonRpcBatchResponseItem::Response(r) => JsonRpcMessage::Response(r),
522-
JsonRpcBatchResponseItem::Error(e) => JsonRpcMessage::Error(e),
523-
}
524-
}
525-
}
526-
527493
/// Represents any JSON-RPC message that can be sent or received.
528494
///
529495
/// This enum covers all possible message types in the JSON-RPC protocol:
@@ -539,10 +505,6 @@ pub enum JsonRpcMessage<Req = Request, Resp = DefaultResponse, Noti = Notificati
539505
Response(JsonRpcResponse<Resp>),
540506
/// A one-way notification (no response expected)
541507
Notification(JsonRpcNotification<Noti>),
542-
/// Multiple requests sent together
543-
BatchRequest(Vec<JsonRpcBatchRequestItem<Req, Noti>>),
544-
/// Multiple responses sent together
545-
BatchResponse(Vec<JsonRpcBatchResponseItem<Resp>>),
546508
/// An error response
547509
Error(JsonRpcError),
548510
}

crates/rmcp/src/model/meta.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,24 +172,6 @@ where
172172
.extensions_mut()
173173
.insert(value);
174174
}
175-
JsonRpcMessage::BatchRequest(json_rpc_batch_request_items) => {
176-
for item in json_rpc_batch_request_items {
177-
match item {
178-
super::JsonRpcBatchRequestItem::Request(json_rpc_request) => {
179-
json_rpc_request
180-
.request
181-
.extensions_mut()
182-
.insert(value.clone());
183-
}
184-
super::JsonRpcBatchRequestItem::Notification(json_rpc_notification) => {
185-
json_rpc_notification
186-
.notification
187-
.extensions_mut()
188-
.insert(value.clone());
189-
}
190-
}
191-
}
192-
}
193175
_ => {}
194176
}
195177
}

crates/rmcp/src/service.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use crate::{
55
error::ErrorData as McpError,
66
model::{
77
CancelledNotification, CancelledNotificationParam, Extensions, GetExtensions, GetMeta,
8-
JsonRpcBatchRequestItem, JsonRpcBatchResponseItem, JsonRpcError, JsonRpcMessage,
9-
JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, Meta, NumberOrString, ProgressToken,
10-
RequestId, ServerJsonRpcMessage,
8+
JsonRpcError, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, Meta,
9+
NumberOrString, ProgressToken, RequestId, ServerJsonRpcMessage,
1110
},
1211
transport::{DynamicTransportError, IntoTransport, Transport},
1312
};
@@ -835,20 +834,6 @@ where
835834
}
836835
}
837836
}
838-
Event::PeerMessage(JsonRpcMessage::BatchRequest(batch)) => {
839-
batch_messages.extend(
840-
batch
841-
.into_iter()
842-
.map(JsonRpcBatchRequestItem::into_non_batch_message),
843-
);
844-
}
845-
Event::PeerMessage(JsonRpcMessage::BatchResponse(batch)) => {
846-
batch_messages.extend(
847-
batch
848-
.into_iter()
849-
.map(JsonRpcBatchResponseItem::into_non_batch_message),
850-
);
851-
}
852837
}
853838
};
854839
let sink_close_result = transport.close().await;

crates/rmcp/src/transport/streamable_http_server/session/local.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,6 @@ impl LocalSessionWorker {
468468
OutboundChannel::Common
469469
}
470470
}
471-
ServerJsonRpcMessage::BatchRequest(_) | ServerJsonRpcMessage::BatchResponse(_) => {
472-
// the server side should never yield a batch request or response now
473-
unreachable!("server side won't yield batch request or response")
474-
}
475471
}
476472
}
477473
async fn handle_server_message(
@@ -824,20 +820,6 @@ impl Worker for LocalSessionWorker {
824820
crate::model::JsonRpcMessage::Notification(notification) => {
825821
self.catch_cancellation_notification(notification)
826822
}
827-
crate::model::JsonRpcMessage::BatchRequest(items) => {
828-
for r in items {
829-
match r {
830-
crate::model::JsonRpcBatchRequestItem::Request(request) => {
831-
if let Some(http_request_id) = http_request_id {
832-
self.register_request(request, http_request_id)
833-
}
834-
}
835-
crate::model::JsonRpcBatchRequestItem::Notification(
836-
notification,
837-
) => self.catch_cancellation_notification(notification),
838-
}
839-
}
840-
}
841823
_ => {}
842824
}
843825
context.send_to_handler(json_rpc_message).await?;

crates/rmcp/src/transport/streamable_http_server/tower.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,6 @@ where
319319
.map_err(internal_error_response("accept message"))?;
320320
Ok(accepted_response())
321321
}
322-
_ => Ok(Response::builder()
323-
.status(http::StatusCode::NOT_IMPLEMENTED)
324-
.body(
325-
Full::new(Bytes::from("Batch requests are not supported yet")).boxed(),
326-
)
327-
.expect("valid response")),
328322
}
329323
} else {
330324
let (session_id, transport) = self
@@ -427,10 +421,6 @@ where
427421
}
428422
ClientJsonRpcMessage::Response(_json_rpc_response) => Ok(accepted_response()),
429423
ClientJsonRpcMessage::Error(_json_rpc_error) => Ok(accepted_response()),
430-
_ => Ok(Response::builder()
431-
.status(http::StatusCode::NOT_IMPLEMENTED)
432-
.body(Full::new(Bytes::from("Batch requests are not supported yet")).boxed())
433-
.expect("valid response")),
434424
}
435425
}
436426
}

crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema.json

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,6 @@
2727
}
2828
]
2929
},
30-
{
31-
"description": "Multiple requests sent together",
32-
"type": "array",
33-
"items": {
34-
"$ref": "#/definitions/JsonRpcBatchRequestItem"
35-
}
36-
},
37-
{
38-
"description": "Multiple responses sent together",
39-
"type": "array",
40-
"items": {
41-
"$ref": "#/definitions/JsonRpcBatchResponseItem"
42-
}
43-
},
4430
{
4531
"description": "An error response",
4632
"allOf": [
@@ -559,26 +545,6 @@
559545
"format": "const",
560546
"const": "notifications/initialized"
561547
},
562-
"JsonRpcBatchRequestItem": {
563-
"anyOf": [
564-
{
565-
"$ref": "#/definitions/JsonRpcRequest"
566-
},
567-
{
568-
"$ref": "#/definitions/JsonRpcNotification"
569-
}
570-
]
571-
},
572-
"JsonRpcBatchResponseItem": {
573-
"anyOf": [
574-
{
575-
"$ref": "#/definitions/JsonRpcResponse"
576-
},
577-
{
578-
"$ref": "#/definitions/JsonRpcError"
579-
}
580-
]
581-
},
582548
"JsonRpcError": {
583549
"type": "object",
584550
"properties": {

0 commit comments

Comments
 (0)