You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 52491ff
Browse filesBrowse the repository at this point in the historyBrowse files
fix(client): make transport-managed header precedence case-insensitive; fix stale eventSourceInit note
- build _commonHeaders() on `new Headers(requestInit.headers)` and `set()` the
transport-managed values in both transports, so Authorization / mcp-session-id /
mcp-protocol-version replace a same-named caller entry whatever its spelling. The
plain-object spread kept `authorization` and `Authorization` side by side and the
Headers constructor combined them into "Bearer <stale>, Bearer <fresh>" for callers
passing a Headers instance or a lowercase key
- drop the now-unused normalizeHeaders import from both transports
- add regression tests for a Headers instance and a lowercase plain object
- rewrite the SSEClientTransportOptions.eventSourceInit note: a custom fetch is always
wrapped, so the provider token is attached and takes precedence over requestInit
- reword the changeset to describe the behavior rather than the old spread order
Copy file name to clipboardExpand all lines: .changeset/oauth-header-spread-order.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,4 +2,4 @@
2
2
'@modelcontextprotocol/client': patch
3
3
---
4
4
5
-
Fix the spread order in `StreamableHTTPClientTransport._commonHeaders()` and `SSEClientTransport._commonHeaders()` so SDK-derived common headers (including fresh OAuth tokens from `authProvider`) win over caller-supplied headers in `requestInit.headers`. Previously a caller-supplied `Authorization` placeholder (e.g. an env-var API key) was merged after the SDK-computed value, silently overriding OAuth-refreshed tokens and breaking the auth-refresh flow once the placeholder went stale. Closes #2208.
5
+
`StreamableHTTPClientTransport` and `SSEClientTransport` now give their transport-managed headers precedence over same-named entries in `requestInit.headers`: `Authorization` when `authProvider` yields a token, `mcp-protocol-version`, and (Streamable HTTP) `mcp-session-id`. Header names compare case-insensitively and every `HeadersInit` form is covered (plain object, tuple array, `Headers` instance). Previously the caller-supplied value won, so a static `Authorization` placeholder (e.g. an env-var API key) kept overriding the OAuth token even after the provider obtained one and the fallback-to-OAuth flow never completed; a `Headers` instance or lowercase key produced a combined `Bearer <stale>, Bearer <fresh>` value instead. A configured `Authorization` is still sent while the provider has no token, and other configured headers pass through unchanged. Closes #2208.
0 commit comments