barrel_mcp_client_transport behaviour (barrel_mcp v3.0.1)

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

Ask the transport to cancel one request. unsupported when it has no per-request channel; the caller then sends the notification.

Convenience wrapper to close any transport handle.

Convenience wrapper to send through any transport handle.

Types

t/0

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

Callbacks

cancel_request/2

(optional)
-callback cancel_request(TransportPid :: pid(), RequestId :: integer() | binary()) -> ok.

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

cancel_request(_, RequestId)

-spec cancel_request(t(), integer() | binary()) -> ok | unsupported.

Ask the transport to cancel one request. unsupported when it has no per-request channel; the caller then sends the notification.

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.