Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/streamable_http_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def call(env)
curl -i http://localhost:9393 -H "Mcp-Session-Id: YOUR_SESSION_ID" \\
--json '{"jsonrpc":"2.0","method":"tools/call","id":3,"params":{"name":"notification_tool","arguments":{"message":"Hello SSE!", "delay": 2}}}'

Note: When an SSE stream is active, tool responses will appear in the SSE stream and the POST request will return {"accepted": true}
Note: When an SSE stream is active, tool responses will appear in the SSE stream and the POST request will return 202 Accepted with no body.

Press Ctrl+C to stop the server
MESSAGE
Expand Down
4 changes: 4 additions & 0 deletions lib/mcp/client/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def require_event_stream_parser!
end

def parse_response_body(response, method, params)
# 202 Accepted is the server's ACK for a JSON-RPC notification or response; no body is expected.
# https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#sending-messages-to-the-server
return if response.status == 202

content_type = response.headers["Content-Type"]

if content_type&.include?("text/event-stream")
Expand Down
15 changes: 15 additions & 0 deletions test/mcp/client/http_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,21 @@ def test_send_request_parses_sse_error_response
assert_equal("Invalid request", response.dig("error", "message"))
end

def test_send_request_returns_nil_for_202_accepted_response
request = {
jsonrpc: "2.0",
method: "notifications/initialized",
}

stub_request(:post, url)
.with(body: request.to_json)
.to_return(status: 202, body: "")

response = client.send_request(request: request)

assert_nil(response)
end

def test_send_request_raises_error_for_sse_without_response
request = {
jsonrpc: "2.0",
Expand Down