refactor: go-sdk module review quick wins (5 items from #7416)#7423
Merged
Conversation
Copilot
AI
changed the title
[WIP] Review Go module modelcontextprotocol/go-sdk
refactor: go-sdk module review quick wins (5 items from #7416)
Jun 12, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR applies several “quick win” refactors from the go-sdk module review, primarily focused on MCP HTTP session-ID spec compliance, reducing duplicated logic, and tightening a couple of gateway/SDK integration seams.
Changes:
- Make plain JSON-RPC HTTP backend initialization spec-compliant by not sending a client-generated
Mcp-Session-Idoninitialize, and by relying on the server-issued session ID thereafter (tests updated accordingly). - Introduce a canonical exported
mcp.PaginateAllcursor-pagination helper and reuse it from the validator test client to reduce duplicated pagination logic. - Centralize the go-sdk streamable transport
MaxRetries: -1sentinel into a named constant and remove an unusedMCPProtocolVersionre-export.
Show a summary per file
| File | Description |
|---|---|
| test/integration/safeinputs_http_test.go | Updates integration mock + assertions to validate spec-compliant session ID behavior (server-issued ID only after initialize). |
| internal/testutil/mcptest/validator.go | Replaces local pagination loop with shared mcp.PaginateAll. |
| internal/server/unified.go | Removes unused MCPProtocolVersion re-export constant. |
| internal/server/unified_http_backend_test.go | Updates/renames test to verify initialize does not send synthetic session ID and that server-issued ID is used after. |
| internal/mcp/pagination.go | Adds exported canonical PaginateAll implementation and clarifies relationship to server-logged paginateAll. |
| internal/mcp/http_transport.go | Extracts streamable retry sentinel constant and makes initialize request spec-compliant (no session header). |
| internal/mcp/connection.go | Updates SDK transport reconnect to reuse the new streamableMaxRetries constant. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/7 changed files
- Comments generated: 2
Comment on lines
+154
to
158
| toolsListSessionID = r.Header.Get("Mcp-Session-Id") | ||
| jsonRPCResult(w, id, map[string]interface{}{ | ||
| "tools": []map[string]interface{}{ | ||
| {"name": "safe_tool", "description": "A safe tool"}, | ||
| {"name": "spec_tool", "description": "A spec-compliant tool", "inputSchema": map[string]interface{}{"type": "object"}}, | ||
| }, |
Collaborator
|
@copilot address review feedback |
Contributor
Author
Addressed in commit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the prioritized "quick win" and tech-debt items from the go-sdk module review, reducing duplication and improving spec compliance.
Changes
streamableMaxRetriesconstant — Extracts theMaxRetries: -1SDK sentinel into a named constant ininternal/mcp/http_transport.go. BothtryStreamableHTTPTransportandreconnectSDKTransportnow reference it; the explanation of SDK sentinel semantics lives in one place instead of two.Remove
server.MCPProtocolVersionre-export — Deletesconst MCPProtocolVersion = mcp.MCPProtocolVersionfrominternal/server/unified.go. No callers existed outside the package; callers should importmcp.MCPProtocolVersiondirectly.Spec-compliant
initializerequest —initializeHTTPSession()no longer generates a syntheticawmg-init-Nsession ID and sends it asMcp-Session-Idon theinitializerequest. The MCP spec assigns session IDs in the server's initialize response; sending a client-generated ID can cause backends to misinterpret the request as resuming an unknown session. The fallback that promoted the synthetic ID when the server returned none is also removed. UpdatedTestHTTPBackendInitializationWithSessionIDRequirement→TestHTTPBackendInitializationSpecCompliantand reworked theTestSafeinputsHTTPBackendintegration test around a spec-compliant mock.Unified pagination algorithm — Adds exported
mcp.PaginateAll[T](maxPages int, fetch func(string) ([]T, string, error)) ([]T, error)as the single canonical cursor-pagination implementation.ValidatorClient.paginateininternal/testutil/mcptest/validator.gonow delegates to it instead of duplicating the loop; the productionpaginateAllretains its server-specific logging and error context on top.Canary tests already present —
TestSchemaBypassCanaryandTestArgumentValidationBypassCanaryintool_registry_test.goalready cover theServer.AddToolschema-validation-bypass; no new work required.