Expand description
§agent-client-protocol – the Agent Client Protocol (ACP) SDK
agent-client-protocol is a Rust SDK for building Agent-Client Protocol (ACP) applications. ACP is a protocol for communication between AI agents and their clients (IDEs, CLIs, etc.), enabling features like tool use, permission requests, and streaming responses.
§What can you build with agent-client-protocol?
- Clients that talk to ACP agents (like building your own Claude Code interface)
- Proxies that add capabilities to existing agents (like adding custom tools via MCP)
- Agents that respond to prompts with AI-powered responses
§Quick Start: Connecting to an Agent
The most common use case is connecting to an existing ACP agent as a client.
This example uses stable ACP protocol v1. The draft protocol v2 feature
provides a command-only V2Session API and receives updates and interactive
requests through typed connection handlers because prompt acceptance and
inbound traffic are independent. With both v2 and MCP-over-ACP features,
Proxy.v2() supports global MCP attachment, while V2SessionBuilder and
V2ResumeSessionBuilder support per-session attachment plus non-blocking
proxy setup. With unstable_session_fork, V2ForkSessionBuilder provides
the same shape for forked sessions and uses the response’s new session ID.
Per-session MCP routes and runners are ready before a setup request is
published, as is proxy session routing for resume replay; successful
attachments remain active for the connection lifetime.
Here’s a minimal example that initializes a v1 connection, creates a session, and sends a prompt:
use agent_client_protocol::Client;
use agent_client_protocol::schema::{ProtocolVersion, v1::InitializeRequest};
Client.builder()
.name("my-client")
.connect_with(transport, async |cx| {
// Step 1: Initialize the connection
cx.send_request(InitializeRequest::new(ProtocolVersion::V1))
.block_task().await?;
// Step 2: Create a session and send a prompt
cx.build_session_cwd()?
.block_task()
.run_until(async |mut session| {
session.send_prompt("What is 2 + 2?")?;
let response = session.read_to_string().await?;
println!("{}", response);
Ok(())
})
.await
})
.awaitFor a complete working example, see yolo_one_shot_client.rs.
§Cookbook
The agent_client_protocol_cookbook crate contains practical guides and examples:
- Connecting as a client
- Global MCP server
- Per-session MCP server with workspace context
- Building agents and reusable components
- Running proxies with the conductor
§WASI
The runtime-neutral protocol engine and transport abstractions compile for
wasm32-wasip1 and wasm32-wasip2. This crate does not provide a WASI
executor or host I/O adapter. The native AcpAgent and Stdio
implementations depend on process spawning and blocking-thread facilities,
so they and LineDirection are not exported on these targets.
Embedders provide their own runtime and transport. They can exchange
TransportFrame values through Channel, newline-delimited JSON through
Lines, or use ByteStreams with futures::io::AsyncRead and
AsyncWrite. The embedding runtime must drive the resulting connection
future.
§Core Concepts
The concepts module provides detailed explanations of how agent-client-protocol works,
including connections, sessions, callbacks, ordering guarantees, and more.
§Related Crates
agent-client-protocol-conductor- Binary for running proxy chains
Re-exports§
pub use role::acp::AgentProtocolRouter;unstable_protocol_v2pub use role::acp::ClientProtocolConnector;unstable_protocol_v2pub use role::acp::ProxyProtocolRouter;unstable_protocol_v2pub use role::Role;pub use role::RoleId;pub use role::UntypedRole;pub use role::acp::Agent;pub use role::acp::Client;pub use role::acp::Conductor;pub use role::acp::Proxy;pub use component::ConnectTo;pub use component::DynConnectTo;
Modules§
- component
- Component abstraction for agents and proxies ConnectTo abstraction for agents and proxies.
- concepts
- Core concepts for understanding and using agent-client-protocol Core concepts for understanding and using agent-client-protocol.
- mcp_
server - Runtime-agnostic MCP server support, including optional attachment to ACP sessions. Runtime-agnostic MCP server support.
- role
- Role types for ACP connections Role types for ACP connections.
- schema
- ACP protocol schema types - all message types, requests, responses, and supporting types ACP protocol schema types and message implementations.
- util
- Utility functions and types
Macros§
- on_
receive_ dispatch - This macro is used for the value of the
to_future_hackparameter ofBuilder::on_receive_dispatchandBuilder::on_receive_dispatch_from. - on_
receive_ notification - This macro is used for the value of the
to_future_hackparameter ofBuilder::on_receive_notificationandBuilder::on_receive_notification_from. - on_
receive_ request - This macro is used for the value of the
to_future_hackparameter ofBuilder::on_receive_requestandBuilder::on_receive_request_from. - tool_fn
- This is a hack that must be given as the final argument of
the MCP server builder’s
tool_fnmethod when defining stateless concurrent tools. - tool_
fn_ mut - This is a hack that must be given as the final argument of
the MCP server builder’s
tool_fn_mutmethod when defining tools.
Structs§
- AcpAgent
Non- target_family=wasm - A component representing an external ACP agent running in a separate process.
- AcpAgent
Config Non- target_family=wasm - Configuration for launching an ACP agent subprocess.
- Active
Session - Stable protocol v1 active session that lets you send prompts and receive updates.
- Blocking
- Marker type indicating the session builder will block the current task.
- Builder
- A JSON-RPC connection that can act as either a server, client, or both.
- Byte
Streams - A component that communicates over byte streams (stdin/stdout, sockets, pipes, etc.).
- Chain
Run - Chains two RunIn implementations to run in parallel.
- Channel
- A channel endpoint representing one side of a bidirectional JSON-RPC transport.
- Connection
To - Connection context for sending messages and spawning tasks.
- Dynamic
Handler Guard - A guard that keeps a dynamic message handler registered.
- Error
- JSON-RPC error object.
- Lines
- A component that communicates over line streams.
- NonBlocking
- Marker type indicating the session builder will not block the current task.
- Null
Close - A close handler that does nothing.
- Null
Handler - Null handler that accepts no messages.
- NullRun
- A no-op RunIn that completes immediately.
- Opened
V2Session unstable_protocol_v2 - A newly available protocol v2 session and its operation-specific response.
- Request
Cancellation - A request-local marker that is set when the peer asks to cancel the request.
- Responder
- The context to respond to an incoming request.
- Response
Router - Context for handling an incoming JSON-RPC response.
- Restore
Session Builder - Stable protocol v1 builder for
session/loadorsession/resume. - Restored
Session - A restored stable-v1 session and the exact operation response that opened it.
- Sent
Request - Represents a pending response of type
Rfrom an outgoing request. - Session
Builder - Stable protocol v1 session builder for a new session request. Allows you to add MCP servers or set other details for this session.
- Stdio
Non- target_family=wasm - A transport that connects to an ACP peer via standard input/output.
- Transport
Batch - A structurally non-empty JSON-RPC batch retained across framed relays.
- Untyped
Message - An incoming JSON message without any typing. Can be a request or a notification.
- V2Connection
To unstable_protocol_v2 - A protocol-v2 connection context.
- V2Fork
Session Builder unstable_protocol_v2andunstable_session_fork - Builder for an unstable draft protocol v2
session/forkrequest. - V2Resume
Session Builder unstable_protocol_v2 - Builder for a draft protocol v2
session/resumerequest. - V2Session
unstable_protocol_v2 - Cloneable command handle for a draft protocol v2 session.
- V2Session
Builder unstable_protocol_v2 - Builder for a draft protocol v2
session/newrequest.
Enums§
- Dispatch
- An incoming request, notification, or response being dispatched through handlers. Requests include the context used to answer them; responses include the context used to route them to the local requester.
- Error
Code - Predefined error codes for common JSON-RPC and ACP-specific errors.
- Handled
- Return type from JrHandler; indicates whether the request was handled or not.
- Line
Direction Non- target_family=wasm - Direction of a line being sent or received.
- RawJson
RpcMessage - One valid JSON-RPC message carried inside a
TransportFrame. - RawJson
RpcParams - Raw JSON-RPC request or notification parameters.
- Session
Message - Incoming stable protocol v1 message from the agent.
- Transport
Batch Entry - One entry in a
TransportBatch. - Transport
Frame - A JSON-RPC frame exchanged between protocol components and transports.
Constants§
- INCOMING_
TRANSPORT_ CLOSED_ REASON - Stable discriminator stored in the
data.reasonfield of errors produced when the incoming transport reaches clean EOF before a request receives its response.
Traits§
- Handle
Connection Close - A handler that runs after the incoming transport reaches clean EOF.
- Handle
Dispatch From - Handlers process incoming JSON-RPC messages on a connection.
- Into
Handled - Trait for converting handler return values into
Handled. - Json
RpcMessage - Common bounds for any JSON-RPC message.
- Json
RpcNotification - A struct that represents a notification (JSON-RPC message that does not expect a response).
- Json
RpcRequest - A struct that represents a request (JSON-RPC message expecting a response).
- Json
RpcResponse - Defines the “payload” of a successful response to a JSON-RPC request.
- Meta
Capability - Trait for capabilities stored in the
_meta.symposiumobject. - Meta
Capability Ext - Extension trait for checking and modifying capabilities in
InitializeRequest. - RunWith
Connection To - A background task that runs alongside a connection.
- Session
Block State - Trait for marker types that indicate blocking vs non-blocking API.
See
SessionBuilder::block_task.
Functions§
- is_
cancel_ request_ notification - Whether a notification is a
$/cancel_request, even when it is still wrapped in_proxy/successorenvelopes. - is_
incoming_ transport_ closed - Return whether
errorreports that the incoming transport reached clean EOF before a request received its response.
Type Aliases§
- BoxFuture
alloc - An owned dynamically typed
Futurefor use in cases where you can’t statically type your result or need to add some indirection. - Result
- Convenience result type using this protocol version’s error type.
- V2Builder
unstable_protocol_v2 - A JSON-RPC connection builder whose callbacks receive
V2ConnectionTo.
Derive Macros§
- Json
RpcNotification - Derive macro for implementing
JsonRpcNotificationandJsonRpcMessagetraits. - Json
RpcRequest - Derive macro for implementing
JsonRpcRequestandJsonRpcMessagetraits. - Json
RpcResponse - Derive macro for implementing
JsonRpcResponsetrait.