barrel_mcp_client_http (barrel_mcp v2.0.2)

View Source

Streamable HTTP transport for barrel_mcp_client.

Implements MCP's Streamable HTTP transport (2025-03-26 onward) on the client side:

  • POST every request with Accept: application/json, text/event-stream. The server may answer with a single JSON envelope or with an SSE stream that interleaves server-initiated requests/notifications until the matching response arrives.
  • GET opens a long-lived SSE channel for unsolicited server-to-client traffic. Optional: a server may return 405, in which case server messages only arrive on POST streams.
  • DELETE on close, with the captured Mcp-Session-Id.
  • MCP-Protocol-Version header echoed on every request after the initialize response has been processed by the client.
  • 401 with WWW-Authenticate triggers the configured auth refresh; the original request is retried once.

Each parsed SSE event's data: payload is forwarded to the owning client as {mcp_in, self(), Json}. The owner sees the same shape as it does from the stdio transport.

Summary

Functions

Open the long-lived GET SSE for unsolicited server messages. Idempotent: a second call while the stream is open is a no-op.

Set the negotiated protocol version. Once set, every outgoing request includes the MCP-Protocol-Version header.

Capture the Mcp-Session-Id returned on the initialize POST so subsequent requests can echo it.

Functions

close(Pid)

code_change(OldVsn, State, Extra)

connect(Owner, Opts)

handle_call(Msg, From, State)

handle_cast(Msg, State)

handle_info(Msg, State)

init(_)

open_event_stream(Pid)

Open the long-lived GET SSE for unsolicited server messages. Idempotent: a second call while the stream is open is a no-op.

send(Pid, Body)

set_protocol_version(Pid, Version)

Set the negotiated protocol version. Once set, every outgoing request includes the MCP-Protocol-Version header.

set_session_id(Pid, SessionId)

Capture the Mcp-Session-Id returned on the initialize POST so subsequent requests can echo it.

terminate(Reason, State)