mcp: Implement support for SEP-2575 on client side (#975)

Implements the client half of the SEP-2575 / `2026-06-30` protocol. This
CL is client-only; server-side `server/discover` is still a
`MethodNotFound` stub.
### Changes
- **`server/discover` probe in `Client.Connect()`** (`client.go`). When
the caller opts into `protocolVersion >= 2026-06-30`, the client probes
the server with `server/discover` before falling back to the legacy
`initialize`
  handshake.
- **Per-request `_meta` injection** (`shared.go`, `injectRequestMeta`).
For`>= 2026-06-30` sessions every outgoing request gets the SEP-2575
triple (`protocolVersion`, `clientInfo`, `clientCapabilities`).
- **Server-side fix**: `ServerSession.handle` no longer pre-populates
`state.InitializeParams` from a `server/discover` request's `_meta`, so
a subsequent fallback `initialize` is not rejected as a duplicate.
### Fallback rules
Client falls back to the legacy `initialize` handshake when discover
returns:
- `MethodNotFound` (-32601),
- `UnsupportedProtocolVersionError` (-32004),
- an HTTP `Bad Request` (substring-matched on the error message, to
interop
  with pre-2026-06-30 servers).

Fixes #966
This commit is contained in:
Guglielmo Colombo 2026-06-02 14:17:01 +02:00 • committed by GitHub
commit c60a318d22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1071,6 +1071,29 @@ type ListPromptsParams struct {
Cursor string `json:"cursor,omitempty"`
}
type DiscoverParams struct {
Meta `json:"_meta,omitempty"`
}
func (x *DiscoverParams) isParams() {}
func (x *DiscoverParams) isNil() bool { return x == nil }
func (x *DiscoverParams) GetProgressToken() any { return getProgressToken(x) }
func (x *DiscoverParams) SetProgressToken(t any) { setProgressToken(x, t) }
type DiscoverResult struct {
Meta `json:"_meta,omitempty"`
// The versions of the Model Context Protocol that the server supports.
SupportedVersions []string `json:"supportedVersions"`
// The server's capabilities.
Capabilities *ServerCapabilities `json:"capabilities"`
// Information about the server implementation.
ServerInfo *Implementation `json:"serverInfo"`
// Instructions describing how to use the server and its features.
Instructions string `json:"instructions,omitempty"`
}
func (*DiscoverResult) isResult() {}
func (x *ListPromptsParams) isParams() {}
func (x *ListPromptsParams) isNil() bool { return x == nil }
func (x *ListPromptsParams) GetProgressToken() any { return getProgressToken(x) }
@ -2041,6 +2064,7 @@ const (
methodCallTool = "tools/call"
notificationCancelled = "notifications/cancelled"
methodComplete = "completion/complete"
methodDiscover = "server/discover"
methodCreateMessage = "sampling/createMessage"
methodElicit = "elicitation/create"
notificationElicitationComplete = "notifications/elicitation/complete"