ExMCP.ACP.AdapterBridge (ex_mcp v0.9.0)

View Source

GenServer bridge between ACP clients and non-native CLI agents.

Owns the Port subprocess and delegates translation to a pluggable ExMCP.ACP.Adapter implementation. Uses an outbox + waiters queue for synchronized message delivery.

Modes

  • Persistent (default) — opens a Port on init, keeps it alive
  • One-shot — adapter manages subprocess per prompt (Codex pattern)

Usage

{:ok, bridge} = AdapterBridge.start_link(
  adapter: ExMCP.ACP.Adapters.Claude,
  adapter_opts: [model: "sonnet"]
)

:ok = AdapterBridge.send_message(bridge, json_rpc_string)
{:ok, response} = AdapterBridge.receive_message(bridge)

Summary

Functions

Returns a specification to start this module under a supervisor.

Close the bridge and terminate the subprocess.

Receive the next ACP message from the agent. Blocks until available.

Send a JSON-encoded ACP message to the agent.

Start the bridge linked to the caller.

Types

t()

@type t() :: GenServer.server()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(bridge)

@spec close(t()) :: :ok

Close the bridge and terminate the subprocess.

receive_message(bridge, timeout \\ 30000)

@spec receive_message(t(), timeout()) :: {:ok, String.t()} | {:error, term()}

Receive the next ACP message from the agent. Blocks until available.

send_message(bridge, json)

@spec send_message(t(), String.t()) :: :ok | {:error, term()}

Send a JSON-encoded ACP message to the agent.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Start the bridge linked to the caller.