Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

manuelibar
Copy link
Contributor

Problem

Users need to modify HTTP requests (add headers, authentication, etc.) but currently must implement custom RoundTripper implementations which requires cloning requests and is more complex than necessary.

Solution

Add ModifyRequest func(*http.Request) field to both SSEClientTransport and StreamableClientTransport. This callback is invoked before each outgoing HTTP request, providing a simple way to modify requests without needing custom RoundTripper implementations.

Changes

  • Add ModifyRequest field to SSEClientTransport (called before GET and POST requests)
  • Add ModifyRequest field to StreamableClientTransport (called before GET, POST, and DELETE requests)
  • Add comprehensive tests covering all request types
  • Add example usage in documentation

Impact

  • Simpler API for common request modification use cases
  • No breaking changes (new optional field)
  • Backward compatible (nil ModifyRequest is safe)

Fixes #533

Add ModifyRequest func(*http.Request) field to both SSEClientTransport
and StreamableClientTransport. This callback is invoked before each
outgoing HTTP request, allowing users to add headers, authentication,
or other request modifications.

This provides a simpler alternative to implementing custom RoundTrippers
for common use cases like adding authorization headers or request IDs.

Fixes modelcontextprotocol#533
jba
jba previously approved these changes Oct 2, 2025
# Conflicts:
#	mcp/streamable_test.go
@manuelibar
Copy link
Contributor Author

manuelibar commented Oct 7, 2025

@jba please check again 🙏 , it appeared to have some merge conflicts prior to merging

@findleyr
Copy link
Contributor

findleyr commented Oct 7, 2025

@manuelibar I think we'll discuss this in the proposal meeting tomorrow and likely approve the proposal (unless anyone objects), so we may as well wait to merge until then.

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.

Proposal: add ModifyRequest func(*http.Request) to HTTP client transports

3 participants