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>
This commit is contained in:
parent
4a7cdf4f2b
commit
ad4b2f9cac
2 changed files with 29 additions and 0 deletions
|
|
@ -222,6 +222,7 @@ export class StreamableHTTPClientTransport implements Transport {
|
|||
}
|
||||
|
||||
const response = await (this._fetch ?? fetch)(this._url, {
|
||||
...this._requestInit,
|
||||
method: 'GET',
|
||||
headers,
|
||||
signal: this._abortController?.signal
|
||||
|
|
|
|||
|
|
@ -425,6 +425,34 @@ describe('StreamableHTTPClientTransport', () => {
|
|||
expect(headers.get('last-event-id')).toBe('test-event-id');
|
||||
});
|
||||
|
||||
it('should include requestInit options (credentials, mode, etc.) in GET SSE request', async () => {
|
||||
// Regression test for #895: POST and DELETE requests spread _requestInit but the
|
||||
// GET SSE request did not, so non-header options like credentials were dropped.
|
||||
vi.clearAllMocks();
|
||||
|
||||
transport = new StreamableHTTPClientTransport(new URL('http://localhost:1234/mcp'), {
|
||||
requestInit: { credentials: 'include', mode: 'cors' }
|
||||
});
|
||||
|
||||
const fetchSpy = globalThis.fetch as Mock;
|
||||
fetchSpy.mockReset();
|
||||
fetchSpy.mockResolvedValue({
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: new Headers({ 'content-type': 'text/event-stream' }),
|
||||
body: new ReadableStream()
|
||||
});
|
||||
|
||||
await transport.start();
|
||||
await (transport as unknown as { _startOrAuthSse: (opts: StartSSEOptions) => Promise<void> })._startOrAuthSse({});
|
||||
|
||||
expect(fetchSpy).toHaveBeenCalled();
|
||||
const init = fetchSpy.mock.calls[0]![1];
|
||||
expect(init.method).toBe('GET');
|
||||
expect(init.credentials).toBe('include');
|
||||
expect(init.mode).toBe('cors');
|
||||
});
|
||||
|
||||
it('should throw error when invalid content-type is received', async () => {
|
||||
// Clear any previous state from other tests
|
||||
vi.clearAllMocks();
|
||||
|
|
|
|||
Loading…
Reference in a new issue