@@ -32,6 +32,12 @@ export interface EventStore {
32
32
* Configuration options for StreamableHTTPServerTransport
33
33
*/
34
34
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
+
35
41
/**
36
42
* Function that generates a session ID for the transport.
37
43
* 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 {
158
164
this . _allowedHosts = options . allowedHosts ;
159
165
this . _allowedOrigins = options . allowedOrigins ;
160
166
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
+ }
161
171
}
162
172
163
173
/**
@@ -459,7 +469,7 @@ export class StreamableHTTPServerTransport implements Transport {
459
469
460
470
// If we have a session ID and an onsessioninitialized handler, call it immediately
461
471
// 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 ) {
463
473
await Promise . resolve ( this . _onsessioninitialized ( this . sessionId ) ) ;
464
474
}
465
475
0 commit comments