@@ -309,35 +309,14 @@ export class StreamableHTTPHandler {
309309 // Set session ID header in response
310310 reply . header ( 'Mcp-Session-Id' , actualSessionId ) ;
311311
312- // Determine response mode
313- const wantsStreaming = acceptHeader . includes ( 'text/event-stream' ) ;
312+ // ALWAYS return JSON for initialize, even if Accept includes text/event-stream
313+ // The SSE stream is established via separate GET request
314+ reply . code ( 200 ) . send ( initResponse ) ;
314315
315- if ( wantsStreaming ) {
316- // Return SSE stream
317- reply . raw . writeHead ( 200 , {
318- 'Content-Type' : 'text/event-stream' ,
319- 'Cache-Control' : 'no-cache' ,
320- 'Connection' : 'keep-alive' ,
321- 'Mcp-Session-Id' : actualSessionId
322- } ) ;
323-
324- const eventId = this . generateEventId ( ) ;
325- reply . raw . write ( `id: ${ eventId } \nevent: message\ndata: ${ JSON . stringify ( initResponse ) } \n\n` ) ;
326-
327- this . logger . debug ( {
328- operation : 'mcp_initialize_sse_response_sent' ,
329- sessionId : actualSessionId ,
330- eventId
331- } , 'Initialize SSE response sent' ) ;
332- } else {
333- // Return standard JSON response
334- reply . code ( 200 ) . send ( initResponse ) ;
335-
336- this . logger . debug ( {
337- operation : 'mcp_initialize_json_response_sent' ,
338- sessionId : actualSessionId
339- } , 'Initialize JSON response sent' ) ;
340- }
316+ this . logger . debug ( {
317+ operation : 'mcp_initialize_json_response_sent' ,
318+ sessionId : actualSessionId
319+ } , 'Initialize JSON response sent' ) ;
341320 }
342321
343322 /**
@@ -383,6 +362,17 @@ export class StreamableHTTPHandler {
383362 // Process the message using the MCP protocol handler
384363 const response = await mcpProtocolHandler . handleMcpRequest ( message , sessionId ) ;
385364
365+ // Handle notifications (null response)
366+ if ( response === null ) {
367+ this . logger . debug ( {
368+ operation : 'mcp_notification_handled' ,
369+ sessionId,
370+ method : message . method
371+ } , 'MCP notification handled - no response sent' ) ;
372+ // Don't send anything for notifications
373+ return ;
374+ }
375+
386376 this . logger . debug ( {
387377 operation : 'mcp_streaming_response_before_send' ,
388378 sessionId,
@@ -461,6 +451,18 @@ export class StreamableHTTPHandler {
461451 // Process the message using the MCP protocol handler
462452 const response = await mcpProtocolHandler . handleMcpRequest ( message , sessionId ) ;
463453
454+ // Handle notifications (null response)
455+ if ( response === null ) {
456+ this . logger . debug ( {
457+ operation : 'mcp_notification_handled' ,
458+ sessionId,
459+ method : message . method
460+ } , 'MCP notification handled - no response sent' ) ;
461+ // Don't send anything for notifications
462+ reply . code ( 204 ) . send ( ) ; // 204 No Content
463+ return ;
464+ }
465+
464466 this . logger . debug ( {
465467 operation : 'mcp_response_before_send' ,
466468 sessionId,
0 commit comments