Skip to content

zidane/acp

An Agent Client Protocol server that lets editors such as Zed drive a zidane agent.

import { … } from 'zidane/acp'src/acp/index.ts

Use this entry point to embed zidane as an ACP (Agent Client Protocol) agent in your own process. runAcpStdioServer serves the protocol over stdio, createAcpServer returns a handler for a custom transport, and the JSON-RPC and content-mapping helpers support custom clients. Sessions use a 1-hour prompt cache (behavior.cacheTtl: '1h'), and each session's system prompt is frozen on its first prompt. Set freezeSystemPrompt: false to send the fresh prompt every time. Editors normally run the zidane-acp command instead, described in ACP.

TypeScript
import { runAcpStdioServer } from 'zidane/acp'
import { anthropic } from 'zidane/providers/anthropic'

const handle = runAcpStdioServer({
  provider: anthropic(),
  permission: { enabled: true },
})

process.once('SIGTERM', () => {
  void handle.close().finally(() => process.exit(143))
})

Functions#

acpMcpServersToZidaneFunction#

Converts MCP server entries from an ACP session request to Zidane McpServerConfig values. http becomes streamable-http, sse stays sse, and anything else is treated as a stdio command.

acpPromptToPromptPartsFunction#

Converts the ACP prompt content blocks of a session/prompt request to Zidane prompt parts. Images and audio without embedded data, and unknown block types, become text parts and add a warning.

createAcpServerFunction#

Creates an ACP agent server. The server speaks ACP v1: initialize, authenticate, logout, session/new, session/load, session/resume, session/list, session/delete, session/close, session/prompt, session/set_mode, session/set_config_option, and the session/cancel notification. It does no I/O itself, so connect it to a transport with createJsonRpcConnection or use runAcpStdioServer. Throws when neither provider nor models is set, or when defaultModelId is not in models.

createClientDeclaredToolsFunction#

Builds agent tools for client-declared specs. Each tool sends a CLIENT_TOOL_CALL_METHOD request to the client and returns the reply text. If the call is aborted, it sends CLIENT_TOOL_CANCEL_METHOD and rejects. A reply with isError: true throws.

createJsonRpcConnectionFunction#

Creates a JSON-RPC 2.0 connection over a pair of byte streams. Frames are newline-delimited JSON by default. Replies to incoming requests come from onRequest; the returned peer sends requests and notifications. Reading starts when start is called.

parseClientToolSpecsFunction#

Validate _meta.zidane.clientTools. Returns undefined when the key is absent (so resume can keep the existing set) and throws on malformed specs.

runAcpStdioServerFunction#

Runs an ACP agent over stdio, usually as the entry point of an editor-facing agent process. Creates the server with createAcpServer, connects it to a JSON-RPC connection on input and output, and starts reading. Throws if neither provider nor models is set.

sessionBlocksToAcpFunction#

Converts stored session content blocks to ACP content blocks, for replaying history. Thinking blocks become text. Images and documents without data become resource_link blocks. Audio without data and system notes are dropped.

stopReasonFromRunFunction#

Maps the outcome of an agent run to an ACP stop reason. An abort gives cancelled, reaching the turn limit gives max_turn_requests. Otherwise the last turn finish reason decides: length gives max_tokens, content-filter and error give refusal, and anything else gives end_turn.

toolResultToAcpContentFunction#

Converts a tool result to ACP tool call content. A string becomes one text content item. Block arrays map block by block, and unsupported blocks fall back to their text form.

withAcpDefaultToolsFunction#

Return preset with the default ACP search/fetch tools filled in. The preset's own tools win on name collision, so this only adds what's missing. Applied to the default base and by the zidane-acp CLI — never to a host-provided AcpServerOptions.preset, which is honored verbatim.

wrapToolsForAcpClientFunction#

Replaces the read_file, write_file and shell tools with versions that run on the ACP client. Uses the client file system and terminal so the user sees editor state and terminal output. Tools the client cannot back, or that are missing from tools, are left as they are.

Classes#

AcpProtocolErrorClass#

Error with a JSON-RPC error code. Throwing it from a handler produces an error response with that code and data.

JsonRpcRemoteErrorClass#

Error thrown when the other side answers a request with a JSON-RPC error response. Carries the remote code and data next to the remote message.

Constants#

ACP_PROTOCOL_VERSIONConstant#

ACP major protocol version this server speaks. initialize answers with this value.

CLIENT_TOOL_CALL_METHODConstant#

JSON-RPC method the agent sends to the client to run a client-declared tool.

CLIENT_TOOL_CANCEL_METHODConstant#

Notification the agent sends when it abandons a pending CLIENT_TOOL_CALL_METHOD.

Interfaces#

AcpClientCapabilitiesInterface#

Capabilities an ACP client declares in initialize. They decide which requests the agent may send back.

AcpClientToolOptionsInterface#

Options for wrapToolsForAcpClient.

AcpClientToolSpecInterface#

A tool the ACP client declares in session/new / session/load / session/resume under _meta.zidane.clientTools. The agent sees it like any other tool; execution round-trips to the client over CLIENT_TOOL_CALL_METHOD.

AcpImplementationInfoInterface#

ACP Implementation metadata. The spec requires name + version; title is an optional UI label. Incoming clientInfo is treated loosely (see InitializeRequest) since we never reflect it back on the wire.

AcpModelChoiceInterface#

A user-selectable model exposed to ACP clients as a category: 'model' session config option. Each choice carries its OWN provider so switching a model can switch provider + credentials. provider may be a factory so the credentials for a model are only resolved when that model is first selected.

AcpModelOptionInterface#

A model-specific boolean option, exposed to the client as a select control.

AcpPeerInterface#

The remote side of an ACP connection, used to send requests and notifications to it.

AcpPermissionPolicyInterface#

Controls when the agent asks the client for permission before running a tool.

AcpPromptMappingInterface#

Result of converting an ACP prompt to Zidane prompt parts, see acpPromptToPromptParts.

AcpServerInterface#

The ACP agent side. Handles requests and notifications from an ACP client and sends updates back through a peer.

AcpServerOptionsInterface#

Options for createAcpServer. Set provider or models.

AcpSessionRuntimeInterface#

In-memory state of one open ACP session.

AgentAuthCapabilitiesInterface#

Authentication features the agent supports.

AgentCapabilitiesInterface#

Capabilities the agent advertises in the initialize response.

AudioContentInterface#

An audio content block.

AuthenticateRequestInterface#

Params of the authenticate request.

AuthMethodInterface#

An authentication method the agent offers.

AvailableCommandInterface#

A slash command the agent offers in a session.

AvailableCommandInputInterface#

Input description for an AvailableCommand.

BlobResourceContentsInterface#

Embedded resource content in binary form.

CancelNotificationInterface#

Params of the session/cancel notification. Aborts the running prompt of a session.

ClientToolCallResponseInterface#

Reply the client returns for a CLIENT_TOOL_CALL_METHOD request.

CloseSessionRequestInterface#

Params of the session/close request.

ContentAnnotationsInterface#

Hints about how a content block should be used or shown.

ContentChunkInterface#

A piece of streamed message content, carried by session/update notifications.

CostInterface#

Monetary cost of a session so far.

CreateTerminalRequestInterface#

Params of the terminal/create request. The agent sends it to start a command in a client terminal.

DeleteSessionRequestInterface#

Params of the session/delete request.

EmbeddedResourceInterface#

A content block that carries a resource inline.

EnvVariableInterface#

An environment variable passed to a stdio MCP server.

HttpHeaderInterface#

An HTTP header sent to an HTTP or SSE MCP server.

ImageContentInterface#

An image content block.

InitializeRequestInterface#

Params of the initialize request, the first call of a connection.

InitializeResponseInterface#

Result of the initialize request.

JsonRpcConnectionInterface#

A JSON-RPC peer bound to a pair of byte streams. Call start to begin reading.

JsonRpcConnectionOptionsInterface#

Options for createJsonRpcConnection.

JsonRpcErrorInterface#

Error object of a JsonRpcFailure.

JsonRpcFailureInterface#

A JSON-RPC 2.0 response to a request that failed.

JsonRpcNotificationInterface#

A JSON-RPC 2.0 notification. It has no id and gets no response.

JsonRpcRequestInterface#

A JSON-RPC 2.0 request. The receiver answers it with a response carrying the same id.

JsonRpcSuccessInterface#

A JSON-RPC 2.0 response to a request that succeeded.

ListSessionsRequestInterface#

Params of the session/list request.

ListSessionsResponseInterface#

Result of the session/list request.

LoadSessionRequestInterface#

Params of the session/load request. Replays the stored history as session/update notifications.

LoadSessionResponseInterface#

session/load and session/resume responses do NOT echo sessionId and carry no inline message history. Conversation history is replayed via session/update notifications before the response is returned.

McpCapabilitiesInterface#

MCP server transports the agent supports. stdio is always supported.

NewSessionRequestInterface#

Params of the session/new request.

NewSessionResponseInterface#

Result of the session/new request.

PermissionOptionInterface#

A choice offered to the user in a permission request.

PlanEntryInterface#

One entry of an execution plan.

PromptCapabilitiesInterface#

Content types the agent accepts in a prompt. Text and resource links are always accepted.

PromptRequestInterface#

Params of the session/prompt request. Starts one turn of the agent.

PromptResponseInterface#

Result of session/prompt, sent when the turn ends.

ReadTextFileRequestInterface#

Params of the fs/read_text_file request. The agent sends it to read a file through the client.

RequestPermissionRequestInterface#

Params of the session/request_permission request. The agent sends it to ask the user before a tool call runs.

A reference to a resource the agent can fetch. The content is not embedded.

ResumeSessionRequestInterface#

Params of the session/resume request. Restores a stored session without replaying its history.

RunAcpStdioServerOptionsInterface#

Options for runAcpStdioServer: the AcpServerOptions plus the stdio transport settings.

SessionCapabilitiesInterface#

Optional session methods the agent supports. A key being present means the method is available.

SessionConfigOptionInterface#

A session configuration option. ACP v1 currently defines a single select (dropdown) variant; id + name + type are required.

SessionConfigSelectGroupInterface#

A named group of select options.

SessionConfigSelectOptionInterface#

One choice of a select config option.

SessionInfoInterface#

Summary of a stored or open session, returned by session/list.

SessionModeInterface#

A mode the session can run in, such as build or plan.

SessionModeStateInterface#

The modes a session offers and the active one.

SessionNotificationInterface#

Params of the session/update notification, the agent stream to the client.

SetSessionConfigOptionRequestInterface#

Params of the session/set_config_option request.

SetSessionConfigOptionResponseInterface#

Result of session/set_config_option.

SetSessionModeRequestInterface#

Params of the session/set_mode request.

TerminalExitStatusInterface#

How a terminal command ended.

TerminalOutputResponseInterface#

Result of the terminal/output request.

TextContentInterface#

A text content block.

TextResourceContentsInterface#

Embedded resource content in text form.

ToolCallLocationInterface#

A file location a tool call touches.

ToolCallUpdateInterface#

A tool call report or an update to one, carried by tool_call and tool_call_update session updates.

WriteTextFileRequestInterface#

Params of the fs/write_text_file request. The agent sends it to write a file through the client.

Types#

AcpContentMapperType#

Converts tool result content to ACP tool call content.

AcpMcpServerType#

An MCP server the client asks the agent to connect to. stdio servers are launched as a command. http and sse servers are reached by URL.

AcpSessionContentMapperType#

Converts stored session content blocks to ACP content blocks.

ContentBlockType#

A block of content in a prompt or a message.

EmbeddedResourceResourceType#

Contents of an embedded resource, as text or binary.

JsonRpcIdType#

Identifier of a JSON-RPC request.

JsonRpcMessageType#

Any JSON-RPC message: a request, a notification or a response.

JsonRpcResponseType#

A JSON-RPC response, either a success or a failure.

RequestPermissionOutcomeType#

How the user answered a permission request: cancelled, or selected with the chosen optionId.

ResumeSessionResponseType#

Result of session/resume. Same shape as LoadSessionResponse.

RoleType#

Author of a message.

SessionConfigOptionCategoryType#

Semantic category of a config option. Clients use it to place the control. Custom strings are allowed.

SessionConfigSelectOptionsType#

Choices of a select option: a flat list or a list of groups.

SessionUpdateType#

Payload of a session/update notification, discriminated by sessionUpdate. Covers message and thought chunks, tool calls, plans, command lists, mode and config changes, session info and usage.

StopReasonType#

Why a prompt turn ended: end_turn, max_tokens, max_turn_requests, refusal or cancelled.

ToolCallContentType#

Content produced by a tool call: plain content, a file diff, or a terminal reference.

ToolCallStatusType#

Execution status of a tool call.

ToolKindType#

Category of a tool, used by clients for icons and grouping.

Enums#

AcpErrorCodeEnum#

JSON-RPC and ACP error codes used in error responses.