barrel_mcp_client_transport behaviour (barrel_mcp v2.0.2)

View Source

Transport behaviour for barrel_mcp_client.

A transport owns the underlying socket/port/process and forwards inbound JSON-RPC messages to the owning client gen_statem. The client never reads the wire directly; it only sends/closes through this behaviour and consumes asynchronous messages of the form:

  • {mcp_in, TransportPid, JsonBinary} — one decoded JSON-RPC envelope arrived from the peer.
  • {mcp_closed, TransportPid, Reason} — the transport ended (peer hung up, port exited, etc.).

Transports MUST deliver one envelope per mcp_in message; framing (line splitting, SSE parsing) is the transport's responsibility.

Summary

Functions

Convenience wrapper to close any transport handle.

Convenience wrapper to send through any transport handle.

Types

t/0

-type t() :: {module(), pid()}.

Callbacks

close/1

-callback close(TransportPid :: pid()) -> ok.

connect/2

-callback connect(Owner :: pid(), Opts :: map()) -> {ok, pid()} | {error, term()}.

send/2

-callback send(TransportPid :: pid(), JsonBinary :: iodata()) -> ok | {error, term()}.

Functions

close(_)

-spec close(t()) -> ok.

Convenience wrapper to close any transport handle.

send(_, Body)

-spec send(t(), iodata()) -> ok | {error, term()}.

Convenience wrapper to send through any transport handle.