Skip to content

Handle 202 Accepted response in HTTP client#323

Draft
atesgoral wants to merge 2 commits intomodelcontextprotocol:mainfrom
atesgoral:ag/client-202-accepted
Draft

Handle 202 Accepted response in HTTP client#323
atesgoral wants to merge 2 commits intomodelcontextprotocol:mainfrom
atesgoral:ag/client-202-accepted

Conversation

@atesgoral
Copy link
Copy Markdown
Contributor

Summary

Second slice of #321 (Streamable HTTP client support), stacked on #322. Until #322 merges, this PR's diff will include the SSE parsing changes; after #322 merges, the diff will reduce to just the 202 branch + test.

The Streamable HTTP spec allows a server to respond 202 Accepted when it has received the request but will deliver the response later via an SSE stream. The client currently errors on 202 because the response has no parseable Content-Type. Return { "accepted" => true } so callers can proceed rather than hard-fail on a valid server response.

Actually picking up the deferred response requires listening on an SSE stream (GET-for-SSE), which is a TODO in the main PR and out of scope here. This change is just the graceful-no-hard-error part.

Changes

  • lib/mcp/client/http.rb: add elsif response.status == 202 branch to parse_response_body returning { "accepted" => true }
  • test/mcp/client/http_test.rb: test for 202 response with empty body

Test plan

  • rake test passes (738 runs, 1848 assertions)
  • rake rubocop no new offenses on changed files
  • New test covers 202 response with empty body

Stack

🤖 Generated with Claude Code

atesgoral and others added 2 commits April 18, 2026 18:19
The Streamable HTTP spec allows servers to respond with either
`application/json` or `text/event-stream`. The client previously
rejected the latter. Add SSE parsing via the optional
`event_stream_parser` gem (users add it to their Gemfile when their
server uses SSE), dispatch on the response Content-Type, and scan the
event stream for the first JSON-RPC response message.

No other Streamable HTTP features (202 handling, session IDs,
`connect`, DELETE termination) are included here; those will land in
follow-up PRs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The Streamable HTTP spec allows a server to respond 202 Accepted when
it has received the request but will deliver the response later via an
SSE stream. The client previously errored on 202 because the response
has no parseable Content-Type. Return `{ "accepted" => true }` so the
caller can decide how to proceed.

Actually picking up the deferred response requires listening on an SSE
stream (GET-for-SSE), which is not yet implemented. This PR only
prevents the hard error on a valid server response.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@atesgoral atesgoral marked this pull request as draft April 18, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant