Skip to content

Commit 8cbb07e

Browse files
feat: add resumeStream() method for clean SSE resumption API
Addresses PR feedback by providing a dedicated method for SSE stream resumption instead of using send() with a fake notification.
1 parent 2516b88 commit 8cbb07e

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/client/streamableHttp.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,4 +620,18 @@ export class StreamableHTTPClientTransport implements Transport {
620620
get protocolVersion(): string | undefined {
621621
return this._protocolVersion;
622622
}
623+
624+
/**
625+
* Resume an SSE stream from a previous event ID.
626+
* Opens a GET SSE connection with Last-Event-ID header to replay missed events.
627+
*
628+
* @param lastEventId The event ID to resume from
629+
* @param options Optional callback to receive new resumption tokens
630+
*/
631+
async resumeStream(lastEventId: string, options?: { onresumptiontoken?: (token: string) => void }): Promise<void> {
632+
await this._startOrAuthSse({
633+
resumptionToken: lastEventId,
634+
onresumptiontoken: options?.onresumptiontoken
635+
});
636+
}
623637
}

src/integration-tests/taskResumability.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
251251
await client2.connect(transport2);
252252

253253
// Resume GET SSE stream with Last-Event-ID to replay missed events
254-
// Per spec, resumption uses GET with Last-Event-ID header, not POST
255-
// When resumptionToken is provided, send() only triggers GET reconnection and returns early
256-
// We use a notification (no id) so we don't expect a response
257-
await transport2.send(
258-
{ jsonrpc: '2.0', method: 'notifications/ping' },
259-
{ resumptionToken: lastEventId, onresumptiontoken: onLastEventIdUpdate }
260-
);
254+
// Per spec, resumption uses GET with Last-Event-ID header
255+
await transport2.resumeStream(lastEventId!, { onresumptiontoken: onLastEventIdUpdate });
261256

262257
// Wait for replayed events to arrive via SSE
263258
await new Promise(resolve => setTimeout(resolve, 100));

0 commit comments

Comments
 (0)