ExMCP.Transport.SSEClient (ex_mcp v0.10.0)

View Source

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

t()

@type t() :: %ExMCP.Transport.SSEClient{
  buffer: String.t(),
  connect_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_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

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

@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)
  • :idle_timeout - Idle/heartbeat timeout in ms (default: 30000)

stop(client)

@spec stop(GenServer.server()) :: :ok

Stops the SSE client gracefully.