# `Snodo.Transport.StreamableHTTP`
[🔗](https://github.com/joshrotenberg/snodo/blob/v0.5.0/lib/snodo/transport/streamable_http.ex#L1)

Protocol-driven adapter for stateless Streamable HTTP requests.

The default dialect is 2026-07-28. Explicitly enabled initialize-era dialects
share admission and execution. They run without HTTP sessions unless the
caller passes a `Snodo.Session.Manager` as the `:sessions` option of
`prepare/3`; see "Initialize-era sessions" below.

`prepare/3` performs HTTP and mirrored-header admission without invoking an
application handler. `execute/3` runs one prepared message through the shared
synchronous server core. This split lets HTTP servers admit a request before
submitting only application work to `Snodo.Server.Executor`.

Complete JSON responses and long-lived SSE descriptors are deliberately
transport-server agnostic so Plug, Bandit, Cowboy, or a custom listener can
translate them without changing protocol code.

## Initialize-era sessions

With `sessions: manager` (a running `Snodo.Session.Manager`, or the
configuration `Snodo.Session.Manager.config/1` returns) and `auth:` (the request's trusted auth value, or `nil`), requests
of the initialize-era dialects belong to a `Snodo.Session`:

  * An `initialize` request starts a session. `execute/3` returns its ID in
    the `Mcp-Session-Id` response header when initialization succeeds, and
    ends the session otherwise. At the manager's `:max_sessions` the request
    gets 503. An `initialize` sent as a notification starts none.
  * Every later request, notification, and response must carry that header.
    A missing header is 400. An unknown or expired ID, or a session bound to
    a different principal, is 404 with JSON-RPC code -32001, and the client
    initializes again. An `MCP-Protocol-Version` that differs from the
    session's version is 400.
  * A JSON-RPC response object is routed to the server request waiting for
    it and answered with 202. One without the header is accepted with 202,
    as without sessions, unless its `MCP-Protocol-Version` names an
    initialize-era version.
  * `DELETE` ends the session and is answered with 200.
  * `GET` with `Accept: text/event-stream` returns `{:standalone, session}`.
    The caller opens the session's standalone stream with
    `Snodo.Session.attach_stream/2` (409 if it already has one).
  * During `execute/3`, a handler's input requests are sent as
    server-to-client requests through the progress sink's owner, which
    receives `{:mcp_stream_message, sink_reference, message}` as a
    `GenServer.call/3` and replies `:ok` once the message is written on
    the request's event stream.

2026-07-28 requests are never part of a session. A `GET` or `DELETE` whose
`MCP-Protocol-Version` names a version without sessions gets 405, as
without sessions.

# `prepare_result`

```elixir
@type prepare_result() ::
  {:ok, Snodo.Transport.StreamableHTTP.Prepared.t()}
  | {:response, Snodo.Transport.StreamableHTTP.Response.t()}
  | {:standalone, Snodo.Session.t()}
```

# `execute`

```elixir
@spec execute(
  Snodo.Server.Runtime.t(),
  Snodo.Transport.StreamableHTTP.Prepared.t(),
  term() | nil
) ::
  Snodo.Transport.StreamableHTTP.Response.t()
  | Snodo.Transport.StreamableHTTP.StreamResponse.t()
```

Executes one admitted request; transports may supply a cancellation token.

# `handle`

```elixir
@spec handle(
  Snodo.Server.Runtime.t(),
  Snodo.Transport.StreamableHTTP.Request.t(),
  keyword()
) ::
  Snodo.Transport.StreamableHTTP.Response.t()
  | Snodo.Transport.StreamableHTTP.StreamResponse.t()
```

Runs admission and execution synchronously for embedding in another HTTP stack.

A standalone `GET` stream cannot be served this way and is answered with 405.

# `prepare`

```elixir
@spec prepare(
  Snodo.Server.Runtime.t(),
  Snodo.Transport.StreamableHTTP.Request.t(),
  keyword()
) ::
  prepare_result()
```

Admits and decodes one HTTP request without executing its MCP handler.

Options are `:allowed_origin_hosts`, `:allowed_hosts`, and, for
initialize-era sessions, `:sessions` and `:auth` (see the module
documentation). `{:standalone, session}` is returned only with `:sessions`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
