Skip to content

Commit c71c55b

Browse files
committed
Allow previously initialized sessionId
1 parent 0d54517 commit c71c55b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/server/streamableHttp.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export interface EventStore {
3232
* Configuration options for StreamableHTTPServerTransport
3333
*/
3434
export interface StreamableHTTPServerTransportOptions {
35+
/**
36+
* For any pre-existing sessions that we need new transport for
37+
* If provided then the tranport will be considered _initialized
38+
*/
39+
sessionId?: string;
40+
3541
/**
3642
* Function that generates a session ID for the transport.
3743
* The session ID SHOULD be globally unique and cryptographically secure (e.g., a securely generated UUID, a JWT, or a cryptographic hash)
@@ -158,6 +164,10 @@ export class StreamableHTTPServerTransport implements Transport {
158164
this._allowedHosts = options.allowedHosts;
159165
this._allowedOrigins = options.allowedOrigins;
160166
this._enableDnsRebindingProtection = options.enableDnsRebindingProtection ?? false;
167+
if (options.sessionId) {
168+
this.sessionId = options.sessionId;
169+
this._initialized = true; // Assume initialized if session ID is provided
170+
}
161171
}
162172

163173
/**
@@ -459,7 +469,7 @@ export class StreamableHTTPServerTransport implements Transport {
459469

460470
// If we have a session ID and an onsessioninitialized handler, call it immediately
461471
// This is needed in cases where the server needs to keep track of multiple sessions
462-
if (this.sessionId && this._onsessioninitialized) {
472+
if (this.sessionId&& this._onsessioninitialized) {
463473
await Promise.resolve(this._onsessioninitialized(this.sessionId));
464474
}
465475

0 commit comments

Comments
 (0)