StreamableHttpClientTransport

class StreamableHttpClientTransport(client: HttpClient, url: String, reconnectionOptions: ReconnectionOptions = ReconnectionOptions(), requestBuilder: HttpRequestBuilder.() -> Unit = {}) : AbstractClientTransport(source)

Client transport implementing the MCP Streamable HTTP transport specification.

Sends messages via HTTP POST and receives messages via HTTP GET with Server-Sent Events. Supports automatic SSE reconnection with exponential backoff, stream resumption via the Last-Event-ID header, and explicit session termination.

Parameters

client

Ktor HTTP client used for all requests

url

MCP endpoint URL

reconnectionOptions

reconnection backoff and retry-limit settings for the SSE stream

requestBuilder

builder applied to every outgoing HTTP request, e.g. for adding auth headers

Constructors

Link copied to clipboard
constructor(client: HttpClient, url: String, reconnectionOptions: ReconnectionOptions = ReconnectionOptions(), requestBuilder: HttpRequestBuilder.() -> Unit = {})
constructor(client: HttpClient, url: String, reconnectionTime: Duration?, requestBuilder: HttpRequestBuilder.() -> Unit = {})

Properties

Link copied to clipboard

MCP protocol version negotiated with the server, or null before connection.

Link copied to clipboard

Session identifier assigned by the server after initialization, or null before connection.

Functions

Link copied to clipboard
open suspend override fun close()
Link copied to clipboard
open override fun onClose(block: () -> Unit)
Link copied to clipboard
open override fun onError(block: (Throwable) -> Unit)
Link copied to clipboard
open override fun onMessage(block: suspend (JSONRPCMessage) -> Unit)
Link copied to clipboard
suspend fun send(message: JSONRPCMessage, resumptionToken: String?, onResumptionToken: (String) -> Unit? = null)

Sends one or more messages with optional resumption support. This is the main send method that matches the TypeScript implementation.

open suspend override fun send(message: JSONRPCMessage, options: TransportSendOptions?)
Link copied to clipboard
open suspend override fun start()
Link copied to clipboard
suspend fun terminateSession()

Terminates the current session by sending a DELETE request to the server.