Overview
A client-side connection to an agent. This class provides the client’s view of an ACP connection, allowing clients (such as code editors) to communicate with agents. It implements theAgent interface to provide methods for initializing sessions, sending prompts, and managing the agent lifecycle.
See protocol docs: Client
Constructor
(agent: Agent) => Client
required
A function that creates a Client handler to process incoming agent requests
Stream
required
The bidirectional message stream for communication. Typically created using
ndJsonStream for stdio-based connections.Methods
initialize
- Negotiate the protocol version to use
- Exchange capability information between client and agent
- Determine available authentication methods
InitializeRequest
required
The initialization request parameters
InitializeResponse
The agent’s capabilities and protocol version
newSession
- Create a new session context
- Connect to any specified MCP servers
- Return a unique session ID for future requests
auth_required error if the agent requires authentication.
NewSessionRequest
required
The new session request parameters
NewSessionResponse
The new session information including session ID
loadSession
loadSession capability.
The agent should:
- Restore the session context and conversation history
- Connect to the specified MCP servers
- Stream the entire conversation history back to the client via notifications
LoadSessionRequest
required
The load session request parameters
LoadSessionResponse
An empty object on success
unstable_forkSession
session.fork capability.
ForkSessionRequest
required
The fork session request parameters
ForkSessionResponse
The forked session information
unstable_listSessions
listSessions capability.
Returns a list of sessions with metadata like session ID, working directory, title, and last update time. Supports filtering by working directory and cursor-based pagination.
ListSessionsRequest
required
The list sessions request parameters
ListSessionsResponse
The list of sessions with metadata
unstable_resumeSession
session.resume capability.
The agent should resume the session context, allowing the conversation to continue without replaying the message history (unlike session/load).
ResumeSessionRequest
required
The resume session request parameters
ResumeSessionResponse
The resumed session information
setSessionMode
availableModes during session creation or loading. Agents may also change modes autonomously and notify the client via current_mode_update notifications.
This method can be called at any time during a session, whether the Agent is idle or actively generating a turn.
SetSessionModeRequest
required
The set session mode request parameters
SetSessionModeResponse
An empty object on success
unstable_setSessionModel
SetSessionModelRequest
required
The set session model request parameters
SetSessionModelResponse
An empty object on success
setSessionConfigOption
SetSessionConfigOptionRequest
required
The set config option request parameters
SetSessionConfigOptionResponse
The full set of configuration options and their current values
authenticate
newSession without receiving an auth_required error.
AuthenticateRequest
required
The authentication request parameters
AuthenticateResponse
An empty object on success
prompt
- Receives user messages with optional context (files, images, etc.)
- Processes the prompt using language models
- Reports language model content and tool calls to the Clients
- Requests permission to run tools
- Executes any requested tool calls
- Returns when the turn is complete with a stop reason
PromptRequest
required
The prompt request parameters
PromptResponse
The prompt response with stop reason
cancel
- Stop all language model requests as soon as possible
- Abort all tool call invocations in progress
- Send any pending
session/updatenotifications - Respond to the original
session/promptrequest withStopReason::Cancelled
CancelNotification
required
The cancellation notification parameters
Promise<void>
A promise that resolves when the notification has been sent
extMethod
string
required
The extension method name
Record<string, unknown>
required
The extension method parameters
Record<string, unknown>
The extension method response
extNotification
string
required
The extension notification name
Record<string, unknown>
required
The extension notification parameters
Promise<void>
A promise that resolves when the notification has been sent
Properties
signal
- Listen for connection closure:
connection.signal.addEventListener('abort', () => {...}) - Check connection status synchronously:
if (connection.signal.aborted) {...} - Pass to other APIs (fetch, setTimeout) for automatic cancellation