Skip to content

refactor: go-sdk module review quick wins (5 items from #7416)#7423

Merged
lpcox merged 4 commits into
mainfrom
copilot/go-fan-review-go-sdk
Jun 12, 2026
Merged

refactor: go-sdk module review quick wins (5 items from #7416)#7423
lpcox merged 4 commits into
mainfrom
copilot/go-fan-review-go-sdk

Conversation

Copilot AI commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Implements the prioritized "quick win" and tech-debt items from the go-sdk module review, reducing duplication and improving spec compliance.

Changes

  • streamableMaxRetries constant — Extracts the MaxRetries: -1 SDK sentinel into a named constant in internal/mcp/http_transport.go. Both tryStreamableHTTPTransport and reconnectSDKTransport now reference it; the explanation of SDK sentinel semantics lives in one place instead of two.

  • Remove server.MCPProtocolVersion re-export — Deletes const MCPProtocolVersion = mcp.MCPProtocolVersion from internal/server/unified.go. No callers existed outside the package; callers should import mcp.MCPProtocolVersion directly.

  • Spec-compliant initialize requestinitializeHTTPSession() no longer generates a synthetic awmg-init-N session ID and sends it as Mcp-Session-Id on the initialize request. 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. Updated TestHTTPBackendInitializationWithSessionIDRequirementTestHTTPBackendInitializationSpecCompliant and reworked the TestSafeinputsHTTPBackend integration 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.paginate in internal/testutil/mcptest/validator.go now delegates to it instead of duplicating the loop; the production paginateAll retains its server-specific logging and error context on top.

  • Canary tests already presentTestSchemaBypassCanary and TestArgumentValidationBypassCanary in tool_registry_test.go already cover the Server.AddTool schema-validation-bypass; no new work required.

GitHub Advanced Security started work on behalf of lpcox June 12, 2026 13:50 View session
GitHub Advanced Security finished work on behalf of lpcox June 12, 2026 13:51
GitHub Advanced Security started work on behalf of lpcox June 12, 2026 14:03 View session
GitHub Advanced Security finished work on behalf of lpcox June 12, 2026 14:04
GitHub Advanced Security started work on behalf of lpcox June 12, 2026 14:05 View session
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
Copilot finished work on behalf of lpcox June 12, 2026 14:05
Copilot AI requested a review from lpcox June 12, 2026 14:05
GitHub Advanced Security finished work on behalf of lpcox June 12, 2026 14:06
@lpcox lpcox marked this pull request as ready for review June 12, 2026 15:12
Copilot AI review requested due to automatic review settings June 12, 2026 15:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-Id on initialize, and by relying on the server-issued session ID thereafter (tests updated accordingly).
  • Introduce a canonical exported mcp.PaginateAll cursor-pagination helper and reuse it from the validator test client to reduce duplicated pagination logic.
  • Centralize the go-sdk streamable transport MaxRetries: -1 sentinel into a named constant and remove an unused MCPProtocolVersion re-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 thread internal/mcp/http_transport.go Outdated
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"}},
},
@lpcox

lpcox commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address review feedback

Addressed in commit 7e0209d.

  • initializeHTTPSession() now uses c.ctx for the initialize HTTP request so cancellation propagates.
  • TestHTTPBackendInitializationSpecCompliant now returns JSON-RPC -32601 for unknown methods to avoid empty-body 200 responses.

GitHub Advanced Security started work on behalf of lpcox June 12, 2026 15:30 View session
Copilot finished work on behalf of lpcox June 12, 2026 15:30
GitHub Advanced Security finished work on behalf of lpcox June 12, 2026 15:32
@lpcox lpcox merged commit ac065da into main Jun 12, 2026
27 checks passed
@lpcox lpcox deleted the copilot/go-fan-review-go-sdk branch June 12, 2026 15:32
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.

3 participants