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<String, Object?>>? subscriptionNotifications, Duration keepAliveInterval = const Duration(seconds: 15), int maxRequestBodyBytes = 4 * 1024 * 1024, Set<String>? allowedOrigins}) → Future<void>
Handles one Streamable HTTP POST request by validating its headers and _meta envelope, dispatching the decoded message to a fresh server created by serverFactory via handleRequestScopedMessage, and writing the HTTP response.
sseMessageStream(Stream<List<int>> bytes) → Stream<Map<String, Object?>>
Decodes the message events of a Streamable HTTP SSE response bytes.
streamableHttpClientChannel(Uri uri, {required ProtocolVersion protocolVersion, required ClientCapabilities clientCapabilities, Implementation? clientInfo, Map<String, String>? headers}) → StreamChannel<Map<String, Object?>>
Creates a StreamChannel that POSTs each JSON-RPC message to uri.