fix: accept namespaced discovery server information (#1044)
* fix: accept namespaced discovery server information (#1039) * fix: preserve discovery server-info compatibility
This commit is contained in:
parent
9528801f6e
commit
2047ae42ec
1 changed files with 170 additions and 1 deletions
|
|
@ -1120,7 +1120,7 @@ impl schemars::JsonSchema for DiscoverRequestParams {
|
|||
pub type DiscoverRequest = Request<DiscoverRequestMethod, DiscoverRequestParams>;
|
||||
|
||||
/// The server's response to a [`DiscoverRequest`].
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||
#[derive(Debug, Serialize, Clone, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[non_exhaustive]
|
||||
|
|
@ -1145,6 +1145,53 @@ pub struct DiscoverResult {
|
|||
pub meta: Option<MetaObject>,
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for DiscoverResult {
|
||||
fn deserialize<__D>(deserializer: __D) -> Result<Self, __D::Error>
|
||||
where
|
||||
__D: serde::Deserializer<'de>,
|
||||
{
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct Helper {
|
||||
result_type: ResultType,
|
||||
supported_versions: Vec<ProtocolVersion>,
|
||||
capabilities: ServerCapabilities,
|
||||
server_info: Option<Implementation>,
|
||||
instructions: Option<String>,
|
||||
ttl_ms: u64,
|
||||
cache_scope: CacheScope,
|
||||
#[serde(rename = "_meta")]
|
||||
meta: Option<MetaObject>,
|
||||
}
|
||||
|
||||
let helper = Helper::deserialize(deserializer)?;
|
||||
let server_info = match helper.server_info {
|
||||
Some(server_info) => server_info,
|
||||
None => {
|
||||
let metadata_server_info = helper
|
||||
.meta
|
||||
.as_ref()
|
||||
.and_then(|metadata| metadata.0.get("io.modelcontextprotocol/serverInfo"))
|
||||
.ok_or_else(|| serde::de::Error::missing_field("serverInfo"))?;
|
||||
|
||||
serde_json::from_value(metadata_server_info.clone())
|
||||
.map_err(serde::de::Error::custom)?
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
result_type: helper.result_type,
|
||||
supported_versions: helper.supported_versions,
|
||||
capabilities: helper.capabilities,
|
||||
server_info,
|
||||
instructions: helper.instructions,
|
||||
ttl_ms: helper.ttl_ms,
|
||||
cache_scope: helper.cache_scope,
|
||||
meta: helper.meta,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl DiscoverResult {
|
||||
/// Create a non-cacheable private discovery result.
|
||||
pub fn new(
|
||||
|
|
|
|||
Loading…
Reference in a new issue