@@ -60,6 +60,7 @@ fn detect_message_type(value: &serde_json::Value) -> MessageTypes {
60
60
/// This trait defines methods to classify and extract information from messages.
61
61
pub trait RPCMessage {
62
62
fn request_id ( & self ) -> Option < & RequestId > ;
63
+ fn jsonrpc ( & self ) -> & str ;
63
64
}
64
65
65
66
pub trait MCPMessage : RPCMessage {
@@ -132,6 +133,15 @@ impl RPCMessage for ClientMessage {
132
133
ClientMessage :: Error ( jsonrpc_error) => Some ( & jsonrpc_error. id ) ,
133
134
}
134
135
}
136
+
137
+ fn jsonrpc ( & self ) -> & str {
138
+ match self {
139
+ ClientMessage :: Request ( client_jsonrpc_request) => client_jsonrpc_request. jsonrpc ( ) ,
140
+ ClientMessage :: Notification ( notification) => notification. jsonrpc ( ) ,
141
+ ClientMessage :: Response ( client_jsonrpc_response) => client_jsonrpc_response. jsonrpc ( ) ,
142
+ ClientMessage :: Error ( jsonrpc_error) => jsonrpc_error. jsonrpc ( ) ,
143
+ }
144
+ }
135
145
}
136
146
137
147
// Implementing the `MCPMessage` trait for `ClientMessage`
@@ -175,7 +185,7 @@ impl MCPMessage for ClientMessage {
175
185
#[ derive( Clone , Debug ) ]
176
186
pub struct ClientJsonrpcRequest {
177
187
pub id : RequestId ,
178
- pub jsonrpc : :: std:: string:: String ,
188
+ jsonrpc : :: std:: string:: String ,
179
189
pub method : String ,
180
190
pub request : RequestFromClient ,
181
191
}
@@ -190,6 +200,9 @@ impl ClientJsonrpcRequest {
190
200
request,
191
201
}
192
202
}
203
+ pub fn jsonrpc ( & self ) -> & :: std:: string:: String {
204
+ & self . jsonrpc
205
+ }
193
206
}
194
207
195
208
/// Formats the ClientJsonrpcRequest as a JSON string.
@@ -298,7 +311,7 @@ impl<'de> serde::Deserialize<'de> for RequestFromClient {
298
311
/// "Similar to JsonrpcNotification , but with the variants restricted to client-side notifications."
299
312
#[ derive( Clone , Debug ) ]
300
313
pub struct ClientJsonrpcNotification {
301
- pub jsonrpc : :: std:: string:: String ,
314
+ jsonrpc : :: std:: string:: String ,
302
315
pub method : :: std:: string:: String ,
303
316
pub notification : NotificationFromClient ,
304
317
}
@@ -312,6 +325,9 @@ impl ClientJsonrpcNotification {
312
325
notification,
313
326
}
314
327
}
328
+ pub fn jsonrpc ( & self ) -> & :: std:: string:: String {
329
+ & self . jsonrpc
330
+ }
315
331
}
316
332
317
333
/// Formats the ClientJsonrpcNotification as a JSON string.
@@ -388,7 +404,7 @@ impl<'de> serde::Deserialize<'de> for NotificationFromClient {
388
404
#[ derive( Clone , Debug ) ]
389
405
pub struct ClientJsonrpcResponse {
390
406
pub id : RequestId ,
391
- pub jsonrpc : :: std:: string:: String ,
407
+ jsonrpc : :: std:: string:: String ,
392
408
pub result : ResultFromClient ,
393
409
}
394
410
@@ -400,6 +416,9 @@ impl ClientJsonrpcResponse {
400
416
result,
401
417
}
402
418
}
419
+ pub fn jsonrpc ( & self ) -> & :: std:: string:: String {
420
+ & self . jsonrpc
421
+ }
403
422
}
404
423
405
424
/// Formats the ClientJsonrpcResponse as a JSON string.
@@ -514,6 +533,19 @@ impl RPCMessage for ServerMessage {
514
533
ServerMessage :: Error ( jsonrpc_error) => Some ( & jsonrpc_error. id ) ,
515
534
}
516
535
}
536
+
537
+ fn jsonrpc ( & self ) -> & str {
538
+ match self {
539
+ // If the message is a request, return the associated request ID
540
+ ServerMessage :: Request ( client_jsonrpc_request) => client_jsonrpc_request. jsonrpc ( ) ,
541
+ // Notifications do not have request IDs
542
+ ServerMessage :: Notification ( notification) => notification. jsonrpc ( ) ,
543
+ // If the message is a response, return the associated request ID
544
+ ServerMessage :: Response ( client_jsonrpc_response) => client_jsonrpc_response. jsonrpc ( ) ,
545
+ // If the message is an error, return the associated request ID
546
+ ServerMessage :: Error ( jsonrpc_error) => jsonrpc_error. jsonrpc ( ) ,
547
+ }
548
+ }
517
549
}
518
550
519
551
// Implementing the `MCPMessage` trait for `ServerMessage`
@@ -576,7 +608,7 @@ impl Display for ServerMessage {
576
608
#[ derive( Clone , Debug ) ]
577
609
pub struct ServerJsonrpcRequest {
578
610
pub id : RequestId ,
579
- pub jsonrpc : :: std:: string:: String ,
611
+ jsonrpc : :: std:: string:: String ,
580
612
pub method : String ,
581
613
pub request : RequestFromServer ,
582
614
}
@@ -591,6 +623,9 @@ impl ServerJsonrpcRequest {
591
623
request,
592
624
}
593
625
}
626
+ pub fn jsonrpc ( & self ) -> & :: std:: string:: String {
627
+ & self . jsonrpc
628
+ }
594
629
}
595
630
596
631
/// Formats the ServerJsonrpcRequest as a JSON string.
@@ -677,7 +712,7 @@ impl<'de> serde::Deserialize<'de> for RequestFromServer {
677
712
/// "Similar to JsonrpcNotification , but with the variants restricted to server-side notifications."
678
713
#[ derive( Clone , Debug ) ]
679
714
pub struct ServerJsonrpcNotification {
680
- pub jsonrpc : :: std:: string:: String ,
715
+ jsonrpc : :: std:: string:: String ,
681
716
pub method : :: std:: string:: String ,
682
717
pub notification : NotificationFromServer ,
683
718
}
@@ -691,6 +726,9 @@ impl ServerJsonrpcNotification {
691
726
notification,
692
727
}
693
728
}
729
+ pub fn jsonrpc ( & self ) -> & :: std:: string:: String {
730
+ & self . jsonrpc
731
+ }
694
732
}
695
733
696
734
/// Formats the ServerJsonrpcNotification as a JSON string.
@@ -766,7 +804,7 @@ impl<'de> serde::Deserialize<'de> for NotificationFromServer {
766
804
#[ derive( Clone , Debug ) ]
767
805
pub struct ServerJsonrpcResponse {
768
806
pub id : RequestId ,
769
- pub jsonrpc : :: std:: string:: String ,
807
+ jsonrpc : :: std:: string:: String ,
770
808
pub result : ResultFromServer ,
771
809
}
772
810
@@ -778,6 +816,9 @@ impl ServerJsonrpcResponse {
778
816
result,
779
817
}
780
818
}
819
+ pub fn jsonrpc ( & self ) -> & :: std:: string:: String {
820
+ & self . jsonrpc
821
+ }
781
822
}
782
823
783
824
/// Formats the ServerJsonrpcResponse as a JSON string.
0 commit comments