Overview
TheClientSideConnection class provides the client’s view of an ACP connection. It implements the Agent interface, giving you access to all agent methods.
Constructor
Creates a new client-side connection to an agent.(agent: Agent) => Client
required
A function that creates a Client handler to process incoming agent requests. The function receives the connection instance (implementing the Agent interface) and should return your Client implementation.
Stream
required
The bidirectional message stream for communication. Typically created using
ndJsonStream() for stdio-based connections.Example
Methods
TheClientSideConnection implements the full Agent interface:
initialize()
Establishes the connection and negotiates protocol capabilities.string
required
The protocol version to use (e.g.,
acp.PROTOCOL_VERSION).ClientCapabilities
required
Capabilities advertised by the client (file system, terminal support, etc.).
string
The negotiated protocol version.
AgentCapabilities
Capabilities supported by the agent.
AuthMethod[]
Available authentication methods.
Example
newSession()
Creates a new conversation session with the agent.string
required
The working directory for the session (absolute path).
McpServer[]
required
MCP servers the agent should connect to for this session.
string
Unique identifier for the created session.
SessionMode
The initial mode of the session.
SessionMode[]
Modes available for this session.
Example
loadSession()
Loads an existing session to resume a previous conversation.Only available if the agent advertises the
loadSession capability.string
required
The ID of the session to load.
McpServer[]
required
MCP servers to connect to for this session.
prompt()
Processes a user prompt within a session.string
required
The session ID to send the prompt to.
PromptContent[]
required
Array of content items (text, images, files, etc.).
StopReason
Why the agent stopped (e.g.,
"finished", "cancelled", "error").Example
cancel()
Cancels ongoing operations for a session.string
required
The session ID to cancel operations for.
Example
setSessionMode()
Sets the operational mode for a session.string
required
The session ID.
string
required
The mode to switch to (must be in
availableModes).authenticate()
Authenticates the client using the specified authentication method.string
required
The ID of the authentication method to use.
setSessionConfigOption()
Sets a configuration option for a session.Properties
signal
AbortSignal that aborts when the connection closes.- Listening for connection closure
- Checking connection status synchronously
- Passing to other APIs for automatic cancellation