fix: honor supported_protocol_versions when negotiating initialize (#1093)

This commit is contained in:
Dale Seo 2026-07-30 15:44:37 -04:00 • committed by GitHub
commit d272389fd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -460,12 +460,18 @@ where
}
}
/// Echoes the client-requested version if known; otherwise returns `server_fallback`.
/// Echoes the client-requested version if the server supports it; otherwise
/// returns `server_fallback`.
///
/// `server_supported` comes from [`Service::supported_protocol_versions`], so a
/// server that narrows that list is never made to answer `initialize` with a
/// version it cannot serve.
pub(crate) fn negotiate_protocol_version(
client_requested: &ProtocolVersion,
server_fallback: ProtocolVersion,
server_supported: &[ProtocolVersion],
) -> ProtocolVersion {
if ProtocolVersion::KNOWN_VERSIONS.contains(client_requested) {
if server_supported.contains(client_requested) {
client_requested.clone()
} else {
tracing::warn!(
@ -578,8 +584,11 @@ where
return Err(ServerInitializeError::InitializeFailed(e));
}
};
init_response.protocol_version =
negotiate_protocol_version(&requested_protocol_version, init_response.protocol_version);
init_response.protocol_version = negotiate_protocol_version(
&requested_protocol_version,
init_response.protocol_version,
&service.supported_protocol_versions(),
);
// Update peer_info so context.protocol_version() reflects the negotiated
// version in all subsequent request handlers.
negotiated_peer_info.protocol_version = init_response.protocol_version.clone();