Skip to content

mcp: Implement server-side support for discover method (SEP-2575)#987

Merged
guglielmo-san merged 46 commits into
mainfrom
guglielmoc/SEP-2567_2575_Stateless_MCP_part3
Jun 8, 2026
Merged

mcp: Implement server-side support for discover method (SEP-2575)#987
guglielmo-san merged 46 commits into
mainfrom
guglielmoc/SEP-2567_2575_Stateless_MCP_part3

Conversation

@guglielmo-san
Copy link
Copy Markdown
Contributor

@guglielmo-san guglielmo-san commented Jun 2, 2026

Summary

Part 3 of the SEP-2575 ("Make MCP Stateless") implementation. Builds on PR #975 which landed the client-side discover/fallback flow and the per-request _meta plumbing. This PR adds the server-side counterparts:

  • server/discover handler (replaces the stub),ProtocolVersionSupporter`
  • transport hook for per-transport version filtering,
  • transport-agnostic version validation and method-removal enforcement in ServerSession.handle,
  • HTTP-level wire compliance for SEP-2575 error codes/status codes,
  • bug fix in internal/jsonrpc2,processResult with an MCPGODEBUG opt-out for backward compatibility.

…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
Resolved conflicts with these strategies:
- Took main's version for SEP-2575 client-side bits already merged via PR #975
  (the cleaner, reviewed version supersedes the part2/part3 in-progress code).
- Kept part3-unique additions:
  * Real server-side server/discover handler (replaces main's stub).
  * UnsupportedProtocolVersionData type per SEP-2575.
  * Server allows server/discover on stateful HTTP transport (stateless-only
    rejection exempts methodDiscover).
  * Rejection of methodSubscribe/methodUnsubscribe in the new protocol.
  * TestStreamableStateful_AcceptsDiscover regression test.
- Removed duplicate injectMeta in shared.go (main moved injection to per-method
  injectRequestMeta in client.go; the centralized helper was redundant).
- Removed duplicate Server.discover stub left behind by the merge.

Known failures (pre-existing test expectations, not regressions from the merge):
- TestMiddleware, ExampleLoggingTransport: written assuming Connect always
  triggers server/discover, but main's logic requires explicit opt-in via
  ClientSessionOptions{protocolVersion: protocolVersion20260630}.
- TestStreamableClientUnsupportedVersionFallback: requires a "Bad Request"
  substring fallback that part3 had but main removed. The structural fix is to
  parse the JSON-RPC error body in checkResponse and match by error.code.
@guglielmo-san guglielmo-san marked this pull request as ready for review June 4, 2026 10:21
…ate documentation for methodDiscover initialization logic
…rror handling, and enable stateless HTTP conformance server
Conflicts:
- mcp/server.go: union of the removed-in-new-protocol method list, keeping
  both branch additions (methodSubscribe, methodUnsubscribe) and main's
  addition (methodSetLevel) from PR #997.
- mcp/client_test.go: kept all five branch-side TestInMemory_E2E_Discover*
  tests and main's new TestClientConnectDiscover_UnsupportedVersionNegotiation
  from PR #989 (retry on advised supportedVersions). Conflict was textual
  (adjacent functions) not semantic.

Additional fix to make PR #989's negotiation test pass on this branch:
exempt server/discover from the dispatcher's unsupported-version gate so
that a probing client with an unsupported MCP-Protocol-Version can still
reach the discover handler and learn the server's supportedVersions via
the UnsupportedProtocolVersionError Data payload. Without this exemption,
the gate at server.go:1561 short-circuited before the handler ran, leaving
the client with no Supported list to negotiate from.
@guglielmo-san guglielmo-san merged commit dd97816 into main Jun 8, 2026
10 checks passed
@guglielmo-san guglielmo-san deleted the guglielmoc/SEP-2567_2575_Stateless_MCP_part3 branch June 8, 2026 15:52
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.

2 participants