@@ -8,7 +8,7 @@ use anyhow::Result;
88use futures:: SinkExt ;
99use rmcp:: model:: {
1010 ClientJsonRpcMessage , ClientNotification , ClientRequest , EmptyResult , InitializedNotification ,
11- InitializedNotificationMethod , RequestId , ServerJsonRpcMessage ,
11+ InitializedNotificationMethod , ProtocolVersion , RequestId , ServerJsonRpcMessage , ServerResult ,
1212} ;
1313use std:: collections:: HashMap ;
1414use std:: time:: { Duration , Instant } ;
@@ -49,6 +49,8 @@ pub struct AppState {
4949 pub url : String ,
5050 /// Maximum time to try reconnecting in seconds (None = infinity)
5151 pub max_disconnected_time : Option < u64 > ,
52+ /// Override protocol version
53+ pub override_protocol_version : Option < ProtocolVersion > ,
5254 /// When we were disconnected
5355 pub disconnected_since : Option < Instant > ,
5456 /// Current state of the application
@@ -78,10 +80,15 @@ pub struct AppState {
7880}
7981
8082impl AppState {
81- pub fn new ( url : String , max_disconnected_time : Option < u64 > ) -> Self {
83+ pub fn new (
84+ url : String ,
85+ max_disconnected_time : Option < u64 > ,
86+ override_protocol_version : Option < ProtocolVersion > ,
87+ ) -> Self {
8288 Self {
8389 url,
8490 max_disconnected_time,
91+ override_protocol_version,
8592 disconnected_since : None ,
8693 state : ProxyState :: Connecting ,
8794 connect_tries : 0 ,
@@ -286,6 +293,7 @@ impl AppState {
286293 "Initial connection successful, received init response. Waiting for client initialized."
287294 ) ;
288295 self . state = ProxyState :: WaitingForClientInitialized ;
296+ message = self . maybe_overwrite_protocol_version ( message) ;
289297 }
290298 }
291299 // --- End Initialization Response Handling ---
@@ -537,4 +545,25 @@ impl AppState {
537545 // Not a response/error, return Some(original_message)
538546 Some ( message)
539547 }
548+
549+ fn maybe_overwrite_protocol_version (
550+ & mut self ,
551+ message : ServerJsonRpcMessage ,
552+ ) -> ServerJsonRpcMessage {
553+ if let Some ( protocol_version) = & self . override_protocol_version {
554+ match message {
555+ ServerJsonRpcMessage :: Response ( mut resp) => {
556+ if let ServerResult :: InitializeResult ( mut initialize_result) = resp. result {
557+ initialize_result. protocol_version = protocol_version. clone ( ) ;
558+ resp. result = ServerResult :: InitializeResult ( initialize_result) ;
559+ return ServerJsonRpcMessage :: Response ( resp) ;
560+ }
561+ ServerJsonRpcMessage :: Response ( resp)
562+ }
563+ other => other,
564+ }
565+ } else {
566+ message
567+ }
568+ }
540569}
0 commit comments