mcp: add Headers and MaxResponseBytes to StreamableClientTransport#926
Open
mcp: add Headers and MaxResponseBytes to StreamableClientTransport#926
Conversation
The header merge loop indexed req.Header by raw map key, so a non-canonical key like "content-type" would miss the canonical entry written by req.Header.Set and be sent as a duplicate. Canonicalize before lookup, and add tests for Headers and MaxResponseBytes.
dbb02b7 to
f612d1a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two configuration options to
StreamableClientTransport:Headers http.Header— additional HTTP headers to send with every request to the MCP endpoint (useful for API keys, tracing IDs, tenant identifiers). Transport-managed headers (Content-Type,Accept,Authorization,Mcp-Protocol-Version,Mcp-Session-Id) take precedence; user-supplied keys are canonicalized before the precedence check so non-canonical spellings cannot produce duplicate headers.MaxResponseBytes int64— caps POST response body size viahttp.MaxBytesReaderto protect clients from unbounded payloads. Zero means no limit; does not apply to the standalone SSE stream.Test plan
TestStreamableClientHeaders— custom headers are forwarded on POST/GET/DELETE; non-canonicalcontent-typedoes not override the transport-set valueTestStreamableClientMaxResponseBytes— tool call succeeds under a large limit and fails when the response exceeds the limitgo test ./mcp/passesgo vet ./mcp/clean