MCPcopy Create free account
hub / github.com/github/copilot-sdk / verifyProtocolVersion

Method verifyProtocolVersion

go/client.go:1670–1711  ·  view source on GitHub ↗

verifyProtocolVersion sends the `connect` handshake (carrying the optional token) and verifies the server's protocol version. Falls back to `ping` against legacy servers that don't implement `connect`.

(ctx context.Context)

Source from the content-addressed store, hash-verified

1668// verifies the server's protocol version. Falls back to `ping` against legacy servers
1669// that don't implement `connect`.
1670func (c *Client) verifyProtocolVersion(ctx context.Context) error {
1671 if c.client == nil {
1672 return fmt.Errorf("client not connected")
1673 }
1674 maxVersion := GetSDKProtocolVersion()
1675
1676 var serverVersion *int
1677 tokenPtr := (*string)(nil)
1678 if c.effectiveConnectionToken != "" {
1679 t := c.effectiveConnectionToken
1680 tokenPtr = &t
1681 }
1682 connectResult, err := c.internalRPC.Connect(ctx, &rpc.ConnectRequest{Token: tokenPtr})
1683 if err != nil {
1684 var rpcErr *jsonrpc2.Error
1685 if errors.As(err, &rpcErr) && (rpcErr.Code == jsonrpc2.ErrMethodNotFound.Code || rpcErr.Message == "Unhandled method connect") {
1686 // Legacy server without `connect`; fall back to `ping`. A token, if any,
1687 // is silently dropped — the legacy server can't enforce one.
1688 pingResult, perr := c.Ping(ctx, "")
1689 if perr != nil {
1690 return perr
1691 }
1692 serverVersion = pingResult.ProtocolVersion
1693 } else {
1694 return err
1695 }
1696 } else {
1697 v := int(connectResult.ProtocolVersion)
1698 serverVersion = &v
1699 }
1700
1701 if serverVersion == nil {
1702 return fmt.Errorf("SDK protocol version mismatch: SDK supports versions %d-%d, but server does not report a protocol version. Please update your server to ensure compatibility", minProtocolVersion, maxVersion)
1703 }
1704
1705 if *serverVersion < minProtocolVersion || *serverVersion > maxVersion {
1706 return fmt.Errorf("SDK protocol version mismatch: SDK supports versions %d-%d, but server reports version %d. Please update your SDK or server to ensure compatibility", minProtocolVersion, maxVersion, *serverVersion)
1707 }
1708
1709 c.negotiatedProtocolVersion = *serverVersion
1710 return nil
1711}
1712
1713// stderrBufferSize is the maximum number of bytes kept from the CLI process's
1714// stderr. Only the tail is retained so that memory stays bounded even when the

Callers 1

StartMethod · 0.95

Calls 3

PingMethod · 0.95
GetSDKProtocolVersionFunction · 0.85
ConnectMethod · 0.45

Tested by

no test coverage detected