go-sdk icon indicating copy to clipboard operation
go-sdk copied to clipboard

mcp: add ModifyRequest to HTTP client transports

Open manuelibar opened this issue 3 months ago • 4 comments

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

manuelibar avatar Sep 30 '25 19:09 manuelibar

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

manuelibar avatar Oct 07 '25 12:10 manuelibar

@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.

findleyr avatar Oct 07 '25 13:10 findleyr

Should we wait for the outcome of https://github.com/golang/go/issues/75814 before merging this?

fgrosse avatar Oct 17 '25 07:10 fgrosse

Yes, I think we're waiting clarity on the end-to-end client oauth flow, before we commit to more API. See also #591.

findleyr avatar Oct 18 '25 14:10 findleyr