@@ -6561,6 +6561,48 @@ def string
65616561 assert_equal overflow , delivery_results . count { |result | result == false }
65626562 end
65636563
6564+ test "modern POST drops a handler notification that cannot be generated and keeps the response" do
6565+ reported = [ ]
6566+ original_reporter = MCP . configuration . exception_reporter
6567+ MCP . configuration . exception_reporter = -> ( e , context ) { reported << [ e . class , context [ :error ] ] }
6568+ delivery_results = [ ]
6569+ @server . define_tool ( name : "logging_tool" ) do |server_context :|
6570+ delivery_results << server_context . notify_log_message ( data : "\xFF " . dup . force_encoding ( Encoding ::UTF_8 ) , level : "info" )
6571+ delivery_results << server_context . notify_log_message ( data : "hi" , level : "info" )
6572+ Tool ::Response . new ( [ { type : "text" , text : "done" } ] )
6573+ end
6574+
6575+ body = {
6576+ jsonrpc : "2.0" ,
6577+ method : "tools/call" ,
6578+ id : 1 ,
6579+ params : {
6580+ name : "logging_tool" ,
6581+ arguments : { } ,
6582+ _meta : {
6583+ "io.modelcontextprotocol/protocolVersion" : "2026-07-28" ,
6584+ "io.modelcontextprotocol/clientInfo" : { name : "modern_client" , version : "2.0" } ,
6585+ "io.modelcontextprotocol/clientCapabilities" : { } ,
6586+ "io.modelcontextprotocol/logLevel" : "info" ,
6587+ } ,
6588+ } ,
6589+ } . to_json
6590+
6591+ response = @transport . handle_request ( modern_rack_request ( body ) )
6592+
6593+ assert_equal 200 , response [ 0 ]
6594+ frames = response [ 2 ] [ 0 ] . split ( "\n \n " ) . reject ( &:empty? ) . map do |chunk |
6595+ JSON . parse ( chunk . sub ( /\A event: message\n data: / , "" ) )
6596+ end
6597+ assert_equal 2 , frames . size
6598+ assert_equal "hi" , frames . first . dig ( "params" , "data" )
6599+ assert_equal [ { "type" => "text" , "text" => "done" } ] , frames . last . dig ( "result" , "content" )
6600+ assert_equal [ false , true ] , delivery_results
6601+ assert_equal [ [ JSON ::GeneratorError , "Failed to generate notification" ] ] , reported
6602+ ensure
6603+ MCP . configuration . exception_reporter = original_reporter
6604+ end
6605+
65646606 test "modern POST without handler notifications keeps the single JSON exchange" do
65656607 response = @transport . handle_request ( modern_rack_request ( modern_body ( "tools/list" , { } ) ) )
65666608
0 commit comments