@@ -1089,42 +1089,6 @@ 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-
11281092const_string ! ( DiscoverRequestMethod = "server/discover" ) ;
11291093
11301094/// Parameters for [`DiscoverRequest`].
@@ -1167,6 +1131,8 @@ pub struct DiscoverResult {
11671131 pub supported_versions : Vec < ProtocolVersion > ,
11681132 /// Capabilities provided by this server.
11691133 pub capabilities : ServerCapabilities ,
1134+ /// Information about the server implementation.
1135+ pub server_info : Implementation ,
11701136 /// Optional guidance for using the server.
11711137 #[ serde( skip_serializing_if = "Option::is_none" ) ]
11721138 pub instructions : Option < String > ,
@@ -1180,44 +1146,44 @@ pub struct DiscoverResult {
11801146}
11811147
11821148impl < ' de > Deserialize < ' de > for DiscoverResult {
1183- fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
1149+ fn deserialize < __D > ( deserializer : __D ) -> Result < Self , __D :: Error >
11841150 where
1185- D : serde:: Deserializer < ' de > ,
1151+ __D : serde:: Deserializer < ' de > ,
11861152 {
11871153 #[ derive( Deserialize ) ]
11881154 #[ serde( rename_all = "camelCase" ) ]
11891155 struct Helper {
11901156 result_type : ResultType ,
11911157 supported_versions : Vec < ProtocolVersion > ,
11921158 capabilities : ServerCapabilities ,
1193- server_info : Option < serde_json :: Value > ,
1159+ server_info : Option < Implementation > ,
11941160 instructions : Option < String > ,
11951161 ttl_ms : u64 ,
11961162 cache_scope : CacheScope ,
11971163 #[ serde( rename = "_meta" ) ]
11981164 meta : Option < MetaObject > ,
11991165 }
12001166
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- }
1167+ let helper = Helper :: deserialize ( deserializer) ?;
1168+ let server_info = match helper. server_info {
1169+ Some ( server_info) => server_info,
1170+ None => {
1171+ let metadata_server_info = helper
1172+ . meta
1173+ . as_ref ( )
1174+ . and_then ( |metadata| metadata. 0 . get ( "io.modelcontextprotocol/serverInfo" ) )
1175+ . ok_or_else ( || serde:: de:: Error :: missing_field ( "serverInfo" ) ) ?;
1176+
1177+ serde_json:: from_value ( metadata_server_info. clone ( ) )
1178+ . map_err ( serde:: de:: Error :: custom) ?
1179+ }
1180+ } ;
12161181
12171182 Ok ( Self {
12181183 result_type : helper. result_type ,
12191184 supported_versions : helper. supported_versions ,
12201185 capabilities : helper. capabilities ,
1186+ server_info,
12211187 instructions : helper. instructions ,
12221188 ttl_ms : helper. ttl_ms ,
12231189 cache_scope : helper. cache_scope ,
@@ -1232,24 +1198,12 @@ impl DiscoverResult {
12321198 supported_versions : Vec < ProtocolVersion > ,
12331199 capabilities : ServerCapabilities ,
12341200 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 ,
12481201 ) -> Self {
12491202 Self {
12501203 result_type : ResultType :: COMPLETE ,
12511204 supported_versions,
12521205 capabilities,
1206+ server_info,
12531207 instructions : None ,
12541208 ttl_ms : 0 ,
12551209 cache_scope : CacheScope :: Private ,
@@ -1271,30 +1225,10 @@ impl DiscoverResult {
12711225 } = server_info;
12721226 let mut result = Self :: new ( supported_versions, capabilities, server_info) ;
12731227 result. instructions = instructions;
1274- if let Some ( meta) = meta {
1275- result. meta . get_or_insert_with ( MetaObject :: new) . extend ( meta) ;
1276- }
1228+ result. meta = meta;
12771229 result
12781230 }
12791231
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-
12981232 /// Set the cache lifetime hint in milliseconds.
12991233 pub fn with_ttl_ms ( mut self , ttl_ms : u64 ) -> Self {
13001234 self . ttl_ms = ttl_ms;
0 commit comments