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<
126126
127127 override async connect ( transport : Transport , options ?: RequestOptions ) : Promise < void > {
128128 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+ }
130134 try {
131135 const result = await this . request (
132136 {
Original file line number Diff line number Diff line change @@ -331,11 +331,10 @@ export class StreamableHTTPServerTransport implements Transport {
331331 const isInitializationRequest = messages . some (
332332 msg => 'method' in msg && msg . method === 'initialize'
333333 ) ;
334- const mcpSessionId = req . headers [ "mcp-session-id" ] as string | undefined ;
335334 if ( isInitializationRequest ) {
336335 // If it's a server with session management and the session ID is already set we should reject the request
337336 // to avoid re-initialization.
338- if ( this . _initialized && this . sessionId !== undefined && mcpSessionId !== this . sessionId ) {
337+ if ( this . _initialized ) {
339338 res . writeHead ( 400 ) . end ( JSON . stringify ( {
340339 jsonrpc : "2.0" ,
341340 error : {
@@ -357,7 +356,7 @@ export class StreamableHTTPServerTransport implements Transport {
357356 } ) ) ;
358357 return ;
359358 }
360- this . sessionId = mcpSessionId ?? this . sessionIdGenerator ( ) ;
359+ this . sessionId = this . sessionIdGenerator ( ) ;
361360 this . _initialized = true ;
362361
363362 }
You can’t perform that action at this time.
0 commit comments