KtorMcpTransport

class KtorMcpTransport(httpClient: HttpClient? = null) : McpTransport

McpTransport implementation on top of Ktor Client — the MCP Streamable HTTP transport. Lives in the kory-ktor module: the network layer must not leak into core.

Every JSON-RPC message is a single POST to the MCP endpoint with Accept: application/json, text/event-stream, as required by the spec; the server answers either with a JSON object or with an SSE stream, and both are surfaced through McpHttpResponse.body.

Why not reuse io.kory.ktor.KoryHttpClient: MCP servers are third-party endpoints, while a KoryHttpClient built from KoryHttpClientConfig carries defaultRequest auth headers (e.g. the provider API key) that would be forwarded to every MCP server. That's why the transport by default creates a minimal standalone client (engine discovered via discoverKoryHttpEngineFactory — Registry on Native, ServiceLoader on JVM), and accepting an explicit HttpClient is opt-in for proxies/interceptors: a shared client must not close the transport and vice versa.

Parameters

httpClient

Optional pre-configured Ktor client; null creates a standalone one. Note: close closes whichever client is used.

Constructors

Link copied to clipboard
constructor(httpClient: HttpClient? = null)

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
open suspend override fun post(request: McpHttpRequest): McpHttpResponse