ExMCP.ACP.Agent.Handler behaviour (ex_mcp v0.10.0)
View SourceBehaviour for native Elixir ACP agents.
Implement this behaviour and run it with ExMCP.ACP.Agent. Prompt callbacks
may either reply immediately or return {:noreply, state} and finish the
prompt later with ExMCP.ACP.Agent.finish_prompt/3 after streaming updates.
Summary
Callbacks
Optionally authenticate a client.
Optionally handle session/cancel.
Optionally close a session.
Optionally customize the initialize response.
Optionally list resumable sessions.
Optionally load an existing session and replay history.
Optionally log out a client.
Called for session/new.
Called for session/prompt.
Optionally resume an existing session without replaying history.
Optionally update a session config option.
Optionally switch a session mode.
Called when the handler starts.
Called when the handler runner terminates.
Types
@type callback_result() :: {:reply, callback_reply(), state()} | {:ok, callback_reply(), state()} | {:noreply, state()} | {:error, any(), state()}
@type context() :: %{ :agent => GenServer.server(), :request_id => integer() | String.t(), optional(:prompt_id) => integer() | String.t(), optional(:session_id) => String.t(), optional(:client_info) => map() | nil, optional(:client_capabilities) => map() | nil, optional(:protocol_version) => pos_integer() }
@type state() :: any()
Callbacks
@callback handle_authenticate(params :: map(), context(), state()) :: callback_result()
Optionally authenticate a client.
@callback handle_cancel(session_id :: String.t(), context(), state()) :: callback_result()
Optionally handle session/cancel.
If this callback is not implemented, the runtime immediately completes the
active prompt with "cancelled".
@callback handle_close_session(session_id :: String.t(), context(), state()) :: callback_result()
Optionally close a session.
@callback handle_initialize(params :: map(), context(), state()) :: callback_result()
Optionally customize the initialize response.
@callback handle_list_sessions(params :: map(), context(), state()) :: callback_result()
Optionally list resumable sessions.
@callback handle_load_session(params :: map(), context(), state()) :: callback_result()
Optionally load an existing session and replay history.
@callback handle_logout(context(), state()) :: callback_result()
Optionally log out a client.
@callback handle_new_session(params :: map(), context(), state()) :: callback_result()
Called for session/new.
Return either a session ID string or a full response map containing
"sessionId".
@callback handle_prompt( session_id :: String.t(), prompt :: [map()], context(), state() ) :: callback_result()
Called for session/prompt.
The prompt_id in the context is the ID to pass to
ExMCP.ACP.Agent.finish_prompt/3 when returning {:noreply, state}.
@callback handle_resume_session(params :: map(), context(), state()) :: callback_result()
Optionally resume an existing session without replaying history.
@callback handle_set_config_option( session_id :: String.t(), config_id :: String.t(), value :: any(), context(), state() ) :: callback_result()
Optionally update a session config option.
@callback handle_set_mode( session_id :: String.t(), mode_id :: String.t(), context(), state() ) :: callback_result()
Optionally switch a session mode.
Called when the handler starts.
Called when the handler runner terminates.