Follow HTTP redirects in transparent proxy#4454
Open
gkatz2 wants to merge 1 commit intostacklok:mainfrom
Open
Conversation
MCP clients expect JSON-RPC responses and cannot handle HTTP redirects. When a remote server returns a 3xx redirect, the proxy now follows it transparently instead of passing the redirect response to the client. Fixes stacklok#4453 Signed-off-by: Greg Katz <gkatz@indeed.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4454 +/- ##
==========================================
+ Coverage 69.57% 69.61% +0.04%
==========================================
Files 489 489
Lines 50193 50228 +35
==========================================
+ Hits 34920 34965 +45
+ Misses 12590 12575 -15
- Partials 2683 2688 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
forwardmethod before returning the response to the client.isRedirectStatushelper that handles 301, 302, 307, and 308. The HTTP method and body are preserved across redirects viareq.Clone(). AmaxRedirectslimit of 10 prevents infinite loops.Fixes #4453
Type of change
Test plan
task test)task test-e2e)task lint-fix)Tested with a local HTTP server returning 308 redirects to a running MCP server (design-system-mcp). Verified:
initializecall succeeds through the redirectDoes this introduce a user-facing change?
Remote MCP servers behind HTTP redirects now work. Previously, the proxy passed redirect responses to the client, causing silent failures. No configuration needed — redirect following is automatic.
Special notes for reviewers
forwardrather thanRoundTripso that session tracking, 401 handling, and DELETE cleanup inRoundTriponly see the final response after all redirects are resolved.isRedirectStatusbecause it explicitly requires changing the method to GET, which would break JSON-RPC.Generated with Claude Code