mco: update JSON-RPC error codes to align with updated MCP specification (#1016)

This PR updates the error codes to align with the updated specifications
in
https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2907

ErrServerClosing and ErrClientClosing are reverted to their 1.6.0
version codes, as they do not overlap anymore with the newly introduced
error codes.
This commit is contained in:
Guglielmo Colombo 2026-06-22 10:27:31 +02:00 • committed by GitHub
commit 3486f6bcaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -306,7 +306,7 @@ func (c *Client) Connect(ctx context.Context, t Transport, opts *ClientSessionOp
// Try to negotiate a mutually supported version if the server
// reports an UnsupportedProtocolVersionError with a supported version.
var werr *jsonrpc.Error
if errors.As(err, &werr) && werr.Code == CodeUnsupportedProtocolVersion && werr.Data != nil {
if errors.As(err, &werr) && werr.Code == CodeUnsupportedProtocolVersion && len(werr.Data) > 0 {
var data UnsupportedProtocolVersionData
if err := json.Unmarshal(werr.Data, &data); err == nil {
if negotiatedVersion := negotiateMutuallySupportedVersion(data.Supported); negotiatedVersion != "" && negotiatedVersion >= protocolVersion20260728 {
@ -384,7 +384,10 @@ func (c *Client) discover(ctx context.Context, cs *ClientSession) (*InitializeRe
if negotiated == "" || negotiated < protocolVersion20260728 {
// If there is no overlap, fall back to initialize so version
// negotiation can happen via the legacy path.
return nil, jsonrpc2.ErrUnsupportedProtocolVersion
return nil, &jsonrpc2.WireError{
Code: CodeUnsupportedProtocolVersion,
Message: "unsupported protocol version",
}
}
return &InitializeResult{