Skip to content

Commit 3f4576d

Browse files
atesgoralclaude
andcommitted
Handle 202 Accepted response when server delivers via SSE stream
When an SSE stream is active, the server responds with 202 Accepted (no Content-Type, empty body) to POST requests, delivering the actual response via the SSE stream. Previously this raised an unsupported Content-Type error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0c3b676 commit 3f4576d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/mcp/client/http.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def parse_response_body(response, method, params)
134134
parse_sse_response(response.body, method, params)
135135
elsif content_type&.include?("application/json")
136136
response.body
137+
elsif response.status == 202
138+
# Server accepted the request and will deliver the response via SSE stream
139+
{ "accepted" => true }
137140
else
138141
raise RequestHandlerError.new(
139142
"Unsupported Content-Type: #{content_type.inspect}. Expected application/json or text/event-stream.",

test/mcp/client/http_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ def test_post_raises_error_for_sse_without_response
265265
assert_equal(:parse_error, error.error_type)
266266
end
267267

268+
def test_post_returns_accepted_for_202_with_no_content_type
269+
stub_request(:post, url)
270+
.to_return(status: 202, body: "")
271+
272+
response = transport.post(body: {})
273+
274+
assert_equal({ "accepted" => true }, response.body)
275+
end
276+
268277
def test_delete_sends_request_with_headers
269278
stub_request(:delete, url)
270279
.with(

0 commit comments

Comments
 (0)