Merge pull request #253 from koic/support_cors_and_accept_wildcard_for_browser_based_mcp_clients

Support CORS and Accept wildcard for browser-based MCP clients
This commit is contained in:
Koichi ITO 2026-03-15 15:31:42 +09:00 • committed by GitHub
commit 95200b5467
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -855,6 +855,21 @@ module MCP
assert_equal 200, response[0]
end
test "POST request with Accept: */* succeeds" do
request = create_rack_request_without_accept(
"POST",
"/",
{
"CONTENT_TYPE" => "application/json",
"HTTP_ACCEPT" => "*/*",
},
{ jsonrpc: "2.0", method: "initialize", id: "123" }.to_json,
)
response = @transport.handle_request(request)
assert_equal 200, response[0]
end
test "GET request without Accept header returns 406" do
init_request = create_rack_request(
"POST",
@ -928,6 +943,30 @@ module MCP
assert_equal "text/event-stream", response[1]["Content-Type"]
end
test "GET request with Accept: */* succeeds" do
init_request = create_rack_request(
"POST",
"/",
{ "CONTENT_TYPE" => "application/json" },
{ jsonrpc: "2.0", method: "initialize", id: "123" }.to_json,
)
init_response = @transport.handle_request(init_request)
session_id = init_response[1]["Mcp-Session-Id"]
request = create_rack_request_without_accept(
"GET",
"/",
{
"HTTP_MCP_SESSION_ID" => session_id,
"HTTP_ACCEPT" => "*/*",
},
)
response = @transport.handle_request(request)
assert_equal 200, response[0]
assert_equal "text/event-stream", response[1]["Content-Type"]
end
test "stateless mode allows requests without session IDs, responding with no session ID" do
stateless_transport = StreamableHTTPTransport.new(@server, stateless: true)