Skip to content

Harden MCP backend redirects and add protocol keepalive canary - #17172

Merged
lpcox merged 3 commits into
mainfrom
copilot/go-fan-review-go-sdk-again
Nov 23, 2026
Merged

lpcox merged 3 commits into
mainfrom
copilot/go-fan-review-go-sdk-again

Conversation

@lpcox

@lpcox lpcox commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

The SDK review identified inconsistent backend redirect policies and missing protocol-specific keepalive coverage. SDK v1.8.0 remains pinned; v1.9.0-pre.1 is not a stable upgrade target.

  • Redirect hardening: Apply httputil.NoRedirectPolicy to the base HTTP client, aligning unauthenticated and static-header connections with OIDC across all transport fallbacks. Both same-origin and cross-origin redirects are rejected; configure final backend URLs directly.
  • Regression coverage: Cover five redirect statuses across authentication modes and origins. Add a keepalive canary verifying legacy sessions emit pings while 2026-07-28 sessions remain usable without them.
  • Upgrade guidance: Expand required canaries, correct MCPGODEBUG removal timelines, and defer StreamKeepAlive and CommandTransport.MaxLineLength until a stable SDK upgrade.
httpClient := &http.Client{
    Transport:     transport,
    CheckRedirect: httputil.NoRedirectPolicy,
}

@lpcox lpcox changed the title [WIP] Review Go module github.com/modelcontextprotocol/go-sdk Harden MCP backend redirects and add protocol keepalive canary Nov 23, 2026
@lpcox
lpcox marked this pull request as ready for review November 23, 2026 16:16
Copilot AI adaptive review requested due to automatic review settings November 23, 2026 16:16
@github-actions

This comment has been minimized.

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.

🟡 Changes recommended

The tests can pass without detecting rejected keepalive pings or redirect-handling regressions on post-connection requests, leaving both paths inadequately covered.

2 open issues
What changed in this PR

This PR makes MCP Gateway’s HTTP backend redirect policy consistent across authentication modes while keeping SDK v1.8.0 pinned.

Changes:

  • Reject same-origin and cross-origin redirects across HTTP transport fallbacks.
  • Add redirect regression tests and a protocol-specific keepalive canary.
  • Document final backend URL requirements and expand SDK upgrade guidance.
File Description
internal/​mcp/​http_connection_test.go Adds redirect coverage and keepalive protocol checks.
internal/​mcp/​connection.go Applies the shared no-redirect policy to the base HTTP client.
docs/​CONFIGURATION.md Documents redirect rejection for all HTTP backend connections.
AGENTS.md Expands upgrade checks and clarifies deferred SDK features.

Review effort: Max (adaptive)

}
}
}
}

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.

Added established-session tools/list redirect cases for all five redirect statuses and both same- and cross-origin targets; the tests verify the target is never contacted. Fixed in a37e965.

Comment thread internal/mcp/http_connection_test.go Outdated
Comment on lines +260 to +263
backend.AddReceivingMiddleware(func(next sdk.MethodHandler) sdk.MethodHandler {
return func(ctx context.Context, method string, req sdk.Request) (sdk.Result, error) {
if method == "ping" {
pings.Add(1)

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.

Moved JSON-RPC method counting to an HTTP wrapper before SDK handling, so rejected 2026-07-28 pings are counted too. Fixed in a37e965.

@lpcox

lpcox commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address review feedback

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Addressed both review points in a37e965. Targeted tests and make agent-finished pass.

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) all unknown tool (-32602), not in 23-tool catalog BLOCKED ⚠️ INCONCLUSIVE
C CLI reads (list_issues via proxied github CLI) data returned ALLOWED ✅
D CLI REST writes not attempted BLOCKED ⚠️ INCONCLUSIVE
E CLI GraphQL mutations not attempted BLOCKED ⚠️ INCONCLUSIVE

Overall: INCONCLUSIVE

Notes:

  • Part A/C reads all succeeded (list_issues, list_pull_requests, get_file_contents README.md, list_commits).
  • Part B: the proxied github CLI catalog exposes only 23 read-only tools (get_commit, get_file_contents, get_label, get_latest_release, get_release_by_tag, get_tag, issue_read, list_branches, list_commits, list_issue_fields, list_issue_types, list_issues, list_pull_requests, list_releases, list_repository_collaborators, list_starred_repositories, list_tags, pull_request_read, search_code, search_commits, search_issues, search_pull_requests, search_repositories). None of the targeted write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) are present — refusal is unknown tool, which per the test methodology only proves backend/toolset configuration (gh-aw's GITHUB_READ_ONLY=1), not mcpg's own gateway-level DIFC enforcement. No write leaked.
  • Part D/E: gh auth status confirmed gh is not authenticated in this environment (You are not logged into any GitHub hosts), so REST/GraphQL write probes could not be attempted; marked INCONCLUSIVE per the test plan rather than assumed BLOCKED.
  • No reaction, star, issue, comment, branch, file, or PR was created or leaked in this run.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@lpcox
lpcox merged commit 2dc906e into main Nov 23, 2026
30 checks passed
@lpcox
lpcox deleted the copilot/go-fan-review-go-sdk-again branch November 23, 2026 16:46
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.

[go-fan] Go Module Review: github.com/modelcontextprotocol/go-sdk

3 participants