ruby-sdk/lib/mcp/client
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Koichi ITO ced5cd1a95 Bound client-side message buffering in the HTTP transport
## Motivation and Context

`MCP::Client::HTTP` buffers server bytes with no upper bound in two places:

- SSE responses are parsed incrementally, but the parser accumulates `data:` lines until
  a blank line dispatches the event, so a server that never terminates an event grows
  the buffer indefinitely. The abort-on-response signal does not help here, since it only fires
  after a complete response event has been dispatched.
- Non-SSE (JSON) bodies accumulate in `SSEStream#buffer` chunk by chunk with no limit.

Both the POST response stream and the standalone GET listening stream are affected.
The stdio client already bounds server frames (`max_line_bytes:`, 4 MiB default)
and the server transports bound request bodies (`max_request_bytes:`, 4 MiB default);
this brings the HTTP client in line.

`MCP::Client::HTTP.new` gains `max_message_bytes:` (default 4 MiB), which caps the bytes buffered
for a single message - an SSE event or a JSON response body. External byte counting cannot tell
consumed-and-discarded bytes (comments, field names, delimiters) from consumed-and-retained ones,
so the check measures the parser's own String buffers after each chunk. An over-limit message raises
`RequestHandlerError` on the request path and stops the GET listening stream instead of reconnecting to
the same over-limit event.

## How Has This Been Tested?

New tests in `test/mcp/client/http_test.rb` cover the SSE and JSON rejection paths end-to-end,
the per-event reset (events that individually fit must not count against later ones),
the env-less `on_data` fallback, and the constructor validation. `bundle exec rake`
(tests, RuboCop, and conformance baseline) passes.

## Breaking Changes

Responses larger than 4 MiB are now rejected by default; pass a larger g`max_message_bytes:` to accept them.
2026-07-15 12:02:15 +09:00
..
oauth Fix RuboCop offenses detected with rubocop-shopify 3.0.0 2026-07-15 01:46:51 +09:00
elicitation.rb Support client-side elicitation with SEP-1034 schema defaults 2026-07-08 01:44:24 +09:00
http.rb Bound client-side message buffering in the HTTP transport 2026-07-15 12:02:15 +09:00
oauth.rb Support private_key_jwt Client Authentication for the client_credentials Grant 2026-06-28 20:59:37 +09:00
paginated_result.rb Add Opt-In ttlMs / cacheScope Cache Hints to List and Read Results per SEP-2549 2026-07-02 17:51:01 +09:00
stdio.rb Handle non-object JSON-RPC messages without raising 2026-07-11 17:06:37 +09:00
tool.rb Add Tool output_schema support with comprehensive validation 2025-09-11 11:12:27 -04:00