fix: honor supported_protocol_versions when negotiating initialize (#1093)
This commit is contained in:
parent
51c8ee60e3
commit
d272389fd4
2 changed files with 246 additions and 16 deletions
|
|
@ -300,6 +300,10 @@ impl<H: ServerHandler> Service<RoleServer> for H {
|
|||
fn get_info(&self) -> <RoleServer as ServiceRole>::Info {
|
||||
self.get_info()
|
||||
}
|
||||
|
||||
fn supported_protocol_versions(&self) -> Cow<'static, [ProtocolVersion]> {
|
||||
ServerHandler::supported_protocol_versions(self)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! server_handler_methods {
|
||||
|
|
@ -321,10 +325,17 @@ macro_rules! server_handler_methods {
|
|||
info.protocol_version = negotiate_protocol_version(
|
||||
&request.protocol_version,
|
||||
info.protocol_version,
|
||||
&self.supported_protocol_versions(),
|
||||
);
|
||||
std::future::ready(Ok(info))
|
||||
}
|
||||
/// Return the protocol versions supported by this server.
|
||||
///
|
||||
/// Defaults to every version this SDK knows. Override it to narrow the
|
||||
/// set to the revisions the server actually implements: the returned
|
||||
/// list is advertised by [`Self::discover`], bounds what `initialize`
|
||||
/// negotiation may agree to, and is what per-request versions are
|
||||
/// validated against.
|
||||
fn supported_protocol_versions(&self) -> Cow<'static, [ProtocolVersion]> {
|
||||
Cow::Borrowed(ProtocolVersion::KNOWN_VERSIONS)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::sync::Arc;
|
||||
use std::{borrow::Cow, sync::Arc};
|
||||
|
||||
use prompt::{IntoPromptRoute, PromptRoute};
|
||||
use tool::{IntoToolRoute, ToolRoute};
|
||||
|
|
@ -6,7 +6,10 @@ use tool::{IntoToolRoute, ToolRoute};
|
|||
use super::ServerHandler;
|
||||
use crate::{
|
||||
RoleServer, Service,
|
||||
model::{ClientNotification, ClientRequest, ListPromptsResult, ListToolsResult, ServerResult},
|
||||
model::{
|
||||
ClientNotification, ClientRequest, ListPromptsResult, ListToolsResult, ProtocolVersion,
|
||||
ServerResult,
|
||||
},
|
||||
service::NotificationContext,
|
||||
};
|
||||
|
||||
|
|
@ -155,6 +158,10 @@ where
|
|||
.list_changed = Some(true);
|
||||
info
|
||||
}
|
||||
|
||||
fn supported_protocol_versions(&self) -> Cow<'static, [ProtocolVersion]> {
|
||||
ServerHandler::supported_protocol_versions(&self.service)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue