Skip to content

Commit 0b7f219

Browse files
committed
fix(client): guard 404 session clear by request session header
1 parent 26f11a3 commit 0b7f219

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/client/src/client/streamableHttp.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export class StreamableHTTPClientTransport implements Transport {
237237
// Try to open an initial SSE stream with GET to listen for server messages
238238
// This is optional according to the spec - server may not support it
239239
const headers = await this._commonHeaders();
240+
const sentWithSession = headers.has('mcp-session-id');
240241
headers.set('Accept', 'text/event-stream');
241242

242243
// Include Last-Event-ID header for resumable streams if provided
@@ -252,7 +253,7 @@ export class StreamableHTTPClientTransport implements Transport {
252253
});
253254

254255
if (!response.ok) {
255-
if (response.status === 404 && this._sessionId !== undefined) {
256+
if (response.status === 404 && sentWithSession) {
256257
this._sessionId = undefined;
257258
}
258259

@@ -541,6 +542,7 @@ export class StreamableHTTPClientTransport implements Transport {
541542
}
542543

543544
const headers = await this._commonHeaders();
545+
const sentWithSession = headers.has('mcp-session-id');
544546
headers.set('content-type', 'application/json');
545547
headers.set('accept', 'application/json, text/event-stream');
546548

@@ -561,7 +563,7 @@ export class StreamableHTTPClientTransport implements Transport {
561563
}
562564

563565
if (!response.ok) {
564-
if (response.status === 404 && this._sessionId !== undefined) {
566+
if (response.status === 404 && sentWithSession) {
565567
this._sessionId = undefined;
566568
}
567569

0 commit comments

Comments
 (0)