ExMCP.ACP.Client.Handler behaviour (ex_mcp v0.10.0)
View SourceBehaviour for handling ACP session events and agent requests.
Implement this behaviour to customize how your application responds to streaming session updates, permission requests, and file access requests from ACP agents.
See ExMCP.ACP.Client.DefaultHandler for a reference implementation.
Summary
Callbacks
Called when the agent requests to read a file.
Called when the agent requests to write a file.
Called when the agent requests permission to use a tool.
Called for each session/update notification from the agent.
Called when the agent requests a terminal operation.
Called when the handler is initialized.
Called when the handler is being terminated.
Types
@type state() :: any()
Callbacks
@callback handle_file_read( session_id :: String.t(), path :: String.t(), opts :: map(), state() ) :: {:ok, content :: String.t(), state()} | {:error, reason :: String.t(), state()}
Called when the agent requests to read a file.
Return {:ok, content, state} with the file contents, or
{:error, reason, state} to deny access.
@callback handle_file_write( session_id :: String.t(), path :: String.t(), content :: String.t(), state() ) :: {:ok, state()} | {:error, reason :: String.t(), state()}
Called when the agent requests to write a file.
Return {:ok, state} to allow the write, or
{:error, reason, state} to deny it.
@callback handle_permission_request( session_id :: String.t(), tool_call :: map(), options :: [map()], state() ) :: {:ok, outcome :: map(), state()}
Called when the agent requests permission to use a tool.
Must return an outcome map with an "optionId" matching one of the
provided options.
@callback handle_session_update(session_id :: String.t(), update :: map(), state()) :: {:ok, state()}
Called for each session/update notification from the agent.
The update map contains a "sessionUpdate" discriminator field indicating
the update type (e.g., "agent_message_chunk", "tool_call", "plan", etc.).
@callback handle_terminal_request( method :: String.t(), params :: map(), id :: integer() | String.t(), state() ) :: {:ok, result :: map(), state()} | {:error, reason :: String.t(), state()}
Called when the agent requests a terminal operation.
The method is one of the stable terminal/* methods and params is the
raw ACP params map. Return {:ok, result, state} with the method-specific
result map, or {:error, reason, state} to deny or fail the operation.
Called when the handler is initialized.
Called when the handler is being terminated.