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:
parent
d54751a8ee
commit
c60a318d22
1 changed files with 1010 additions and 96 deletions
|
|
@ -525,6 +525,28 @@ func TestMultiRoundTrip_ReadResource_ManualRetry(t *testing.T) {
|
|||
|
||||
func mustConnect(t *testing.T, s *Server, clientOpts *ClientOptions) *ClientSession {
|
||||
t.Helper()
|
||||
|
||||
// The mrtr tests require negotiating the 2026-06-30 protocol version.
|
||||
// Server.discover is currently a stub that returns ErrMethodNotFound, which
|
||||
// would cause Client.Connect to fall back to the legacy initialize handshake
|
||||
// and downgrade the negotiated version. Install a receiving middleware that
|
||||
// answers server/discover with a DiscoverResult advertising 2026-06-30 so
|
||||
// the client can negotiate the new protocol via the discover path.
|
||||
//
|
||||
// TODO: Remove this once the server has a proper discover implementation.
|
||||
s.AddReceivingMiddleware(func(next MethodHandler) MethodHandler {
|
||||
return func(ctx context.Context, method string, req Request) (Result, error) {
|
||||
if method == methodDiscover {
|
||||
return &DiscoverResult{
|
||||
SupportedVersions: []string{protocolVersion20260630},
|
||||
Capabilities: &ServerCapabilities{},
|
||||
ServerInfo: testImpl,
|
||||
}, nil
|
||||
}
|
||||
return next(ctx, method, req)
|
||||
}
|
||||
})
|
||||
|
||||
st, ct := NewInMemoryTransports()
|
||||
ss, err := s.Connect(t.Context(), st, nil)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue