@@ -6,9 +6,10 @@ use crate::model::{
66 ClientRequest , ClientResult , CreateMessageRequest , CreateMessageRequestParam ,
77 CreateMessageResult , ListRootsRequest , ListRootsResult , LoggingMessageNotification ,
88 LoggingMessageNotificationParam , ProgressNotification , ProgressNotificationParam ,
9- PromptListChangedNotification , ResourceListChangedNotification , ResourceUpdatedNotification ,
10- ResourceUpdatedNotificationParam , ServerInfo , ServerJsonRpcMessage , ServerNotification ,
11- ServerRequest , ServerResult , ToolListChangedNotification ,
9+ PromptListChangedNotification , ProtocolVersion , ResourceListChangedNotification ,
10+ ResourceUpdatedNotification , ResourceUpdatedNotificationParam , ServerInfo ,
11+ ServerJsonRpcMessage , ServerNotification , ServerRequest , ServerResult ,
12+ ToolListChangedNotification ,
1213} ;
1314
1415#[ derive( Debug , Clone , Copy , Default , PartialEq , Eq ) ]
@@ -65,11 +66,11 @@ where
6566 T : IntoTransport < RoleServer , E , A > ,
6667 E : std:: error:: Error + From < std:: io:: Error > + Send + Sync + ' static ,
6768{
69+ const SUPPORTED_HIGHEST_VERSION : ProtocolVersion = ProtocolVersion :: LATEST ;
6870 let ( sink, stream) = transport. into_transport ( ) ;
6971 let mut sink = Box :: pin ( sink) ;
7072 let mut stream = Box :: pin ( stream) ;
7173 let id_provider = <Arc < AtomicU32RequestIdProvider > >:: default ( ) ;
72-
7374 // service
7475 let ( request, id) = stream
7576 . next ( )
9091 )
9192 . into ( ) ) ;
9293 } ;
93- let init_response = service. get_info ( ) ;
94+
95+ let protocol_version = match peer_info
96+ . params
97+ . protocol_version
98+ . partial_cmp ( & SUPPORTED_HIGHEST_VERSION )
99+ . ok_or ( std:: io:: Error :: new (
100+ std:: io:: ErrorKind :: InvalidData ,
101+ "unsupported protocol version" ,
102+ ) ) ? {
103+ std:: cmp:: Ordering :: Less => peer_info. params . protocol_version . clone ( ) ,
104+ _ => SUPPORTED_HIGHEST_VERSION ,
105+ } ;
106+
107+ let mut init_response = service. get_info ( ) ;
108+ init_response. protocol_version = protocol_version;
94109 sink. send ( ServerJsonRpcMessage :: response (
95110 ServerResult :: InitializeResult ( init_response) ,
96111 id,
0 commit comments