go-sdk icon indicating copy to clipboard operation
go-sdk copied to clipboard

Streamable HTTP: client sets Mcp-Name raw and does not Base64-encode a non-header-safe name

Open arpankernel opened this issue 2 months ago • 1 comments

Describe the bug

The Streamable HTTP client sets the Mcp-Name header from the raw name without Base64-wrapping a value that is not header-safe. The 2026-07-28 transport spec requires the client to encode such a value with the =?base64?...?= sentinel, the same rule it applies to Mcp-Param-*.

mcp/streamable_headers.go, setStandardHeaders (main line 210):

if name, ok := extractName(msg.Method, msg.Params); ok {
    header.Set(nameHeader, name)
}

The value is set directly, unlike the Mcp-Param-* path, which runs each value through encodeHeaderValue (line ~250) and Base64-wraps it when requiresBase64Encoding is true.

Transport page, "Value encoding":

The same encoding rule applies to the Mcp-Name header value. Tool and prompt names are only SHOULD-constrained to header-safe characters, so a name (or resource URI) outside the safe set is carried as: Mcp-Name: =?base64?{Base64EncodedValue}?=

Impact

A tool name or resource URI containing non-ASCII, control, or whitespace characters is sent as a raw header value. Depending on the HTTP stack it is either mangled or produces an invalid header, and a spec-compliant server that expects the sentinel encoding will not match it.

Suggested fix

Run the Mcp-Name value through encodeHeaderValue (or the same requiresBase64Encoding plus Base64 wrap) before setting the header, mirroring Mcp-Param-*.

This is the client-side counterpart to #1234 (server-side decode), fixed in #1242.

arpankernel avatar Sep 05 '26 09:09 arpankernel

I'd like to work on this if the proposed scope matches the maintainers' intent.

For negotiated protocol versions >= 2026-07-28, I propose encoding unsafe Mcp-Name values in Streamable HTTP client requests using the existing encodeHeaderValue helper. Safe ASCII values and behavior for older protocol versions would remain unchanged. I would add coverage for Unicode, leading/trailing whitespace, control characters, and sentinel-shaped literals.

I used AI assistance to inspect the relevant code and specification and to help draft this proposal. I have reviewed the analysis and will personally verify the implementation and tests.

Would this scope be welcome?

remote-controlled-man avatar Sep 06 '26 08:09 remote-controlled-man