File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -126,7 +126,11 @@ export class Client<
126
126
127
127
override async connect ( transport : Transport , options ?: RequestOptions ) : Promise < void > {
128
128
await super . connect ( transport ) ;
129
-
129
+ // When transport sessionId is already set this means we are trying to reconnect.
130
+ // In this case we don't need to initialize again.
131
+ if ( transport . sessionId !== undefined ) {
132
+ return ;
133
+ }
130
134
try {
131
135
const result = await this . request (
132
136
{
Original file line number Diff line number Diff line change @@ -331,11 +331,10 @@ export class StreamableHTTPServerTransport implements Transport {
331
331
const isInitializationRequest = messages . some (
332
332
msg => 'method' in msg && msg . method === 'initialize'
333
333
) ;
334
- const mcpSessionId = req . headers [ "mcp-session-id" ] as string | undefined ;
335
334
if ( isInitializationRequest ) {
336
335
// If it's a server with session management and the session ID is already set we should reject the request
337
336
// to avoid re-initialization.
338
- if ( this . _initialized && this . sessionId !== undefined && mcpSessionId !== this . sessionId ) {
337
+ if ( this . _initialized ) {
339
338
res . writeHead ( 400 ) . end ( JSON . stringify ( {
340
339
jsonrpc : "2.0" ,
341
340
error : {
@@ -357,7 +356,7 @@ export class StreamableHTTPServerTransport implements Transport {
357
356
} ) ) ;
358
357
return ;
359
358
}
360
- this . sessionId = mcpSessionId ?? this . sessionIdGenerator ( ) ;
359
+ this . sessionId = this . sessionIdGenerator ( ) ;
361
360
this . _initialized = true ;
362
361
363
362
}
You can’t perform that action at this time.
0 commit comments