class ActionController::MCPServer::Transport

Overview

implements the Streamable HTTP transport, statelessly. Each POST is handled on its own, so the requests of a client can be served by any instance of the application.

2026-07-28 requests carry their protocol version and client capabilities in _meta, earlier versions start with initialize and no session is created

Defined in:

action-controller/mcp/transport.cr

Constant Summary

META_CAPABILITIES = "io.modelcontextprotocol/clientCapabilities"
META_SERVER_INFO = "io.modelcontextprotocol/serverInfo"
META_SUBSCRIPTION = "io.modelcontextprotocol/subscriptionId"
META_VERSION = "io.modelcontextprotocol/protocolVersion"
METHOD_HEADER = "Mcp-Method"
NAME_HEADER = "Mcp-Name"
NAMED_METHODS = {"tools/call" => "name", "prompts/get" => "name", "resources/read" => "uri"}

methods that name a tool, prompt or resource in the Mcp-Name header

RESOURCE_METADATA_PATH = "/.well-known/oauth-protected-resource"
VERSION_HEADER = "MCP-Protocol-Version"

Constructors

Instance Method Summary

Constructor Detail

def self.new(route_handler : Router::RouteHandler, path : String = "/mcp", endpoint : Bool = false, composition : Composition = Composition.default) #

endpoint: true serves the controller endpoint mounted at #path


[View source]

Instance Method Detail

def auth_cache : AuthCache #

[View source]
def bound : Array(String) #

the path params bound from the URL, for controller endpoints


[View source]
def close_subscriptions : Nil #

completes every open subscriptions/listen stream, i.e. when shutting down. Clients listen again, to another instance


[View source]
def method_not_allowed(context : HTTP::Server::Context) : HTTP::Server::Context #

there are no event streams or sessions, so GET and DELETE aren't supported


[View source]
def path : String #

the path the transport is mounted at, a template for controller endpoints


[View source]

client to server messages


[View source]
def protocol : Protocol #

[View source]
def resource_metadata(context : HTTP::Server::Context) : HTTP::Server::Context #

OAuth 2.0 protected resource metadata, see MCPServer.resource_metadata


[View source]