Skip to content

mcp: Implement support for methodDiscover on client side#975

Draft
guglielmo-san wants to merge 34 commits into
mainfrom
guglielmoc/SEP-2575_Stateless_MCP_part2
Draft

mcp: Implement support for methodDiscover on client side#975
guglielmo-san wants to merge 34 commits into
mainfrom
guglielmoc/SEP-2575_Stateless_MCP_part2

Conversation

@guglielmo-san
Copy link
Copy Markdown
Contributor

@guglielmo-san guglielmo-san commented May 26, 2026

Implements the client half of the SEP-2575 / 2026-06-30 protocol on top of
part 1 (which added per-request _meta validation on the server). 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. On success, the negotiated version is picked from
    DiscoverResult.SupportedVersions ∩ supportedProtocolVersions and stored
    in ClientSession.state.InitializeResult so existing accessors keep working.
  • Per-request _meta injection (shared.go, injectRequestMeta). For
    >= 2026-06-30 sessions every outgoing request gets the SEP-2575 triple
    (protocolVersion, clientInfo, clientCapabilities) without overwriting
    caller-set keys.
  • DiscoverParams / DiscoverResult types (protocol.go) matching the
    SEP schema, plus methodDiscover registration and the DiscoverRequest
    type alias.
  • HTTP transport: setMCPHeaders now falls back to a context-supplied
    protocol version when initializedResult is still nil (needed so the
    discover probe carries the Mcp-Protocol-Version header); the standalone
    GET SSE stream is skipped for >= 2026-06-30 (replaced in a follow-up by
    subscriptions/listen).
  • Error plumbing: transport.go wraps closed-connection errors with
    errors.Join so callers can still inspect the underlying jsonrpc2 error
    (used to distinguish UnsupportedProtocolVersionError from
    ErrServerClosing, both -32004).
  • 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 that 400 on the unknown _meta.protocolVersion).

Fixes #966

…t stateless protocol to stateless HTTP servers
…protocol version checking in server and tests
…rt headers and conditional SSE stream initialization
…ization, and correct session metadata mapping
…version propagation in client and transport layers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SEP-2575: Make MCP Stateless

1 participant