@@ -524,6 +524,10 @@ pub struct JsonRpcNotification<N = Notification> {
524524pub struct ErrorCode ( pub i32 ) ;
525525
526526impl ErrorCode {
527+ /// The request used a protocol version the server does not support.
528+ pub const UNSUPPORTED_PROTOCOL_VERSION : Self = Self ( -32022 ) ;
529+ /// Processing the request requires a client capability that was not declared.
530+ pub const MISSING_REQUIRED_CLIENT_CAPABILITY : Self = Self ( -32021 ) ;
527531 pub const HEADER_MISMATCH : Self = Self ( -32020 ) ;
528532 pub const RESOURCE_NOT_FOUND : Self = Self ( -32002 ) ;
529533 pub const INVALID_REQUEST : Self = Self ( -32600 ) ;
@@ -573,6 +577,30 @@ impl ErrorData {
573577 pub fn header_mismatch ( message : impl Into < Cow < ' static , str > > , data : Option < Value > ) -> Self {
574578 Self :: new ( ErrorCode :: HEADER_MISMATCH , message, data)
575579 }
580+ /// Create an unsupported-protocol-version error.
581+ pub fn unsupported_protocol_version (
582+ requested : ProtocolVersion ,
583+ supported : & [ ProtocolVersion ] ,
584+ ) -> Self {
585+ Self :: new (
586+ ErrorCode :: UNSUPPORTED_PROTOCOL_VERSION ,
587+ "Unsupported protocol version" ,
588+ Some ( serde_json:: json!( {
589+ "requested" : requested,
590+ "supported" : supported,
591+ } ) ) ,
592+ )
593+ }
594+ /// Create a missing-required-capability error.
595+ pub fn missing_required_client_capability ( required : ClientCapabilities ) -> Self {
596+ Self :: new (
597+ ErrorCode :: MISSING_REQUIRED_CLIENT_CAPABILITY ,
598+ "Missing required client capability" ,
599+ Some ( serde_json:: json!( {
600+ "requiredCapabilities" : required,
601+ } ) ) ,
602+ )
603+ }
576604 pub fn parse_error ( message : impl Into < Cow < ' static , str > > , data : Option < Value > ) -> Self {
577605 Self :: new ( ErrorCode :: PARSE_ERROR , message, data)
578606 }
@@ -1000,6 +1028,112 @@ impl InitializeResult {
10001028pub type ServerInfo = InitializeResult ;
10011029pub type ClientInfo = InitializeRequestParams ;
10021030
1031+ const_string ! ( DiscoverRequestMethod = "server/discover" ) ;
1032+
1033+ /// Parameters for [`DiscoverRequest`].
1034+ #[ derive( Debug , Serialize , Deserialize , Clone , Copy , PartialEq , Eq , Default ) ]
1035+ #[ serde( deny_unknown_fields) ]
1036+ #[ expect( clippy:: exhaustive_structs, reason = "intentionally exhaustive" ) ]
1037+ pub struct DiscoverRequestParams { }
1038+
1039+ #[ cfg( feature = "schemars" ) ]
1040+ #[ derive( schemars:: JsonSchema ) ]
1041+ #[ expect( dead_code, reason = "schema-only representation of request parameters" ) ]
1042+ struct DiscoverRequestParamsSchema {
1043+ #[ schemars( rename = "_meta" ) ]
1044+ meta : RequestMetaObject ,
1045+ }
1046+
1047+ #[ cfg( feature = "schemars" ) ]
1048+ impl schemars:: JsonSchema for DiscoverRequestParams {
1049+ fn schema_name ( ) -> Cow < ' static , str > {
1050+ Cow :: Borrowed ( "DiscoverRequestParams" )
1051+ }
1052+
1053+ fn json_schema ( generator : & mut schemars:: SchemaGenerator ) -> schemars:: Schema {
1054+ DiscoverRequestParamsSchema :: json_schema ( generator)
1055+ }
1056+ }
1057+
1058+ /// A request for the server's supported protocol versions and capabilities.
1059+ pub type DiscoverRequest = Request < DiscoverRequestMethod , DiscoverRequestParams > ;
1060+
1061+ /// The server's response to a [`DiscoverRequest`].
1062+ #[ derive( Debug , Serialize , Deserialize , Clone , PartialEq ) ]
1063+ #[ serde( rename_all = "camelCase" ) ]
1064+ #[ cfg_attr( feature = "schemars" , derive( schemars:: JsonSchema ) ) ]
1065+ #[ non_exhaustive]
1066+ pub struct DiscoverResult {
1067+ /// Identifies how the result should be parsed.
1068+ pub result_type : ResultType ,
1069+ /// Protocol versions implemented by this server.
1070+ pub supported_versions : Vec < ProtocolVersion > ,
1071+ /// Capabilities provided by this server.
1072+ pub capabilities : ServerCapabilities ,
1073+ /// Information about the server implementation.
1074+ pub server_info : Implementation ,
1075+ /// Optional guidance for using the server.
1076+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1077+ pub instructions : Option < String > ,
1078+ /// How long clients may consider this response fresh, in milliseconds.
1079+ pub ttl_ms : u64 ,
1080+ /// Whether the cached result may be shared across authorization contexts.
1081+ pub cache_scope : CacheScope ,
1082+ /// Protocol-level response metadata.
1083+ #[ serde( rename = "_meta" , skip_serializing_if = "Option::is_none" ) ]
1084+ pub meta : Option < MetaObject > ,
1085+ }
1086+
1087+ impl DiscoverResult {
1088+ /// Create a non-cacheable private discovery result.
1089+ pub fn new (
1090+ supported_versions : Vec < ProtocolVersion > ,
1091+ capabilities : ServerCapabilities ,
1092+ server_info : Implementation ,
1093+ ) -> Self {
1094+ Self {
1095+ result_type : ResultType :: COMPLETE ,
1096+ supported_versions,
1097+ capabilities,
1098+ server_info,
1099+ instructions : None ,
1100+ ttl_ms : 0 ,
1101+ cache_scope : CacheScope :: Private ,
1102+ meta : None ,
1103+ }
1104+ }
1105+
1106+ /// Create a discovery result from the server's initialization information.
1107+ pub fn from_server_info (
1108+ supported_versions : Vec < ProtocolVersion > ,
1109+ server_info : ServerInfo ,
1110+ ) -> Self {
1111+ let ServerInfo {
1112+ capabilities,
1113+ server_info,
1114+ instructions,
1115+ meta,
1116+ ..
1117+ } = server_info;
1118+ let mut result = Self :: new ( supported_versions, capabilities, server_info) ;
1119+ result. instructions = instructions;
1120+ result. meta = meta;
1121+ result
1122+ }
1123+
1124+ /// Set the cache lifetime hint in milliseconds.
1125+ pub fn with_ttl_ms ( mut self , ttl_ms : u64 ) -> Self {
1126+ self . ttl_ms = ttl_ms;
1127+ self
1128+ }
1129+
1130+ /// Set the cache scope.
1131+ pub fn with_cache_scope ( mut self , cache_scope : CacheScope ) -> Self {
1132+ self . cache_scope = cache_scope;
1133+ self
1134+ }
1135+ }
1136+
10031137#[ allow( clippy:: derivable_impls) ]
10041138impl Default for ServerInfo {
10051139 fn default ( ) -> Self {
@@ -3795,6 +3929,7 @@ ts_union!(
37953929 export type ClientRequest =
37963930 | PingRequest
37973931 | InitializeRequest
3932+ | DiscoverRequest
37983933 | CompleteRequest
37993934 | SetLevelRequest
38003935 | GetPromptRequest
@@ -3818,6 +3953,7 @@ impl ClientRequest {
38183953 match & self {
38193954 ClientRequest :: PingRequest ( r) => r. method . as_str ( ) ,
38203955 ClientRequest :: InitializeRequest ( r) => r. method . as_str ( ) ,
3956+ ClientRequest :: DiscoverRequest ( r) => r. method . as_str ( ) ,
38213957 ClientRequest :: CompleteRequest ( r) => r. method . as_str ( ) ,
38223958 ClientRequest :: SetLevelRequest ( r) => r. method . as_str ( ) ,
38233959 ClientRequest :: GetPromptRequest ( r) => r. method . as_str ( ) ,
@@ -3889,6 +4025,7 @@ ts_union!(
38894025
38904026ts_union ! (
38914027 export type ServerResult =
4028+ | DiscoverResult
38924029 | InitializeResult
38934030 | CompleteResult
38944031 | GetPromptResult
0 commit comments