genkit icon indicating copy to clipboard operation
genkit copied to clipboard

[Go] `StreamableHTTPConfig.HTTPClient` is silently ignored by the Streamable HTTP transport

Open vllst-io opened this issue 2 months ago • 6 comments

Summary

StreamableHTTPConfig.HTTPClient (go/plugins/mcp/client.go) is a dead field: Genkit pins mcp-go v0.29.0, whose Streamable HTTP transport exposes no option to inject a custom http.Client, so the field is silently ignored.

The SSE transport already honors its HTTPClient field via WithHTTPClient; Streamable HTTP does not, even though it's the newer, recommended transport.

Why a custom http.Client matters

A custom client is the only way to set the transport-level behavior that a remote MCP server often requires:

  • mTLS / client certificates (TLSClientConfig.Certificates)
  • Private CA / custom trust (TLSClientConfig.RootCAs)
  • Corporate proxies (http.Transport.Proxy)
  • Connection pooling / keep-alive tuning (MaxIdleConns, MaxIdleConnsPerHost, IdleConnTimeout)
  • Dial and TLS handshake timeouts (DialContext, TLSHandshakeTimeout)
  • Custom RoundTripper (tracing, retries, rate limiting)

Reproducing the Issue

Pass a custom http.Client to the Streamable HTTP transport and observe that it is never used:

package main

import (
    "net/http"

    "github.com/firebase/genkit/go/plugins/mcp"
)

// A round tripper that records whether it is ever called. It isn't.
type recordingTransport struct{ called bool }
func (t *recordingTransport) RoundTrip(*http.Request) (*http.Response, error) {
    t.called = true
    return nil, nil
}

func main() {
    recorder := &recordingTransport{}
    customClient := &http.Client{Transport: recorder}

    _, _ = mcp.NewGenkitMCPClient(mcp.MCPClientOptions{
        Name: "my-mcp-server",
        StreamableHTTP: &mcp.StreamableHTTPConfig{
            BaseURL:    "https://mcp.example.com",
            HTTPClient: customClient, // <-- silently ignored
        },
    })

    // recorder.called is false: the transport used its own default client.
}

Expected behavior

The provided HTTPClient should be used for all requests made by the Streamable HTTP transport, so that callers can control TLS (mTLS, private CAs), proxy, connection pooling / keep-alive, and transport-level timeouts — exactly as the SSE transport already does via WithHTTPClient.

Runtime:

  • OS: MacOS
  • Version 26.6

Go version go version go1.27.0 darwin/arm64

Edit: I tried opening a PR, but I believe there are access restrictions, so I incremented this issue with a "How to Fix" section.

How to Fix

The custom-client option already exists upstream: mcp-go added transport.WithHTTPBasicClient in v0.32.0. The fix is a dependency bump plus wiring the field. Some minor internal API compatibility changes must be made as well, which would not impact the user.

1. Bump mcp-go

In go/go.mod:

-	github.com/mark3labs/mcp-go v0.29.0
+	github.com/mark3labs/mcp-go v0.32.0

v0.32.0 is the minimal version with WithHTTPBasicClient. It declares go 1.23, so it does not force Genkit's go directive (currently 1.25.0).

2. Wire the field

In go/plugins/mcp/client.go, inside createTransport's Streamable HTTP branch (the if options.StreamableHTTP != nil { ... } block), apply the custom client before WithHTTPTimeout:

if options.StreamableHTTP != nil {
    var streamableHTTPOptions []transport.StreamableHTTPCOption
    // Apply the custom client first so a later WithHTTPTimeout sets its
    // Timeout field rather than being lost when the client is replaced.
    if options.StreamableHTTP.HTTPClient != nil {
        streamableHTTPOptions = append(streamableHTTPOptions, transport.WithHTTPBasicClient(options.StreamableHTTP.HTTPClient))
    }
    if options.StreamableHTTP.Headers != nil {
        streamableHTTPOptions = append(streamableHTTPOptions, transport.WithHTTPHeaders(options.StreamableHTTP.Headers))
    }
    if options.StreamableHTTP.Timeout > 0 {
        streamableHTTPOptions = append(streamableHTTPOptions, transport.WithHTTPTimeout(options.StreamableHTTP.Timeout))
    }
    // ...
}

The ordering matters: WithHTTPTimeout mutates the Timeout field of whichever client is currently installed, so it must run after WithHTTPBasicClient. The purpose of this is to not impact the current Genkit interface.

3. Migrate the request literals (API change)

mcp-go v0.32.0 renamed the anonymous Params structs to named types, so the request construction in prompts.go, tools.go, and resources.go must change, e.g.:

// before (v0.29.0)
req := mcp.GetPromptRequest{
    Params: struct {
        Name      string            `json:"name"`
        Arguments map[string]string `json:"arguments,omitempty"`
    }{Name: promptName, Arguments: args},
}

// after (v0.32.0)
req := mcp.GetPromptRequest{
    Params: mcp.GetPromptParams{Name: promptName, Arguments: args},
}

The full list of replacements:

File Old (anonymous) New (named)
prompts.go GetPromptRequest.Params struct mcp.GetPromptParams
prompts.go ListPromptsRequest.PaginatedRequest.Params struct mcp.PaginatedParams
tools.go ListToolsRequest.PaginatedRequest.Params struct mcp.PaginatedParams
tools.go CallToolRequest.Params struct mcp.CallToolParams
resources.go ReadResourceRequest.Params struct mcp.ReadResourceParams
resources.go ListResourcesRequest.PaginatedRequest.Params struct mcp.PaginatedParams
resources.go ListResourceTemplatesRequest.PaginatedRequest.Params struct mcp.PaginatedParams

4. Add a test

Add a unit test (e.g. client_test.go) asserting createTransport actually uses the custom client, a recording RoundTripper that the transport must hit, plus a check that the custom client's Timeout is set (proving the ordering in step 2):

customClient := &http.Client{Transport: recordingRoundTripper{...}}
c := &GenkitMCPClient{}
tr, err := c.createTransport(MCPClientOptions{
    StreamableHTTP: &StreamableHTTPConfig{
        BaseURL:    "http://example.com/mcp",
        HTTPClient: customClient,
        Timeout:    7 * time.Second,
    },
})
// assert: customClient.Timeout == 7s, and driving tr.SendRequest(...)
// hits the recordingRoundTripper.

5. Verify

cd go
go build ./...
go vet ./plugins/mcp/...
go test ./plugins/mcp/...
gofmt -l plugins/mcp

vllst-io avatar Sep 10 '26 17:09 vllst-io

I will take this issue. Please assign it to me.

The problem is that StreamableHTTPConfig.HTTPClient in go/plugins/mcp/client.go is ignored. The code does not allow injecting a custom http.Client. I will first inspect the mcp-go package version being used. Then, I will add a mechanism similar to WithHTTPClient in the SSE transport to use the provided HTTPClient. I will test by passing a custom client and checking if it is used.

modelpath-dev avatar Sep 10 '26 21:09 modelpath-dev

@modelpath-dev btw, how can one become a contributor? I have deep interest in the project, for both personal and professional use and I would love to contribute.

vllst-io avatar Sep 11 '26 12:09 vllst-io

Hey @vllst-io, that's awesome to hear! You can start by checking out the contribution guidelines in the repo. It's usually a good idea to begin with small issues or bug fixes to get familiar with the codebase. Looking forward to your contributions!

modelpath-dev avatar Sep 13 '26 11:09 modelpath-dev

Hey @vllst-io, that's awesome to hear! You can start by checking out the contribution guidelines in the repo. It's usually a good idea to begin with small issues or bug fixes to get familiar with the codebase. Looking forward to your contributions!

I have read it! But when I was trying to push the fix, following the specified branch format, I got an access denied. Therefore, I don't know if there are specific steps to which I have to follow, if so, I'd be glad to hear!

Thanks, @modelpath-dev!

vllst-io avatar Sep 13 '26 15:09 vllst-io

You might need to fork the repo first, make your changes in your fork, and then submit a pull request. That's a common workflow for open-source projects. Let me know if you need any more help!

modelpath-dev avatar Sep 13 '26 16:09 modelpath-dev

You might need to fork the repo first, make your changes in your fork, and then submit a pull request. That's a common workflow for open-source projects. Let me know if you need any more help!

Sure! Thanks a lot, I'll be doing that for this! Sorry for mistaking this repo's approach to OS contribs!

vllst-io avatar Sep 14 '26 14:09 vllst-io