Skip to content

Commit 189d5fc

Browse files
authored
Merge pull request #74 from mogox/increase_streamable_coverage
Adding test for streamable errors for StreamableHTTPTransport
2 parents 13bee9f + b1fa433 commit 189d5fc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/mcp/server/transports/streamable_http_transport_test.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,41 @@ class StreamableHTTPTransportTest < ActiveSupport::TestCase
566566
assert_not @transport.instance_variable_get(:@sessions).key?(session_id)
567567
end
568568

569+
test "responds with 405 for unsupported methods" do
570+
request = create_rack_request(
571+
"PUT",
572+
"/",
573+
{},
574+
)
575+
576+
response = @transport.handle_request(request)
577+
assert_equal 405, response[0]
578+
assert_equal({ "Content-Type" => "application/json" }, response[1])
579+
580+
body = JSON.parse(response[2][0])
581+
assert_equal "Method not allowed", body["error"]
582+
end
583+
584+
test "handle post request with a standard error" do
585+
request = create_rack_request(
586+
"POST",
587+
"/",
588+
{ "CONTENT_TYPE" => "application/json" },
589+
{ jsonrpc: "2.0", method: "initialize", id: "4567" }.to_json,
590+
)
591+
592+
@transport.define_singleton_method(:extract_session_id) do |_request|
593+
raise StandardError, "Test error"
594+
end
595+
596+
response = @transport.handle_request(request)
597+
assert_equal 500, response[0]
598+
assert_equal({ "Content-Type" => "application/json" }, response[1])
599+
600+
body = JSON.parse(response[2][0])
601+
assert_equal "Internal server error", body["error"]
602+
end
603+
569604
private
570605

571606
def create_rack_request(method, path, headers, body = nil)

0 commit comments

Comments
 (0)