livery_mcp (livery v0.13.0)
View SourceMCP Streamable HTTP handler.
Bridges Livery to the barrel_mcp protocol core. handler/1
returns a Livery handler that serves the MCP Streamable HTTP
transport (POST requests, GET SSE streams, DELETE session
termination, OPTIONS preflight) by delegating to
barrel_mcp_http_engine:handle/6, the transport-neutral MCP
engine. Livery owns the wire (H1/H2/H3, router, middleware); the
engine owns the protocol.
Mount it like any handler, typically at /mcp:
Router = livery_router:compile([
{<<"POST">>, <<"/mcp">>, livery_mcp:handler()},
{<<"GET">>, <<"/mcp">>, livery_mcp:handler()},
{<<"DELETE">>, <<"/mcp">>, livery_mcp:handler()}
]),
livery:start_service(#{https => #{...}, router => Router}).Register tools, resources, and prompts through barrel_mcp's own
API (barrel_mcp:reg_tool/4 and friends); they live in the shared
barrel_mcp_registry. The barrel_mcp application must be running;
it is an optional application of Livery, so list it in your own
applications.
Options (all optional):
auth: abarrel_mcpauth provider config (default: no auth). A provider that refuses its options makeshandler/1raise{auth_provider, Module, Reason}rather than fail per request.barrel_mcp_auth_bearerrequires anaudience, and acceptsaudience => anyonly with averifierfunsession_enabled: useMcp-Session-Idsessions (defaulttrue)allowed_origins:any | [binary()](defaultany)allow_missing_origin: accept requests with noOrigin(defaulttrue)sse_buffer_size: server-stream buffer (default256)sse_keepalive_ms: how often a quiet SSE stream emits a comment, which is also what notices a peer that left without closing (default: thebarrel_mcpsse_keepalive_msapp env, else15000)max_body_bytes: request body cap, answered413past it (default 16 MiB)body_timeout_ms: how long to wait for each body chunk, answered408past it (default60000)resource_metadata: OAuth protected-resource-metadata map
The handler delivers the response directly through the adapter and
returns the taken_over sentinel, so do not stack response-mutating
middleware after it.
Summary
Functions
MCP handler with default options.
MCP handler built from Opts (see the module docs).
A router for the MCP endpoint at /mcp, ready to mount with
livery_router:nest/3 or merge/2.
router/0 with MCP handler options.
Types
-type opts() :: #{auth => map(), session_enabled => boolean(), allowed_origins => any | [binary()], allow_missing_origin => boolean(), sse_buffer_size => pos_integer(), sse_keepalive_ms => pos_integer(), max_body_bytes => pos_integer(), body_timeout_ms => pos_integer(), resource_metadata => undefined | map()}.
Functions
-spec handler() -> fun((livery_req:req()) -> livery_resp:resp()).
MCP handler with default options.
-spec handler(opts()) -> fun((livery_req:req()) -> livery_resp:resp()).
MCP handler built from Opts (see the module docs).
-spec router() -> livery_router:router().
A router for the MCP endpoint at /mcp, ready to mount with
livery_router:nest/3 or merge/2.
-spec router(opts()) -> livery_router:router().
router/0 with MCP handler options.