fix: negotiate protocol version in handler (#930)

* fix: negotiate protocol version in handler (fixes #916)

* fix: use server pinned version as fallback in default initialize handler
This commit is contained in:
actsalan 2026-06-29 10:29:06 -07:00 • committed by GitHub
commit 80a74795e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -162,7 +162,7 @@ where
}
/// Echoes the client-requested version if known; otherwise returns `server_fallback`.
fn negotiate_protocol_version(
pub(crate) fn negotiate_protocol_version(
client_requested: &ProtocolVersion,
server_fallback: ProtocolVersion,
) -> ProtocolVersion {
@ -254,6 +254,11 @@ where
&peer_info.params.protocol_version,
init_response.protocol_version,
);
// Update peer_info so context.protocol_version() reflects the negotiated
// version in all subsequent request handlers.
let mut negotiated_peer_info = peer_info.params.clone();
negotiated_peer_info.protocol_version = init_response.protocol_version.clone();
peer.set_peer_info(negotiated_peer_info);
transport
.send(ServerJsonRpcMessage::response(
ServerResult::InitializeResult(init_response),