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 {
359
359
360
360
async send ( message : JSONRPCMessage , options ?: { relatedRequestId ?: RequestId } ) : Promise < void > {
361
361
let requestId = options ?. relatedRequestId ;
362
- let shouldCloseConnection = false ;
363
362
if ( 'result' in message || 'error' in message ) {
364
363
// If the message is a response, use the request ID from the message
365
364
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 ;
369
365
}
370
366
if ( requestId === undefined ) {
371
367
throw new Error ( "No request ID provided for the message" ) ;
@@ -380,8 +376,8 @@ export class StreamableHTTPServerTransport implements Transport {
380
376
sseResponse . write (
381
377
`event: message\ndata: ${ JSON . stringify ( message ) } \n\n` ,
382
378
) ;
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 ) {
385
381
this . _sseResponseMapping . delete ( requestId ) ;
386
382
// Only close the connection if it's not needed by other requests
387
383
const canCloseConnection = ! [ ...this . _sseResponseMapping . entries ( ) ] . some ( ( [ id , res ] ) => res === sseResponse && id !== requestId ) ;
You can’t perform that action at this time.
0 commit comments