fix(client): preserve custom Accept headers in StreamableHTTPClientTransport (#1655)

Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
This commit is contained in:
Niels Kaspers 2026-04-02 15:52:53 +03:00 • committed by GitHub
commit 1eb31236e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -237,7 +237,9 @@ export class StreamableHTTPClientTransport implements Transport {
// Try to open an initial SSE stream with GET to listen for server messages
// This is optional according to the spec - server may not support it
const headers = await this._commonHeaders();
headers.set('Accept', 'text/event-stream');
const userAccept = headers.get('accept');
const types = [...(userAccept?.split(',').map(s => s.trim().toLowerCase()) ?? []), 'text/event-stream'];
headers.set('accept', [...new Set(types)].join(', '));
// Include Last-Event-ID header for resumable streams if provided
if (resumptionToken) {
@ -538,7 +540,9 @@ export class StreamableHTTPClientTransport implements Transport {
const headers = await this._commonHeaders();
headers.set('content-type', 'application/json');
headers.set('accept', 'application/json, text/event-stream');
const userAccept = headers.get('accept');
const types = [...(userAccept?.split(',').map(s => s.trim().toLowerCase()) ?? []), 'application/json', 'text/event-stream'];
headers.set('accept', [...new Set(types)].join(', '));
const init = {
...this._requestInit,