Skip to content

Commit 0abd23f

Browse files
author
De Wildt van Reenen
committed
fix: client sss start include requestInit options (#895)
1 parent 3bc2235 commit 0abd23f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/client/streamableHttp.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,30 @@ describe("StreamableHTTPClientTransport", () => {
502502
expect(global.fetch).toHaveBeenCalledTimes(2);
503503
});
504504

505+
it("should always include requestInit options for initial connection in SSE", async () => {
506+
const requestInit: RequestInit = {
507+
credentials: 'include'
508+
};
509+
510+
transport = new StreamableHTTPClientTransport(new URL("http://localhost:1234/mcp"), {
511+
requestInit: requestInit
512+
});
513+
514+
let actualReqInit: RequestInit = {};
515+
516+
((global.fetch as jest.Mock)).mockImplementation(
517+
async (_url, reqInit) => {
518+
actualReqInit = reqInit;
519+
return new Response(null, { status: 200, headers: { "content-type": "text/event-stream" } });
520+
}
521+
);
522+
523+
await transport.start();
524+
525+
await transport["_startOrAuthSse"]({});
526+
expect(actualReqInit.credentials).toBe("include");
527+
});
528+
505529
it("should always send specified custom headers (Headers class)", async () => {
506530
const requestInit = {
507531
headers: new Headers({

src/client/streamableHttp.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export class StreamableHTTPClientTransport implements Transport {
208208
}
209209

210210
const response = await (this._fetch ?? fetch)(this._url, {
211+
...this._requestInit,
211212
method: "GET",
212213
headers,
213214
signal: this._abortController?.signal,
@@ -301,7 +302,7 @@ export class StreamableHTTPClientTransport implements Transport {
301302
}
302303

303304
private _handleSseStream(
304-
stream: ReadableStream<Uint8Array> | null,
305+
stream: ReadableStream<Uint8Array> | null,
305306
options: StartSSEOptions,
306307
isReconnectable: boolean,
307308
): void {
@@ -352,8 +353,8 @@ export class StreamableHTTPClientTransport implements Transport {
352353

353354
// Attempt to reconnect if the stream disconnects unexpectedly and we aren't closing
354355
if (
355-
isReconnectable &&
356-
this._abortController &&
356+
isReconnectable &&
357+
this._abortController &&
357358
!this._abortController.signal.aborted
358359
) {
359360
// Use the exponential backoff reconnection strategy

0 commit comments

Comments
 (0)