mcp: add ModifyRequest to HTTP client transports
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
ModifyRequestfield toSSEClientTransport(called before GET and POST requests) - Add
ModifyRequestfield toStreamableClientTransport(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
@jba please check again 🙏 , it appeared to have some merge conflicts prior to merging
@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.
Should we wait for the outcome of https://github.com/golang/go/issues/75814 before merging this?
Yes, I think we're waiting clarity on the end-to-end client oauth flow, before we commit to more API. See also #591.