# Adapter protocol

An adapter is a process Blossom launches, and both sides exchange JSON-RPC 2.0 messages over stdio.

Names and shapes follow the [Agent Client Protocol](https://agentclientprotocol.com) where they overlap: Blossom is the client, the adapter the agent.

![JSON-RPC 2.0 over stdio between an adapter and Blossom core](/docs/protocol.jpg)

## Transport

- One message per line, UTF-8, no embedded newlines, 1 MiB at most. The host skips a longer line, one that is not UTF-8, and any message it does not know.
- Standard output carries protocol messages only; adapters log to standard error.
- Keys are `camelCase`, discriminator values `snake_case`, request identifiers unsigned integers.
- Closing standard input ends the adapter, and one still there two seconds later is killed with its process group.
- Limits: 128 sessions and 32 pending requests per adapter, 16 agents per manifest.

## Version

`protocolVersion` is a single integer that changes only on a breaking change, and it is `1` today. The host sends the latest version it supports, the adapter answers with the same version or the latest it does, and on a mismatch the host kills it and marks it stopped. One that has not answered within thirty seconds of its launch is killed.

An addition never changes the version: every new field is optional, and a host that does not know one skips it.

## Messages

| Method | Direction | Kind | Origin |
|---|---|---|---|
| `initialize` | host → adapter | request | ACP |
| `session/started` | adapter → host | notification | Blossom |
| `session/update` | adapter → host | notification | ACP |
| `session/closed` | adapter → host | notification | Blossom |
| `session/request_permission` | adapter → host | request | ACP |
| `elicitation/create` | adapter → host | request | ACP |
| `$/cancel_request` | adapter → host | notification | ACP |
| `session/new` | host → adapter | request | ACP |
| `session/prompt` | host → adapter | request | ACP |
| `session/cancel` | host → adapter | notification | ACP |
| `session/close` | host → adapter | request | ACP |

A session identifier only has to be unique within its adapter, which reaches only the sessions it started and the agents it announced. `limits/read` and `changes/read` are Blossom's own, asked only of an agent whose manifest offers them.

## One exchange

A permission request, and the answer Blossom writes back:

```json
{ "jsonrpc": "2.0", "id": 1, "method": "session/request_permission", "params": { "sessionId": "codex-tests", "toolCall": { "toolCallId": "codex-tests-run", "title": "bun run test --filter notch" }, "options": [ { "optionId": "allow", "name": "Allow", "kind": "allow_once" }, { "optionId": "reject", "name": "Reject", "kind": "reject_once" } ] } }

{ "jsonrpc": "2.0", "id": 1, "result": { "outcome": { "outcome": "selected", "optionId": "allow" } } }
```

A request that stops being pending without the user resolving it gets the other outcome ACP defines, `cancelled`.

> [!NOTE]
> What a request would do, its `kind` and `content`, stays in memory only while the request waits, and is shown only in the panel of that request.

## Acting on a session

The last four methods go from the host to the adapter, and only when the agent declared the capability **and** the user turned acting on for it, which is off by default.

| Capability | The adapter takes |
|---|---|
| `start` | `session/new`, and `session/prompt`, `session/cancel` and `session/close` for the sessions it started that way |
| `prompt` | `session/prompt` for a session of this agent that Blossom did not start |
| `cancel` | `session/cancel` for any session of this agent, also one begun in a terminal |

`session/close` is never sent for a session Blossom did not start. An adapter that cannot do what it was asked answers with a JSON-RPC error: `-32601`, `-32002` for an unknown session, `-32010` when another process holds it.

## Schema and SDK

`bun run generate` writes the schema of every message to `crates/protocol/generated/schema.json`, and `sdks/adapter` writes the same messages from `serve(manifest, onReady)`.

> [!TIP]
> Why Blossom acts on sessions is in [../decisions/acting.md](../../decisions/acting.md); the packages the app includes are in [adapters.md](adapters.md).
