streamable_http library
The Streamable HTTP transport described by the 2026-07-28 revision of the Model Context Protocol specification, https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http.
Every POST carries a single JSON-RPC request or notification along with
its own client context. There is no session state between requests. A
request is answered on an SSE response stream if its handler emits related
notifications, and with a JSON body otherwise. List and resource change
notifications reach onNotification, and a successful
subscriptions/listen request also keeps its SSE response open for the
changes it accepted.
A client posts with streamableHttpClientChannel. JSON replies use
jsonDecode and SSE replies use sseMessageStream.
Functions
-
handleStreamableHttpRequest(
HttpRequest request, MCPServerFactory serverFactory, {void onNotification(Map< String, Object?> notification)?, Stream<Map< ? subscriptionNotifications, Duration keepAliveInterval = const Duration(seconds: 15), int maxRequestBodyBytes = 4 * 1024 * 1024, Set<String, Object?> >String> ? allowedOrigins}) → Future<void> -
Handles one Streamable HTTP POST
requestby validating its headers and_metaenvelope, dispatching the decoded message to a fresh server created byserverFactoryvia handleRequestScopedMessage, and writing the HTTP response. -
sseMessageStream(
Stream< List< bytes) → Stream<int> >Map< String, Object?> > -
Decodes the
messageevents of a Streamable HTTP SSE responsebytes. -
streamableHttpClientChannel(
Uri uri, {required ProtocolVersion protocolVersion, required ClientCapabilities clientCapabilities, Implementation? clientInfo, Map< String, String> ? headers}) → StreamChannel<Map< String, Object?> > -
Creates a
StreamChannelthat POSTs each JSON-RPC message touri.