Client (oauth/bounded_body.rb)

ruby-sdk · lib/mcp/client/oauth/bounded_body.rb · ruby · Apache-2.0
auth, Auth / Identity

Enforces byte limits on OAuth response bodies to prevent memory issues during streaming.

# Source: https://github.com/modelcontextprotocol/ruby-sdk | License: Apache-2.0
# Provided via justclaw.it.com; keep this notice with the code.
# frozen_string_literal: true

module MCP
  class Client
    module OAuth
      # Bounds an OAuth response body while it arrives, rather than after it has been buffered.
      # Discovery documents, registration responses, and token responses are all small by definition,
      # so a body that keeps growing is never something worth holding in memory. Matches the 4 MiB cap of
      # `MCP::Client::HTTP::MAX_MESSAGE_BYTES` and `MCP::Client::Stdio::MAX_LINE_BYTES`.
      class BoundedBody
        MAX_RESPONSE_BYTES = 4 * 1024 * 1024

        # Raised while the body is read. Each caller translates it into its own error type,
        # so this never re

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key