internal/mcp: provide a customizable http.Client to client transports
Allow customizing the http.Client used for HTTP MCP client transports, by adding client options structs. Change-Id: I2297acb136f8d0f7fa70d58cd244a6a81cc89751 Reviewed-on: https://go-review.googlesource.com/c/tools/+/682756 Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
4012cc3d2e
commit
e228d78d19
1 changed files with 89 additions and 14 deletions
|
|
@ -571,13 +571,26 @@ func (t *StreamableServerTransport) Close() error {
|
|||
//
|
||||
// TODO(rfindley): support retries and resumption tokens.
|
||||
type StreamableClientTransport struct {
|
||||
url string
|
||||
url string
|
||||
opts StreamableClientTransportOptions
|
||||
}
|
||||
|
||||
// StreamableClientTransportOptions provides options for the
|
||||
// [NewStreamableClientTransport] constructor.
|
||||
type StreamableClientTransportOptions struct {
|
||||
// HTTPClient is the client to use for making HTTP requests. If nil,
|
||||
// http.DefaultClient is used.
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// NewStreamableClientTransport returns a new client transport that connects to
|
||||
// the streamable HTTP server at the provided URL.
|
||||
func NewStreamableClientTransport(url string) *StreamableClientTransport {
|
||||
return &StreamableClientTransport{url: url}
|
||||
func NewStreamableClientTransport(url string, opts *StreamableClientTransportOptions) *StreamableClientTransport {
|
||||
t := &StreamableClientTransport{url: url}
|
||||
if opts != nil {
|
||||
t.opts = *opts
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// Connect implements the [Transport] interface.
|
||||
|
|
@ -589,9 +602,13 @@ func NewStreamableClientTransport(url string) *StreamableClientTransport {
|
|||
// When closed, the connection issues a DELETE request to terminate the logical
|
||||
// session.
|
||||
func (t *StreamableClientTransport) Connect(ctx context.Context) (Connection, error) {
|
||||
client := t.opts.HTTPClient
|
||||
if client == nil {
|
||||
client = http.DefaultClient
|
||||
}
|
||||
return &streamableClientConn{
|
||||
url: t.url,
|
||||
client: http.DefaultClient,
|
||||
client: client,
|
||||
incoming: make(chan []byte, 100),
|
||||
done: make(chan struct{}),
|
||||
}, nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue