Skip to content

Commit 91ecc6f

Browse files
Add SEP-1699 priming event support for POST SSE responses
Send priming event with id and empty data when retryInterval is configured. This enables clients to establish resumption capability before any actual messages are sent, allowing proper reconnection behavior.
1 parent 9ddf34d commit 91ecc6f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/server/streamableHttp.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,18 @@ export class StreamableHTTPServerTransport implements Transport {
568568
}
569569

570570
res.writeHead(200, headers);
571+
572+
// SEP-1699: Send priming event with id and empty data to establish resumption capability
573+
// This primes the client's Last-Event-ID for reconnection and sets retry interval
574+
// Only send when retryInterval is configured (enabling polling behavior)
575+
if (this._retryInterval !== undefined) {
576+
const primingEventId = this._eventStore
577+
? await this._eventStore.storeEvent(streamId, {} as JSONRPCMessage)
578+
: `priming-${Date.now()}`;
579+
580+
const primingEvent = `id: ${primingEventId}\nretry: ${this._retryInterval}\ndata: \n\n`;
581+
res.write(primingEvent);
582+
}
571583
}
572584
// Store the response for this request to send messages back through this connection
573585
// We need to track by request ID to maintain the connection

0 commit comments

Comments
 (0)