| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Updated to also apply SEP-2243's value-encoding rules to Mcp-Name. Without it, a tool name or URI containing non-ASCII characters raises UnicodeEncodeError and breaks the request, and CR/LF in a value is a header-injection vector. Now safe printable-ASCII values pass through unchanged and everything else is wrapped as =?base64?<b64>?=, matching the spec's examples. Added test_encode_mcp_header_value covering passthrough plus each base64 trigger (non-ASCII, leading/trailing whitespace, control char, sentinel collision). |
Sorry, something went wrong.
Per SEP-2243, MCP clients should send routing headers on POST requests so spec-compliant servers and intermediaries can route without parsing the JSON-RPC body. The StreamableHTTP client did not send them. Add Mcp-Method (the JSON-RPC method, for requests and notifications) and Mcp-Name (params.name for tools and prompts, else params.uri for resources) to outgoing POST headers. Mcp-Name values are encoded per the SEP-2243 value rules: safe printable-ASCII values are sent unchanged, while non-ASCII, control characters, or significant leading/trailing whitespace are wrapped as =?base64?<b64>?=. Besides matching the spec, this prevents a UnicodeEncodeError when a tool name or URI contains non-ASCII characters, and neutralizes header injection via CR/LF. Responses and errors, which have no method, send neither header. Fixes modelcontextprotocol#2715
|
Closing as superseded — the SEP-2243 header support has since landed upstream via #2950, #2974, and #2990, which together are a strict superset of this change (same base64 sentinel encoding and name/uri mapping), and test_legacy_wire now pins the 2025-negotiated behavior this PR would have conflicted with. Nothing here that main doesn't already do better. Thanks! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #2715. Per SEP-2243 (accepted — see the draft changelog), the Streamable HTTP transport requires Mcp-Method and Mcp-Name headers on POST requests so servers/intermediaries can route without parsing the JSON-RPC body. The Python client did not send them.
Changes
The encoding is not just spec-compliance — without it, a tool name/URI containing non-ASCII raises UnicodeEncodeError and breaks the request, and a value containing CR/LF is a header-injection vector. Verified both: café now sends as =?base64?Y2Fmw6k=?= and is accepted by httpx; "a\r\nEvil: 1" is base64-wrapped.
The broader x-mcp-header custom-header part of SEP-2243 is intentionally out of scope here (separate feature); this PR covers the Mcp-Method/Mcp-Name requirement from #2715.
Tests
Full tests/shared/test_streamable_http.py passes (76 tests); ruff and pyright clean.