File tree Expand file tree Collapse file tree 1 file changed +2
-6
lines changed Expand file tree Collapse file tree 1 file changed +2
-6
lines changed Original file line number Diff line number Diff line change @@ -359,13 +359,9 @@ export class StreamableHTTPServerTransport implements Transport {
359359
360360 async send ( message : JSONRPCMessage , options ?: { relatedRequestId ?: RequestId } ) : Promise < void > {
361361 let requestId = options ?. relatedRequestId ;
362- let shouldCloseConnection = false ;
363362 if ( 'result' in message || 'error' in message ) {
364363 // If the message is a response, use the request ID from the message
365364 requestId = message . id ;
366- // This is a response to the original request, we can close the stream
367- // after sending all related responses
368- shouldCloseConnection = true ;
369365 }
370366 if ( requestId === undefined ) {
371367 throw new Error ( "No request ID provided for the message" ) ;
@@ -380,8 +376,8 @@ export class StreamableHTTPServerTransport implements Transport {
380376 sseResponse . write (
381377 `event: message\ndata: ${ JSON . stringify ( message ) } \n\n` ,
382378 ) ;
383-
384- if ( shouldCloseConnection ) {
379+ // After all JSON-RPC responses have been sent, the server SHOULD close the SSE stream.
380+ if ( 'result' in message || 'error' in message ) {
385381 this . _sseResponseMapping . delete ( requestId ) ;
386382 // Only close the connection if it's not needed by other requests
387383 const canCloseConnection = ! [ ...this . _sseResponseMapping . entries ( ) ] . some ( ( [ id , res ] ) => res === sseResponse && id !== requestId ) ;
You can’t perform that action at this time.
0 commit comments