Skip to content

mcp: add Headers and MaxResponseBytes to StreamableClientTransport#926

Open
pja-ant wants to merge 2 commits intomainfrom
pja/streamable-transport-headers-maxbytes
Open

mcp: add Headers and MaxResponseBytes to StreamableClientTransport#926
pja-ant wants to merge 2 commits intomainfrom
pja/streamable-transport-headers-maxbytes

Conversation

@pja-ant
Copy link
Copy Markdown

@pja-ant pja-ant commented May 1, 2026

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 via http.MaxBytesReader to 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-canonical content-type does not override the transport-set value
  • TestStreamableClientMaxResponseBytes — tool call succeeds under a large limit and fails when the response exceeds the limit
  • go test ./mcp/ passes
  • go vet ./mcp/ clean

@pja-ant pja-ant marked this pull request as ready for review May 1, 2026 15:37
pja-ant added 2 commits May 1, 2026 16:38
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.
@pja-ant pja-ant force-pushed the pja/streamable-transport-headers-maxbytes branch from dbb02b7 to f612d1a Compare May 1, 2026 15:39
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.

1 participant