Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/preserve-accept-header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@modelcontextprotocol/client": patch
---

Preserve custom Accept headers instead of unconditionally overwriting them
4 changes: 3 additions & 1 deletion packages/client/src/client/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export class SSEClientTransport implements Transport {
...this._eventSourceInit,
fetch: async (url, init) => {
const headers = await this._commonHeaders();
headers.set('Accept', 'text/event-stream');
if (!headers.has('Accept')) {
headers.set('Accept', 'text/event-stream');
}
const response = await fetchImpl(url, {
...init,
headers
Expand Down
8 changes: 6 additions & 2 deletions packages/client/src/client/streamableHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,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');
if (!headers.has('Accept')) {
headers.set('Accept', 'text/event-stream');
}

// Include Last-Event-ID header for resumable streams if provided
if (resumptionToken) {
Expand Down Expand Up @@ -473,7 +475,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');
if (!headers.has('accept')) {
headers.set('accept', 'application/json, text/event-stream');
}

const init = {
...this._requestInit,
Expand Down
Loading