@@ -1089,6 +1089,42 @@ impl InitializeResult {
10891089pub type ServerInfo = InitializeResult ;
10901090pub type ClientInfo = InitializeRequestParams ;
10911091
1092+ /// Information learned about a server by a client.
1093+ ///
1094+ /// Legacy initialization requires [`server_info`](Self::server_info), while
1095+ /// the modern discovery lifecycle carries it as optional, self-reported result
1096+ /// metadata. The remaining fields are available in both lifecycle modes.
1097+ #[ derive( Debug , Serialize , Deserialize , Clone , PartialEq ) ]
1098+ #[ serde( rename_all = "camelCase" ) ]
1099+ #[ cfg_attr( feature = "schemars" , derive( schemars:: JsonSchema ) ) ]
1100+ #[ non_exhaustive]
1101+ pub struct ServerPeerInfo {
1102+ /// The negotiated protocol version.
1103+ pub protocol_version : ProtocolVersion ,
1104+ /// The capabilities advertised by the server.
1105+ pub capabilities : ServerCapabilities ,
1106+ /// Optional, self-reported server implementation identity.
1107+ pub server_info : Option < Implementation > ,
1108+ /// Optional human-readable instructions about using the server.
1109+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1110+ pub instructions : Option < String > ,
1111+ /// Protocol-level response metadata.
1112+ #[ serde( rename = "_meta" , skip_serializing_if = "Option::is_none" ) ]
1113+ pub meta : Option < MetaObject > ,
1114+ }
1115+
1116+ impl From < ServerInfo > for ServerPeerInfo {
1117+ fn from ( info : ServerInfo ) -> Self {
1118+ Self {
1119+ protocol_version : info. protocol_version ,
1120+ capabilities : info. capabilities ,
1121+ server_info : Some ( info. server_info ) ,
1122+ instructions : info. instructions ,
1123+ meta : info. meta ,
1124+ }
1125+ }
1126+ }
1127+
10921128const_string ! ( DiscoverRequestMethod = "server/discover" ) ;
10931129
10941130/// Parameters for [`DiscoverRequest`].
@@ -1120,7 +1156,7 @@ impl schemars::JsonSchema for DiscoverRequestParams {
11201156pub type DiscoverRequest = Request < DiscoverRequestMethod , DiscoverRequestParams > ;
11211157
11221158/// The server's response to a [`DiscoverRequest`].
1123- #[ derive( Debug , Serialize , Deserialize , Clone , PartialEq ) ]
1159+ #[ derive( Debug , Serialize , Clone , PartialEq ) ]
11241160#[ serde( rename_all = "camelCase" ) ]
11251161#[ cfg_attr( feature = "schemars" , derive( schemars:: JsonSchema ) ) ]
11261162#[ non_exhaustive]
@@ -1131,8 +1167,6 @@ pub struct DiscoverResult {
11311167 pub supported_versions : Vec < ProtocolVersion > ,
11321168 /// Capabilities provided by this server.
11331169 pub capabilities : ServerCapabilities ,
1134- /// Information about the server implementation.
1135- pub server_info : Implementation ,
11361170 /// Optional guidance for using the server.
11371171 #[ serde( skip_serializing_if = "Option::is_none" ) ]
11381172 pub instructions : Option < String > ,
@@ -1145,18 +1179,77 @@ pub struct DiscoverResult {
11451179 pub meta : Option < MetaObject > ,
11461180}
11471181
1182+ impl < ' de > Deserialize < ' de > for DiscoverResult {
1183+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
1184+ where
1185+ D : serde:: Deserializer < ' de > ,
1186+ {
1187+ #[ derive( Deserialize ) ]
1188+ #[ serde( rename_all = "camelCase" ) ]
1189+ struct Helper {
1190+ result_type : ResultType ,
1191+ supported_versions : Vec < ProtocolVersion > ,
1192+ capabilities : ServerCapabilities ,
1193+ server_info : Option < serde_json:: Value > ,
1194+ instructions : Option < String > ,
1195+ ttl_ms : u64 ,
1196+ cache_scope : CacheScope ,
1197+ #[ serde( rename = "_meta" ) ]
1198+ meta : Option < MetaObject > ,
1199+ }
1200+
1201+ let mut helper = Helper :: deserialize ( deserializer) ?;
1202+ let has_canonical_server_info = helper
1203+ . meta
1204+ . as_ref ( )
1205+ . is_some_and ( |metadata| metadata. 0 . contains_key ( MetaObject :: META_KEY_SERVER_INFO ) ) ;
1206+ if !has_canonical_server_info
1207+ && let Some ( server_info) = helper
1208+ . server_info
1209+ . and_then ( |value| serde_json:: from_value :: < Implementation > ( value) . ok ( ) )
1210+ {
1211+ helper
1212+ . meta
1213+ . get_or_insert_with ( MetaObject :: new)
1214+ . set_server_info ( server_info) ;
1215+ }
1216+
1217+ Ok ( Self {
1218+ result_type : helper. result_type ,
1219+ supported_versions : helper. supported_versions ,
1220+ capabilities : helper. capabilities ,
1221+ instructions : helper. instructions ,
1222+ ttl_ms : helper. ttl_ms ,
1223+ cache_scope : helper. cache_scope ,
1224+ meta : helper. meta ,
1225+ } )
1226+ }
1227+ }
1228+
11481229impl DiscoverResult {
11491230 /// Create a non-cacheable private discovery result.
11501231 pub fn new (
11511232 supported_versions : Vec < ProtocolVersion > ,
11521233 capabilities : ServerCapabilities ,
11531234 server_info : Implementation ,
1235+ ) -> Self {
1236+ Self :: new_without_server_info ( supported_versions, capabilities)
1237+ . with_server_info ( server_info)
1238+ }
1239+
1240+ /// Create a non-cacheable private discovery result without a server identity.
1241+ ///
1242+ /// Server identity is optional display-only metadata. Servers should normally
1243+ /// use [`DiscoverResult::new`], but this constructor supports peers that do
1244+ /// not advertise an implementation name and version.
1245+ pub fn new_without_server_info (
1246+ supported_versions : Vec < ProtocolVersion > ,
1247+ capabilities : ServerCapabilities ,
11541248 ) -> Self {
11551249 Self {
11561250 result_type : ResultType :: COMPLETE ,
11571251 supported_versions,
11581252 capabilities,
1159- server_info,
11601253 instructions : None ,
11611254 ttl_ms : 0 ,
11621255 cache_scope : CacheScope :: Private ,
@@ -1178,10 +1271,30 @@ impl DiscoverResult {
11781271 } = server_info;
11791272 let mut result = Self :: new ( supported_versions, capabilities, server_info) ;
11801273 result. instructions = instructions;
1181- result. meta = meta;
1274+ if let Some ( meta) = meta {
1275+ result. meta . get_or_insert_with ( MetaObject :: new) . extend ( meta) ;
1276+ }
11821277 result
11831278 }
11841279
1280+ /// Return the optional self-reported server identity from result metadata.
1281+ pub fn server_info ( & self ) -> Option < Implementation > {
1282+ self . meta . as_ref ( ) . and_then ( MetaObject :: server_info)
1283+ }
1284+
1285+ /// Set the self-reported server identity in canonical result metadata.
1286+ pub fn set_server_info ( & mut self , server_info : Implementation ) {
1287+ self . meta
1288+ . get_or_insert_with ( MetaObject :: new)
1289+ . set_server_info ( server_info) ;
1290+ }
1291+
1292+ /// Set the self-reported server identity in canonical result metadata.
1293+ pub fn with_server_info ( mut self , server_info : Implementation ) -> Self {
1294+ self . set_server_info ( server_info) ;
1295+ self
1296+ }
1297+
11851298 /// Set the cache lifetime hint in milliseconds.
11861299 pub fn with_ttl_ms ( mut self , ttl_ms : u64 ) -> Self {
11871300 self . ttl_ms = ttl_ms;
0 commit comments