acp

package
v0.4.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package acp implements the JSON-RPC-over-stdio core of the Agent Client Protocol. It deliberately exposes protocol values without depending on the editor, so probes and runners can share one transport implementation.

Index

Constants

View Source
const CodeMethodNotFound = -32601

CodeMethodNotFound is the JSON-RPC error code for a method the receiver does not implement.

Variables

This section is empty.

Functions

func ChoosePermission

func ChoosePermission(req PermissionRequest, editorServer string) (string, error)

ChoosePermission enforces editor policy for an ACP permission request. A call to a tool of the editorServer MCP server (see IsServerTool) whose kind is not edit, delete, move or execute gets the agent's allow_once option. Every other request gets reject_once, and a request without the option it needs fails closed with an error.

func IsServerTool

func IsServerTool(call ToolCallUpdate, server string) bool

IsServerTool reports whether call is a call to a tool of the MCP server named server, as the agent identifies it. ACP has no field for the server, so it accepts the identifications agents send:

  • Gemini CLI's toolCall._meta["gemini-cli"].mcp.server_name;
  • a programmatic Name of the form mcp__<server>__<tool> (Claude Code and Codex), <server>_<tool> (OpenCode) or <server>/<tool>.

Title is display text an agent may compose from anything, so it never counts.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is one side of an ACP connection: it sends requests and notifications to an agent and reads the agent's responses, notifications and requests.

One Call runs at a time and is the only reader of the connection. Writes (requests, responses to the agent's requests and notifications such as session/cancel) take their own lock, so a notification can be sent while a Call waits for its response, as session/cancel is sent during session/prompt.

func New

func New(r io.Reader, w io.Writer) *Client

New returns a client that reads the agent's messages from r and writes its own to w.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params any, onNotification func(Notification) error) (json.RawMessage, error)

Call sends one request and reads until its response. Notifications and requests received before the response are passed to onNotification in arrival order; a request is answered with a method-not-found error when onNotification is nil.

func (*Client) Cancel

func (c *Client) Cancel(params any) error

Cancel sends the session/cancel notification for the session params names. The agent then ends the prompt in progress with the cancelled stop reason.

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context, params any, on func(Notification) error) (json.RawMessage, error)

Initialize sends initialize.

func (*Client) Notify

func (c *Client) Notify(method string, params any) error

Notify sends a notification. It does not wait for a Call in progress, so session/cancel reaches the agent while session/prompt waits for its response.

func (*Client) Prompt

func (c *Client) Prompt(ctx context.Context, params any, on func(Notification) error) (json.RawMessage, error)

Prompt sends session/prompt.

func (*Client) Respond

func (c *Client) Respond(id json.RawMessage, result any, rpcErr *RPCError) error

Respond answers a request the agent sent, received by the notification callback, with result or with rpcErr when it is set.

func (*Client) SessionLoad

func (c *Client) SessionLoad(ctx context.Context, params any, on func(Notification) error) (json.RawMessage, error)

SessionLoad sends session/load, which agents answer after replaying the session's history as session/update notifications.

func (*Client) SessionNew

func (c *Client) SessionNew(ctx context.Context, params any, on func(Notification) error) (json.RawMessage, error)

SessionNew sends session/new.

func (*Client) SessionResume

func (c *Client) SessionResume(ctx context.Context, params any, on func(Notification) error) (json.RawMessage, error)

SessionResume sends session/resume, which continues a session without replaying it.

func (*Client) SessionSetConfigOption

func (c *Client) SessionSetConfigOption(ctx context.Context, params any, on func(Notification) error) (json.RawMessage, error)

SessionSetConfigOption sends session/set_config_option.

func (*Client) SessionSetModel

func (c *Client) SessionSetModel(ctx context.Context, params any, on func(Notification) error) (json.RawMessage, error)

SessionSetModel sends session/set_model, the older way to pick a model that agents such as Gemini CLI still implement in place of a model config option.

type Notification

type Notification struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
}

Notification is a message the agent sent while a Call waited: a notification when ID is empty, or a request the client must answer with Respond when ID is set. JSON-RPC allows a number or a string as an ID, so ID keeps the agent's bytes.

func (Notification) IsRequest

func (n Notification) IsRequest() bool

IsRequest reports whether n is a request that expects a response.

type PermissionOption

type PermissionOption struct {
	OptionID string `json:"optionId"`
	Name     string `json:"name,omitempty"`
	Kind     string `json:"kind"`
}

PermissionOption is one of the choices an agent offers in session/request_permission.

type PermissionRequest

type PermissionRequest struct {
	SessionID string             `json:"sessionId"`
	ToolCall  ToolCallUpdate     `json:"toolCall"`
	Options   []PermissionOption `json:"options"`
}

PermissionRequest is the params of session/request_permission.

type RPCError

type RPCError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

RPCError is a JSON-RPC error object.

type Request

type Request struct {
	JSONRPC string `json:"jsonrpc"`
	ID      uint64 `json:"id"`
	Method  string `json:"method"`
	Params  any    `json:"params,omitempty"`
}

Request is a JSON-RPC request the client sends.

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id"`
	Result  json.RawMessage `json:"result"`
	Error   *RPCError       `json:"error,omitempty"`
}

Response is a JSON-RPC response to one of the client's requests.

type ToolCallUpdate

type ToolCallUpdate struct {
	ToolCallID string          `json:"toolCallId"`
	Title      string          `json:"title,omitempty"`
	Name       string          `json:"name,omitempty"`
	Kind       string          `json:"kind,omitempty"`
	Meta       json.RawMessage `json:"_meta,omitempty"`
}

ToolCallUpdate is the tool call a permission request is about. Title is display text; Name, when the agent sends it, is the tool's programmatic name; Kind is one of ACP's tool kinds (read, edit, delete, move, search, execute, think, fetch, switch_mode, other).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL