Skip to content

Commit ad4b2f9

Browse files
bhosmer-antDe Wildt van Reenenmattzcareyfelixweinberger
authored
Include requestInit options in GET SSE stream request (#1592)
Co-authored-by: De Wildt van Reenen <dewildt@labs.epiuse.com> Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com> Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
1 parent 4a7cdf4 commit ad4b2f9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

packages/client/src/client/streamableHttp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export class StreamableHTTPClientTransport implements Transport {
222222
}
223223

224224
const response = await (this._fetch ?? fetch)(this._url, {
225+
...this._requestInit,
225226
method: 'GET',
226227
headers,
227228
signal: this._abortController?.signal

packages/client/test/client/streamableHttp.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,34 @@ describe('StreamableHTTPClientTransport', () => {
425425
expect(headers.get('last-event-id')).toBe('test-event-id');
426426
});
427427

428+
it('should include requestInit options (credentials, mode, etc.) in GET SSE request', async () => {
429+
// Regression test for #895: POST and DELETE requests spread _requestInit but the
430+
// GET SSE request did not, so non-header options like credentials were dropped.
431+
vi.clearAllMocks();
432+
433+
transport = new StreamableHTTPClientTransport(new URL('http://localhost:1234/mcp'), {
434+
requestInit: { credentials: 'include', mode: 'cors' }
435+
});
436+
437+
const fetchSpy = globalThis.fetch as Mock;
438+
fetchSpy.mockReset();
439+
fetchSpy.mockResolvedValue({
440+
ok: true,
441+
status: 200,
442+
headers: new Headers({ 'content-type': 'text/event-stream' }),
443+
body: new ReadableStream()
444+
});
445+
446+
await transport.start();
447+
await (transport as unknown as { _startOrAuthSse: (opts: StartSSEOptions) => Promise<void> })._startOrAuthSse({});
448+
449+
expect(fetchSpy).toHaveBeenCalled();
450+
const init = fetchSpy.mock.calls[0]![1];
451+
expect(init.method).toBe('GET');
452+
expect(init.credentials).toBe('include');
453+
expect(init.mode).toBe('cors');
454+
});
455+
428456
it('should throw error when invalid content-type is received', async () => {
429457
// Clear any previous state from other tests
430458
vi.clearAllMocks();

0 commit comments

Comments
 (0)