@@ -853,6 +853,47 @@ class StreamableHTTPTransportTest < ActiveSupport::TestCase
853853 assert_nil ( body )
854854 end
855855
856+ test "send_response_to_stream returns 202 when message is sent to stream" do
857+ # Create and initialize a session
858+ init_request = create_rack_request (
859+ "POST" ,
860+ "/" ,
861+ { "CONTENT_TYPE" => "application/json" } ,
862+ { jsonrpc : "2.0" , method : "initialize" , id : "123" } . to_json ,
863+ )
864+ init_response = @transport . handle_request ( init_request )
865+ session_id = init_response [ 1 ] [ "Mcp-Session-Id" ]
866+
867+ # Connect with SSE
868+ io = StringIO . new
869+ get_request = create_rack_request (
870+ "GET" ,
871+ "/" ,
872+ { "HTTP_MCP_SESSION_ID" => session_id } ,
873+ )
874+ response = @transport . handle_request ( get_request )
875+ response [ 2 ] . call ( io ) if response [ 2 ] . is_a? ( Proc )
876+
877+ # Give the stream time to set up
878+ sleep ( 0.1 )
879+
880+ # Make a regular request that will be routed through send_response_to_stream
881+ request = create_rack_request (
882+ "POST" ,
883+ "/" ,
884+ {
885+ "CONTENT_TYPE" => "application/json" ,
886+ "HTTP_MCP_SESSION_ID" => session_id ,
887+ } ,
888+ { jsonrpc : "2.0" , method : "ping" , id : "456" } . to_json ,
889+ )
890+
891+ response = @transport . handle_request ( request )
892+ assert_equal 202 , response [ 0 ]
893+ assert_empty response [ 1 ]
894+ assert_empty response [ 2 ]
895+ end
896+
856897 test "handle post request with a standard error" do
857898 request = create_rack_request (
858899 "POST" ,
0 commit comments