acpd library
The acpd library — Dart SDK for the Agent Client Protocol (ACP).
ACP is a JSON-RPC 2.0 based protocol standardizing communication between code editors/IDEs and AI-powered coding agents. This package provides:
- Schema types: strongly-typed definitions of all ACP v1 wire messages.
- JSON-RPC engine: request/response correlation, notifications, cancellation, and extension methods.
- Roles: ClientRole and AgentRole abstractions with typed handlers.
- Session: a high-level helper for the prompt-turn lifecycle.
Platform-specific transports live in companion packages:
package:acpd_io— Stdio and process-basedAcpAgenttransports.package:acpd_http— HTTP/SSE and WebSocket transports.package:acpd_test— in-memory transport pair and mock roles.
Classes
- AcpConnection
- A connection that stays open independently of a single prompt turn.
- AgentAuthCapabilities
- Agent auth capabilities.
- AgentAuthMethod
- The agent auth-method variant.
- AgentCapabilities
- Capabilities supported by the agent.
- AgentConnection
- A running agent connection — use agent to call client-side methods.
- AgentContext
- The agent's view of the client, for issuing client-side ACP requests.
- AgentMessageChunk
- A chunk of the agent's response being streamed.
- AgentRole
- Builds an agent role: registers agent-side handlers and connects.
- AgentThoughtChunk
- A chunk of the agent's internal reasoning being streamed.
- Annotations
- Optional annotations that help clients decide how to display or route content.
- AudioContent
- Audio content — base64-encoded audio data.
- AuthenticateRequest
-
Request parameters for
authenticate. - AuthenticateResponse
-
Response to
authenticate(empty body). - AuthMethod
-
The
typefield discriminates the method; when absent it is treated asagent. Onlyagentis defined in v1. - AuthMethodAgent
- Agent-handled authentication method (default type).
- AvailableCommand
- Information about a command the agent can execute.
- AvailableCommandsSessionUpdate
- Available commands are ready or have changed.
- AvailableCommandsUpdate
- Notification that available commands changed.
- BatchTransportFrame
- A frame carrying one non-empty JSON-RPC batch.
- BlobResourceContents
- Binary resource contents.
- BooleanConfigOptionCapabilities
- Boolean config-option sub-capability.
- CancelNotification
-
The
session/cancelclient→agent notification payload. - CancelRequestNotification
-
The
$/cancel_requestprotocol-level notification payload. - CapabilityFlag
-
Marker capability sub-objects (empty body, just
_meta). - ClientCapabilities
- Capabilities supported by the client.
- ClientConnection
- A running client connection — use client to call agent-side methods.
- ClientContext
- The client's view of the agent, for issuing agent-side ACP requests.
- ClientRole
- Builds a client role: registers client-side handlers and connects.
- ClientSessionCapabilities
- Client-side session capabilities.
- CloseSessionRequest
-
Request parameters for
session/close. - CloseSessionResponse
-
Response to
session/close(empty body). - ConfigOptionSessionUpdate
- Session configuration options updated.
- ConfigOptionUpdate
- Session configuration options updated.
- Connection
- A JSON-RPC 2.0 connection.
- ConnectionFailure
- A locally observed connection or handler failure.
- Content
-
A standard content block wrapper (the
Contentschema type). - ContentBlock
- A content block — one of five variants distinguished by type.
- ContentChunk
- A streamed item of content.
- Cost
- Cumulative session cost.
- CreateTerminalRequest
-
Request parameters for
terminal/create. - CreateTerminalResponse
-
Response to
terminal/create. - CurrentModeSessionUpdate
- The current mode of the session changed.
- CurrentModeUpdate
- The current mode of the session changed.
- DeleteSessionRequest
-
Request parameters for
session/delete. - DeleteSessionResponse
-
Response to
session/delete(empty body). - Diff
- A diff representing file modifications.
- EmbeddedResource
- An embedded resource (text or binary) inlined into the content stream.
- EnvVariable
- An environment variable to set when launching an MCP server.
- FileSystemCapabilities
- File-system capabilities.
- HandlerRegistration
- The result of registering a handler — call dispose to remove it.
- HttpHeader
- An HTTP header to set when making requests to an MCP server.
- ImageContent
- Image content — base64-encoded image data.
- Implementation
- Metadata about a client or agent implementation.
- InitializeRequest
-
Request parameters for
initialize. - InitializeResponse
-
Response to
initialize. - KillTerminalRequest
-
Request parameters for
terminal/kill. - KillTerminalResponse
-
Response to
terminal/kill(empty body). - LineTransport
- A transport that exchanges raw JSON lines (newline-delimited JSON).
- ListSessionsRequest
-
Request parameters for
session/list. - ListSessionsResponse
-
Response to
session/list. - LoadSessionRequest
-
Request parameters for
session/load. - LoadSessionResponse
-
Response to
session/load. - LogoutRequest
-
Request parameters for
logout. - LogoutResponse
-
Response to
logout(empty body). - MalformedBatchEntry
- A malformed value retained inside a JSON-RPC batch.
- MalformedTransportFrame
- A malformed standalone wire value.
- McpCapabilities
- MCP transport capabilities.
- McpServer
- MCP server configuration.
- McpServerHttp
- HTTP transport configuration.
- McpServerSse
- SSE transport configuration.
- McpServerStdio
- Stdio transport configuration (all agents must support this).
- MessageBatchEntry
- A valid message inside a JSON-RPC batch.
- NewSessionRequest
-
Request parameters for
session/new. - NewSessionResponse
-
Response to
session/new. - PermissionCancelled
- The turn was cancelled before the user responded.
- PermissionOption
- A permission option presented to the user.
- PermissionSelected
- The user selected a permission option.
- Plan
- An execution plan for accomplishing complex tasks.
- PlanEntry
- A single entry in an execution plan.
- PlanUpdate
- The agent's execution plan.
- PromptCapabilities
- Prompt input capabilities.
- PromptRequest
-
Request parameters for
session/prompt. - PromptResponse
-
Response to
session/prompt. - PromptTurnResult
- The result of a prompt turn: the terminal stopReason and every SessionUpdate observed during the turn, in arrival order.
- ReadTextFileRequest
-
Request parameters for
fs/read_text_file. - ReadTextFileResponse
-
Response to
fs/read_text_file. - ReleaseTerminalRequest
-
Request parameters for
terminal/release. - ReleaseTerminalResponse
-
Response to
terminal/release(empty body). - RequestCancellation
- Cancellation signal for an inbound JSON-RPC request.
- RequestPermissionOutcome
- The outcome of a permission request.
- RequestPermissionRequest
-
Request parameters for
session/request_permission. - RequestPermissionResponse
-
Response to
session/request_permission. - ResourceContents
- A sealed union over text and binary resource payloads.
- ResourceLink
- A link to a resource the server can read.
- ResumeSessionRequest
-
Request parameters for
session/resume. - RpcMessage
- A discriminated union over all JSON-RPC message kinds.
- RpcNotification
-
A JSON-RPC 2.0 notification (no
id, no response expected). - RpcRequest
- A JSON-RPC 2.0 request message.
- RpcResponse
- Session
- A high-level client session bound to a ClientConnection.
- SessionCapabilities
- Agent-side session capabilities.
- SessionConfigBooleanOption
- A boolean on/off config option.
- SessionConfigGroupedOptions
- A grouped list of options.
- SessionConfigOption
- A session configuration option — select or boolean.
- SessionConfigOptionCategory
- Semantic category for a session configuration option (UX hint only).
- SessionConfigOptionsCapabilities
- Client session config-options capability.
- SessionConfigSelectGroup
- A group of option values under a header.
- SessionConfigSelectOption
- A possible value for a session configuration option.
- SessionConfigSelectOptions
- A sealed union over flat vs grouped option lists.
- SessionConfigSelectOptionValue
- A single-value (dropdown) config option.
- SessionConfigUngroupedOptions
- A flat list of options.
- SessionInfo
-
Information about a session (from
session/list). - SessionInfoSessionUpdate
- Session metadata updated (title, timestamps).
- SessionInfoUpdate
- Update to session metadata (partial).
- SessionMode
- A mode the agent can operate in (e.g. "plan", "normal").
- SessionModeState
- The set of modes and the one currently active.
- SessionUpdate
- A session update — one of 11 variants.
- SessionUpdateNotification
-
The
session/updatenotification envelope: binds a sessionId to an update payload. - SetBooleanConfigOption
- Set a boolean config option.
- SetSessionConfigOptionRequest
-
Request parameters for
session/set_config_option. - SetSessionConfigOptionResponse
-
Response to
session/set_config_option. - SetSessionModeRequest
-
Request parameters for
session/set_mode. - SetSessionModeResponse
-
Response to
session/set_mode(empty body). - SetValueIdConfigOption
- Set a value-id (select) config option.
- SingleTransportFrame
- A frame carrying one valid JSON-RPC message.
- Terminal
-
An embedded terminal reference (the
Terminalschema type). - TerminalExitStatus
- Exit status of a terminal command.
- TerminalOutputRequest
-
Request parameters for
terminal/output. - TerminalOutputResponse
-
Response to
terminal/output. - TextContentBlock
- Text content. May be plain text or Markdown.
- TextResourceContents
- Text-based resource contents.
- ToolCall
- A complete tool call.
- ToolCallContent
- Content produced by a tool call.
- ToolCallContentBlock
- A standard content block wrapped for tool-call output.
- ToolCallDiff
- A file modification diff.
- ToolCallLocation
- A file location affected by a tool call.
- ToolCallStatusUpdate
- Update on the status or results of a tool call.
- ToolCallTerminal
- An embedded terminal reference.
- ToolCallUpdate
- A partial update to an existing tool call.
- ToolCallUpdateSession
- Notification that a new tool call has been initiated.
- Transport
- A bidirectional framed JSON-RPC transport channel.
- TransportBatch
- A structurally non-empty JSON-RPC batch.
- TransportBatchEntry
- One entry in a TransportBatch.
- TransportFrame
- One complete JSON-RPC value exchanged by a Transport.
- UnstructuredCommandInput
- Unstructured command input — all text typed after the command name.
- UsageSessionUpdate
- Context window and cost update.
- UsageUpdate
- Context window and cost update.
- UserMessageChunk
- A chunk of the user's message being streamed.
- WaitForTerminalExitRequest
-
Request parameters for
terminal/wait_for_exit. - WaitForTerminalExitResponse
-
Response to
terminal/wait_for_exit. - WriteTextFileRequest
-
Request parameters for
fs/write_text_file. - WriteTextFileResponse
-
Response to
fs/write_text_file(empty body).
Enums
- ErrorCode
- Predefined error codes for JSON-RPC 2.0 and ACP-specific errors.
- PermissionOptionKind
- The type of permission option presented to the user.
- PlanEntryPriority
- Priority levels for plan entries.
- PlanEntryStatus
- Status of a plan entry in the execution flow.
- ProtocolVersion
- Protocol version identifier.
- Role
- The sender or recipient of a message in a conversation.
- StopReason
- Reasons why an agent stops processing a prompt turn.
- ToolCallStatus
- Execution status of a tool call.
- ToolKind
- Categories of tools that an agent can invoke.
Extension Types
- SessionUpdateKind
- The discriminator value for each SessionUpdate variant.
Extensions
- ErrorCodeMessage on ErrorCode
- A human-readable label for each ErrorCode, per the schema.
Constants
- kCancelRequestMethod → const String
- The JSON-RPC protocol-level cancel-request notification method.
- kJsonRpcVersion → const String
- The JSON-RPC protocol version string used by every ACP message.
Functions
-
asJsonObject(
Object? value) → Map< String, Object?> -
Casts a decoded JSON value to
Map<String, Object?>. -
decodeFrame(
String source) → TransportFrame - Decodes one complete JSON-RPC transport value.
-
decodeMessage(
String line) → RpcMessage - Decodes a JSON line into a JSON-RPC message.
-
encodeFrame(
TransportFrame frame) → String - Encodes one complete JSON-RPC transport value.
-
encodeMessage(
RpcMessage message) → String - Encodes a JSON-RPC message to a newline-delimited JSON line.
-
jsonDecodeAs<
T> (String data) → T -
Converts a JSON-decodeable string into a typed value via
fromJson. -
jsonEncodeTo(
Object? value) → String - Encodes a value map to a compact JSON string.
-
readField<
T> (Map< String, Object?> json, String key) → T? -
Reads an optional object field, returning
nullwhen absent ornull. -
readFieldOr<
T> (Map< String, Object?> json, String key, T defaultValue) → T - Reads a required field with a default value when the field is absent.
-
readListField<
T> (Map< String, Object?> json, String key, T convert(Map<String, Object?> )) → List<T> -
Converts a list field of nested objects into typed values via
convert. -
readMeta(
Map< String, Object?> json) → Map<String, Object?> -
Reads the
_metafield, returning an empty map when absent. -
requireField<
T> (Map< String, Object?> json, String key) → T - Reads a required field, throwing FormatException when absent.
-
unknownValue(
String type, Object? value) → Never -
Ensures
valueis non-null, otherwise throws a FormatException. -
validateRpcParams(
Object? params) → void -
Validates a JSON-RPC 2.0
paramsmember. -
writeMeta(
Map< String, Object?> json, Map<String, Object?> ? meta) → void -
Writes
_metaintojsononly when non-null and non-empty.
Typedefs
-
AgentNotificationHandler<
P> = FutureOr< void> Function(AgentContext context, P params) - Handler signature for client-to-agent notifications.
-
AgentRequestHandler<
P, R> = FutureOr< R> Function(AgentContext context, P params, RequestCancellation cancellation) - Handler signature for agent-side requests.
-
AnyNotificationHandler
= FutureOr<
void> Function(String method, Object? params) - A catch-all handler that receives both method name and params.
-
CancellableRequestHandler
= FutureOr<
Object?> Function(Object? params, RequestCancellation cancellation) - A handler for an inbound request that observes peer cancellation.
-
ClientNotificationHandler<
P> = FutureOr< void> Function(ClientContext context, P params) - Handler signature for client-side notifications.
-
ClientRequestHandler<
P, R> = FutureOr< R> Function(ClientContext context, P params, RequestCancellation cancellation) - Handler signature for client-side requests.
- LogoutCapabilities = CapabilityFlag
- Logout sub-capability of AgentAuthCapabilities.
-
NotificationHandler
= FutureOr<
void> Function(Object? params) - A handler for an incoming JSON-RPC notification.
-
RequestHandler
= FutureOr<
Object?> Function(Object? params) - A handler for an incoming JSON-RPC request.
- RequestId = Object?
- A JSON-RPC 2.0 request identifier: string, integer, or null.
- ResumeSessionResponse = LoadSessionResponse
-
Response to
session/resume. - SessionAdditionalDirectoriesCapabilities = CapabilityFlag
- SessionCloseCapabilities = CapabilityFlag
- SessionDeleteCapabilities = CapabilityFlag
- SessionListCapabilities = CapabilityFlag
- Session-level capability sub-objects.
- SessionResumeCapabilities = CapabilityFlag
- TextContent = TextContentBlock
-
Alias matching the ACP schema's
TextContenttype name.
Exceptions / Errors
- RpcError
- A JSON-RPC 2.0 error.