Skip to content

Conversation

Zizo-Vi
Copy link
Contributor

@Zizo-Vi Zizo-Vi commented Aug 27, 2025

This PR updates the HttpClientStreamableHttpTransport to automatically handle HTTP redirects, such as 307 Temporary Redirect.

Resolve: #433

Motivation and Context

Currently, the HttpClientStreamableHttpTransport does not handle HTTP redirects. The underlying java.net.http.HttpClient defaults to a redirect policy of NEVER. Consequently, when an MCP server returns a 307 status code, the client fails to follow the redirect and throws an error. This change configures the HTTP client to automatically follow redirects, making the transport more robust and compliant with standard HTTP behavior.

How Has This Been Tested?

This was tested by pointing the client to a server endpoint that issues a 307 Temporary Redirect. Before this change, the client would fail. With this change, the client successfully follows the redirect and establishes a connection with the new endpoint.

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

The fix is applied by setting the followRedirects policy to HttpClient.Redirect.NORMAL in the HttpClient.Builder. This enables the client to handle common redirect status codes (301, 302, 307, 308) automatically.

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.

Streamablehttp throws exception 'Client failed to initialize by explicit API call'
1 participant