mcpStatelessStreamableHttp

fun Application.mcpStatelessStreamableHttp(path: String = "/mcp", enableDnsRebindingProtection: Boolean = false, allowedHosts: List<String>? = null, allowedOrigins: List<String>? = null, eventStore: EventStore? = null, block: RoutingContext.() -> Server)(source)

Configures the Ktor Application to handle Model Context Protocol (MCP) over stateless Streamable HTTP Transport

Sets up an HTTP POST endpoint at path. GET and DELETE requests return 405 Method Not Allowed. Simple request/response pairs are returned as JSON (not SSE streams).

Automatically installs ContentNegotiation with McpJson and SSE.

Parameters

path

The URL path where the server listens for incoming JSON-RPC requests. Defaults to "/mcp".

enableDnsRebindingProtection

Determines whether DNS rebinding protection is enabled. Defaults to false.

allowedHosts

A list of allowed hostnames. If null, host filtering is disabled.

allowedOrigins

A list of allowed origins for CORS. If null, origin filtering is disabled.

eventStore

An optional EventStore implementation to provide resumability and event replay support.

block

factory block with access to the RoutingContext (for reading request headers) that creates and returns the Server to handle the connection.