Urchin.Transport.StreamableHTTP (Urchin v0.2.0)

Copy Markdown View Source

A Plug implementing the MCP Streamable HTTP transport (revision 2025-11-25).

Mount it at a single endpoint path serving POST, GET and DELETE:

forward "/mcp", to: Urchin.Transport.StreamableHTTP, init_opts: [server: MyServer]

or run it standalone via Urchin.start_link/2 / Urchin.Endpoint.

Options

  • :server (required) - a module implementing Urchin.Server
  • :init_arg - argument passed to Urchin.Server.init/1 once per session (default nil)
  • :allowed_origins - :all, a list of allowed Origin values, or nil to allow missing origins plus localhost (default nil)
  • :require_session - reject post-initialize requests without a session id (default true)
  • :enable_get - offer the GET SSE stream (default true)
  • :allow_delete - allow client session termination via DELETE (default true)
  • :min_log_level - default minimum log level for new sessions (default "info")
  • :request_timeout - per-request handler timeout in ms (default 60_000)
  • :validate_protocol_version - validate the MCP-Protocol-Version header (default true)
  • :auth - an Urchin.Auth (or keyword options) to require OAuth 2.1 bearer tokens on every request; nil (default) serves MCP unauthenticated. The metadata discovery endpoint is served by Urchin.Endpoint/Urchin.Auth.Metadata, not this plug.

The plug reads the raw request body itself, so mount it before any JSON body parser.