Skip to content

Conversation

@manuelibar
Copy link
Contributor

Description

This change decouples client transports from the concrete net/http.Client by accepting any HTTP client that implements Do(http.Request) (http.Response, error). This enables middleware (auth, tracing, retries), improves testability, and unifies behavior across streamable and SSE transports.

What changed

  • Introduce HTTPClient interface in the mcp package.
  • StreamableClientTransport: change HTTPClient field type to the interface; default to http.DefaultClient when nil.
  • SSEClientTransport: same change as streamable.

Why

  • Flexibility to inject custom HTTP clients with middleware.
  • Better testability via interface-based dependencies.
  • Consistency across transports (streamable and SSE).

Compatibility

  • Backward compatible: existing code passing http.Client continues to work (it satisfies the interface).
  • No behavior changes; defaults remain the same when HTTPClient is nil.

Testing

  • go test ./... passes locally.
  • Existing transport tests validate streamable/SSE flows.

Fixes #522

@manuelibar
Copy link
Contributor Author

@findleyr I'll close this PR given that the proposal was declined.
Thanks!

@manuelibar manuelibar closed this Sep 26, 2025
@manuelibar manuelibar deleted the fix/decouple-http-client-client-transports-issue-522 branch September 26, 2025 17:46
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.

Decouple client transports from *http.Client by accepting an interface

1 participant