java.lang.Object
io.modelcontextprotocol.client.transport.FlowSseClient

public class FlowSseClient extends Object
A Server-Sent Events (SSE) client implementation using Java's Flow API for reactive stream processing. This client establishes a connection to an SSE endpoint and processes the incoming event stream, parsing SSE-formatted messages into structured events.

The client supports standard SSE event fields including:

  • event - The event type (defaults to "message" if not specified)
  • id - The event ID
  • data - The event payload data

Events are delivered to a provided FlowSseClient.SseEventHandler which can process events and handle any errors that occur during the connection.

Author:
Christian Tzolov
See Also:
  • Constructor Details

    • FlowSseClient

      public FlowSseClient(HttpClient httpClient)
      Creates a new FlowSseClient with the specified HTTP client.
      Parameters:
      httpClient - the HttpClient instance to use for SSE connections
    • FlowSseClient

      public FlowSseClient(HttpClient httpClient, HttpRequest.Builder requestBuilder)
      Creates a new FlowSseClient with the specified HTTP client and request builder.
      Parameters:
      httpClient - the HttpClient instance to use for SSE connections
      requestBuilder - the HttpRequest.Builder to use for SSE requests
  • Method Details

    • subscribe

      public void subscribe(String url, FlowSseClient.SseEventHandler eventHandler)
      Subscribes to an SSE endpoint and processes the event stream.

      This method establishes a connection to the specified URL and begins processing the SSE stream. Events are parsed and delivered to the provided event handler. The connection remains active until either an error occurs or the server closes the connection.

      Parameters:
      url - the SSE endpoint URL to connect to
      eventHandler - the handler that will receive SSE events and error notifications
      Throws:
      RuntimeException - if the connection fails with a non-200 status code