File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -358,18 +358,22 @@ func (c *Client) discover(ctx context.Context, cs *ClientSession) (*InitializeRe
358358 return nil , false , err
359359 }
360360
361- // Pick the highest protocol version that both the server and this SDK
362- // support. If there is no overlap, fall back to initialize so version
363- // negotiation can happen via the legacy path .
364- negotiated := ""
365- for _ , v := range res . SupportedVersions {
366- if slices .Contains (supportedProtocolVersions , v ) && v > negotiated {
361+ // Pick the highest protocol version that both the server and this SDK support.
362+ // Since supportedProtocolVersions is defined in descending order (newest to oldest),
363+ // the first match we find is the highest supported version .
364+ var negotiated string
365+ for _ , v := range supportedProtocolVersions {
366+ if slices .Contains (res . SupportedVersions , v ) {
367367 negotiated = v
368+ break
368369 }
369370 }
370371 if negotiated == "" {
372+ // If there is no overlap, fall back to initialize so version
373+ // negotiation can happen via the legacy path.
371374 return nil , true , nil
372375 }
376+
373377 return & InitializeResult {
374378 Capabilities : res .Capabilities ,
375379 Instructions : res .Instructions ,
You can’t perform that action at this time.
0 commit comments