# Agent Client Protocol (ACP)

Speak Agent Client Protocol v1 from a constrained Ferrite application so editors and local clients can run agent sessions while keeping filesystem and terminal ownership on the client.

Model Context Protocol (MCP) connects an agent to tools and data. Agent Client Protocol (ACP) solves the opposite boundary: it connects an editor or workstation client to an agent while the client retains ownership of the local filesystem and terminal. Whenever the agent needs to read a file or run a command, it requests access explicitly through ACP messages such as `fs/read_text_file` and `session/request_permission`.

Ferrite provides ACP v1 through the `acp` source package and exposes an `/acp` face on applications built with the [Agent SDK](/developers/agent-sdk/).

## Add the `acp` package

Install the host-free ACP v1 source package into your application:

```bash
ferrite add acp
```

`acp` compiles cleanly under Ferrite's single-dependency rule (`ferrite-app` only) with zero network, clock, or entropy preconditions. Every external value arrives as an explicit parameter, so protocol state transitions are deterministic and testable offline.

## Package modules and protocol roles

| Module | Role |
| --- | --- |
| `proto.rs` | Bidirectional JSON-RPC 2.0 envelope, strict `CallId` vs notification separation, per-entry batch handling |
| `transport.rs` | HTTP/SSE and WebSocket binding, connection IDs (`Acp-Connection-Id`), and `resolve_route` session routing |
| `schema.rs` | ACP v1 wire types matching the normative v1 JSON schema, including presence-encoded capabilities (`{}` vs absent) |
| `agent.rs` | Agent role covering the 13 methods an editor or client invokes (`initialize`, session creation, prompts, cancellation) |
| `client.rs` | Client role covering the 11 callback methods an agent invokes on the editor (`fs/read_text_file`, `session/request_permission`, terminal requests) |
| `session.rs` | Session lifecycle and per-connection state management |

## Expose `/acp` through the Agent SDK

If your application already embeds a durable agent with `agent-sdk`, mount the SDK's ACP face to map each ACP session onto a durable agent thread. Forward the connection and authorization headers in `ferrite.json`:

```json filename="ferrite.json (excerpt)"
{
  "prefix": "/acp",
  "binding": "requests",
  "kind": "api",
  "forward_headers": ["authorization", "content-type", "accept", "acp-connection-id"]
}
```

See [Agent API](/developers/agent-api/) for how `/acp` sits alongside the Thread API, `/mcp`, and `/a2a` on the same embedded agent runtime.

## Safety guarantees and host responsibilities

- **Session routing fails closed.** `transport::resolve_route` returns a `Result` and is the only public routing entry point. A `session/prompt` missing a valid session identifier is rejected rather than leaking onto the connection-wide stream.
- **Deterministic connection IDs.** Identifiers are derived as a digest over host-supplied inputs (such as subject, timestamp, and correlation ID) so a redelivered `initialize` request converges on the same connection instead of opening a duplicate session.
- **Per-entry batch handling.** JSON-RPC batches validate and answer each member independently so one malformed entry never discards valid sibling requests.
- **Host supplies transport, authentication, and persistence.** The `acp` source package implements the wire protocol and session state machine only. Your application supplies caller authentication (failing closed when credentials are missing or unconfigured), attaches the `Acp-Connection-Id` response header on `initialize`, and persists session state in your app's store.

## Next steps

- Wire `/acp`, `/mcp`, and `/a2a` onto a single embedded agent in [Agent API](/developers/agent-api/).
- Compare ACP with remote agent delegation in [Agent Cards and A2A](/developers/a2a-agent-cards/).
- Build an embedded durable agent with [Agent SDK](/developers/agent-sdk/).
