Server-Sent Events client for the Streamable HTTP transport.
This internal module implements the SSE portion of the Streamable HTTP transport as defined in the MCP specification. It provides robust connection handling with keep-alive, reconnection, and retry logic.
Features:
- Automatic reconnection with exponential backoff
- Keep-alive/heartbeat mechanism
- Proper handling of SSE retry suggestions
- Connection health monitoring
Note: This is an internal implementation detail of the Streamable HTTP transport.
Summary
Functions
Returns a specification to start this module under a supervisor.
Starts an SSE client connected to the given URL.
Stops the SSE client gracefully.
Types
@type t() :: %ExMCP.Transport.SSEClient{ allowed_private_hosts: [String.t()], buffer: String.t(), connect_timeout: non_neg_integer(), consumer_ack_timeout: pos_integer(), dns_resolver: module() | function(), dns_timeout_ms: pos_integer(), handshake_ref: reference() | nil, handshake_timeout: non_neg_integer(), headers: [{String.t(), String.t()}], heartbeat_ref: reference() | nil, httpc_profile: atom() | nil, idle_timeout: non_neg_integer(), last_event_id: String.t() | nil, max_buffer_bytes: pos_integer(), max_response_bytes: pos_integer(), max_retry_delay: non_neg_integer(), parent: pid(), reconnect_timer: reference() | nil, ref: reference() | nil, retry_count: non_neg_integer(), retry_delay: non_neg_integer(), ssl_opts: keyword(), url: String.t() }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec start_link(keyword()) :: GenServer.on_start()
Starts an SSE client connected to the given URL.
Options:
:url- The SSE endpoint URL (required):headers- Additional HTTP headers:ssl_opts- SSL options for HTTPS connections:parent- Process to send events to (defaults to caller):initial_retry_delay- Initial reconnection delay in ms (default: 1000):max_retry_delay- Maximum reconnection delay in ms (default: 60000):connect_timeout- Connection timeout in ms (default: 30000):handshake_timeout- Maximum time to receive response headers:idle_timeout- Idle/heartbeat timeout in ms (default: 30000):max_response_bytes- Maximum non-streaming response size:max_buffer_bytes- Maximum bytes retained for an incomplete SSE frame:consumer_ack_timeout- Maximum time a downstream event consumer may stall:dns_timeout_ms- Maximum time allowed for DNS resolution:dns_resolver- Resolver module or function used before pinning the connection:allowed_private_hosts- Exact hostnames explicitly permitted to resolve privately
@spec stop(GenServer.server()) :: :ok
Stops the SSE client gracefully.