Class ClientSideConnection
Implements
Index
Constructors
Accessors
Methods
Constructors
constructor
-
new ClientSideConnection(
toClient: (agent: Agent) => Client,
stream: Stream,
): ClientSideConnectionCreates a new client-side connection to an agent.
This establishes the communication channel between a client and agent following the ACP specification.
Parameters
- toClient: (agent: Agent) => Client
A function that creates a Client handler to process incoming agent requests
- stream: Stream
The bidirectional message stream for communication. Typically created using ndJsonStream for stdio-based connections.
See protocol docs: Communication Model
Returns ClientSideConnection
- toClient: (agent: Agent) => Client
Accessors
signal
-
get signal(): AbortSignal
AbortSignal that aborts when the connection closes.
This signal can be used to:
- 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
The connection closes when the underlying stream ends, either normally or due to an error.
Returns AbortSignal
Example
const connection = new ClientSideConnection(client, stream);
// Listen for closure
connection.signal.addEventListener('abort', () => {
console.log('Connection closed - performing cleanup');
});
// Check status
if (connection.signal.aborted) {
console.log('Connection is already closed');
}
// Pass to other APIs
fetch(url, { signal: connection.signal }); - Listen for connection closure:
closed
-
get closed(): Promise<void>
Promise that resolves when the connection closes.
The connection closes when the underlying stream ends, either normally or due to an error. Once closed, the connection cannot send or receive any more messages.
This is useful for async/await style cleanup:
Returns Promise<void>
Methods
initialize
-
Establishes the connection with a client and negotiates protocol capabilities.
This method is called once at the beginning of the connection to:
- Negotiate the protocol version to use
- Exchange capability information between client and agent
- Determine available authentication methods
The agent should respond with its supported protocol version and capabilities.
See protocol docs: Initialization
Parameters
- params: InitializeRequest
Returns Promise<InitializeResponse>
new Session
-
Creates a new conversation session with the agent.
Sessions represent independent conversation contexts with their own history and state.
The agent should:
- Create a new session context
- Connect to any specified MCP servers
- Return a unique session ID for future requests
The request may include
additionalDirectoriesto expand the session's filesystem scope beyondcwdwithout changing the base for relative paths.May return an
auth_requirederror if the agent requires authentication.See protocol docs: Session Setup
Parameters
- params: NewSessionRequest
Returns Promise<NewSessionResponse>
load Session
-
Loads an existing session to resume a previous conversation.
This method is only available if the agent advertises the
loadSessioncapability.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
The request may include
additionalDirectoriesto set the complete list of additional workspace roots for the loaded session.See protocol docs: Loading Sessions
Parameters
- params: LoadSessionRequest
Returns Promise<LoadSessionResponse>
unstable_ fork Session
-
ExperimentalUNSTABLE
This capability is not part of the spec yet, and may be removed or changed at any point.
Forks an existing session to create a new independent session.
Creates a new session based on the context of an existing one, allowing operations like generating summaries without affecting the original session's history.
The request may include
additionalDirectoriesto set the complete list of additional workspace roots for the forked session.This method is only available if the agent advertises the
session.forkcapability.Parameters
- params: ForkSessionRequest
Returns Promise<ForkSessionResponse>
list Sessions
-
Lists existing sessions from the agent.
This method is only available if the agent advertises the
listSessionscapability.Returns a list of sessions with metadata like session ID, working directory, title, and last update time. Supports filtering by working directory,
additionalDirectories, and cursor-based pagination.Parameters
- params: ListSessionsRequest
Returns Promise<ListSessionsResponse>
delete Session
-
Deletes an existing session returned by
session/list.This method is only available if the agent advertises the
sessionCapabilities.deletecapability.Parameters
- params: DeleteSessionRequest
Returns Promise<DeleteSessionResponse>
resume Session
-
Resumes an existing session without returning previous messages.
This method is only available if the agent advertises the
session.resumecapability.The agent should resume the session context, allowing the conversation to continue without replaying the message history (unlike
session/load).The request may include
additionalDirectoriesto set the complete list of additional workspace roots for the resumed session.Parameters
- params: ResumeSessionRequest
Returns Promise<ResumeSessionResponse>
close Session
-
Closes an active session and frees up any resources associated with it.
This method is only available if the agent advertises the
session.closecapability.The agent must cancel any ongoing work (as if
session/cancelwas called) and then free up any resources associated with the session.Parameters
- params: CloseSessionRequest
Returns Promise<CloseSessionResponse>
set Session Mode
-
Sets the operational mode for a session.
Allows switching between different agent modes (e.g., "ask", "architect", "code") that affect system prompts, tool availability, and permission behaviors.
The mode must be one of the modes advertised in
availableModesduring session creation or loading. Agents may also change modes autonomously and notify the client viacurrent_mode_updatenotifications.This method can be called at any time during a session, whether the Agent is idle or actively generating a turn.
See protocol docs: Session Modes
Parameters
- params: SetSessionModeRequest
Returns Promise<SetSessionModeResponse>
set Session Config Option
-
setSessionConfigOption(
params: SetSessionConfigOptionRequest,
): Promise<SetSessionConfigOptionResponse>Set a configuration option for a given session.
The response contains the full set of configuration options and their current values, as changing one option may affect the available values or state of other options.
Parameters
- params: SetSessionConfigOptionRequest
Returns Promise<SetSessionConfigOptionResponse>
authenticate
-
Authenticates the client using the specified authentication method.
Called when the agent requires authentication before allowing session creation. The client provides the authentication method ID that was advertised during initialization.
After successful authentication, the client can proceed to create sessions with
newSessionwithout receiving anauth_requirederror.See protocol docs: Initialization
Parameters
- params: AuthenticateRequest
Returns Promise<AuthenticateResponse>
unstable_ list Providers
-
ExperimentalUNSTABLE
This capability is not part of the spec yet, and may be removed or changed at any point.
Lists providers that can be configured by the client.
This method is only available if the agent advertises the
providerscapability.Parameters
- params: ListProvidersRequest
Returns Promise<ListProvidersResponse>
unstable_ set Provider
-
ExperimentalUNSTABLE
This capability is not part of the spec yet, and may be removed or changed at any point.
Replaces the configuration for a provider.
This method is only available if the agent advertises the
providerscapability.Parameters
- params: SetProviderRequest
Returns Promise<SetProviderResponse>
unstable_ disable Provider
-
ExperimentalUNSTABLE
This capability is not part of the spec yet, and may be removed or changed at any point.
Disables a provider.
This method is only available if the agent advertises the
providerscapability.Parameters
- params: DisableProviderRequest
Returns Promise<DisableProviderResponse>
logout
-
Logout of the current authentication method.
Parameters
- params: LogoutRequest
Returns Promise<LogoutResponse>
prompt
-
Processes a user prompt within a session.
This method handles the whole lifecycle of a 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
See protocol docs: Prompt Turn
Parameters
- params: PromptRequest
Returns Promise<PromptResponse>
cancel
-
Cancels ongoing operations for a session.
This is a notification sent by the client to cancel an ongoing prompt turn.
Upon receiving this notification, the Agent SHOULD:
- 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
See protocol docs: Cancellation
Parameters
- params: CancelNotification
Returns Promise<void>
unstable_ start Nes
-
ExperimentalUNSTABLE: This capability is not part of the spec yet, and may be removed or changed at any point.
Starts a NES (Next Edit Suggestions) session.
Parameters
- params: StartNesRequest
Returns Promise<StartNesResponse>
unstable_ suggest Nes
-
ExperimentalUNSTABLE: This capability is not part of the spec yet, and may be removed or changed at any point.
Sends a NES suggestion request.
Parameters
- params: SuggestNesRequest
Returns Promise<SuggestNesResponse>
unstable_ close Nes
-
ExperimentalUNSTABLE: This capability is not part of the spec yet, and may be removed or changed at any point.
Closes a NES session.
Parameters
- params: CloseNesRequest
Returns Promise<CloseNesResponse>
unstable_ did Open Document
-
ExperimentalUNSTABLE: This capability is not part of the spec yet, and may be removed or changed at any point.
Notifies the agent that a document was opened.
Parameters
- params: DidOpenDocumentNotification
Returns Promise<void>
unstable_ did Change Document
-
ExperimentalUNSTABLE: This capability is not part of the spec yet, and may be removed or changed at any point.
Notifies the agent that a document was changed.
Parameters
- params: DidChangeDocumentNotification
Returns Promise<void>
unstable_ did Close Document
-
ExperimentalUNSTABLE: This capability is not part of the spec yet, and may be removed or changed at any point.
Notifies the agent that a document was closed.
Parameters
- params: DidCloseDocumentNotification
Returns Promise<void>
unstable_ did Save Document
-
ExperimentalUNSTABLE: This capability is not part of the spec yet, and may be removed or changed at any point.
Notifies the agent that a document was saved.
Parameters
- params: DidSaveDocumentNotification
Returns Promise<void>
unstable_ did Focus Document
-
ExperimentalUNSTABLE: This capability is not part of the spec yet, and may be removed or changed at any point.
Notifies the agent that a document received focus.
Parameters
- params: DidFocusDocumentNotification
Returns Promise<void>
unstable_ accept Nes
-
ExperimentalUNSTABLE: This capability is not part of the spec yet, and may be removed or changed at any point.
Notifies the agent that a NES suggestion was accepted.
Parameters
- params: AcceptNesNotification
Returns Promise<void>
unstable_ reject Nes
-
ExperimentalUNSTABLE: This capability is not part of the spec yet, and may be removed or changed at any point.
Notifies the agent that a NES suggestion was rejected.
Parameters
- params: RejectNesNotification
Returns Promise<void>
request
-
request<Method extends AgentRequestMethod>(
method: Method,
params: AgentRequestParamsByMethod[Method],
options?: SendRequestOptions,
): Promise<AgentRequestResponsesByMethod[Method]>Sends a request to the agent by ACP method name.
Built-in method literals infer their params and response types. Custom methods can specify their response and params types with generics.
Type Parameters
- Method extends AgentRequestMethod
Parameters
- method: Method
- params: AgentRequestParamsByMethod[Method]
Optionaloptions: SendRequestOptions
Returns Promise<AgentRequestResponsesByMethod[Method]>
-
request<Response = unknown, Params = unknown>(
method: string,
params?: Params,
options?: SendRequestOptions,
): Promise<Response>Sends a request to the agent by ACP method name.
Built-in method literals infer their params and response types. Custom methods can specify their response and params types with generics.
Type Parameters
- Response = unknown
- Params = unknown
Parameters
- method: string
Optionalparams: ParamsOptionaloptions: SendRequestOptions
Returns Promise<Response>
notify
-
notify<Method extends AgentNotificationMethod>(
method: Method,
params: AgentNotificationParamsByMethod[Method],
): Promise<void>Sends a notification to the agent by ACP method name.
Built-in method literals infer their params type. Custom notifications can specify their params type with a generic.
Type Parameters
- Method extends AgentNotificationMethod
Parameters
- method: Method
- params: AgentNotificationParamsByMethod[Method]
Returns Promise<void>
-
Sends a notification to the agent by ACP method name.
Built-in method literals infer their params type. Custom notifications can specify their params type with a generic.
Type Parameters
- Params = unknown
Parameters
- method: string
Optionalparams: Params
Returns Promise<void>
ext Method
-
Extension method.
Parameters
- method: string
- params: Record<string, unknown>
Returns Promise<Record<string, unknown>>
Deprecated
Use request.
ext Notification
-
Extension notification.
Parameters
- method: string
- params: Record<string, unknown>
Returns Promise<void>
Deprecated
Use notify.

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 the Agent interface to provide methods for initializing sessions, sending prompts, and managing the agent lifecycle.
See protocol docs: Client
Deprecated
Prefer client, which registers typed handlers with a single context object and supports
connectWithand session helpers.