Reference

API reference

Every public function, type and trait, generated from the sources and their documentation. Three packages: the protocol itself, and the two server transports.

moonacp203 items

The protocol, its types, and the contracts on both sides.

Values83

fnPromptCapabilities::none
() -> PromptCapabilities

Nothing supported: no images, no audio, no embedded context.

fnMcpCapabilities::none
() -> McpCapabilities

No MCP transport supported.

fnSessionCapabilities::none
() -> SessionCapabilities

No session method beyond session/new.

fnAgentAuthCapabilities::none
() -> AgentAuthCapabilities

No authentication step offered.

fnAgentCapabilities::none
() -> AgentCapabilities

An agent that supports only session/new and session/prompt.

fnFileSystemCapabilities::none
() -> FileSystemCapabilities

No file access granted.

fnClientAuthCapabilities::none
() -> ClientAuthCapabilities

No terminal authentication offered by the client.

fnClientSessionCapabilities::none
() -> ClientSessionCapabilities

No supplementary session features.

fnElicitationCapabilities::none
() -> ElicitationCapabilities

No elicitation kind supported.

fnClientCapabilities::none
() -> ClientCapabilities

A client that reads and writes nothing, runs nothing, and answers no ask.

fnImplementation::new
(name : String, version : String) -> Implementation

A name and a version, which is all the protocol asks for.

fnConfigCategory::to_string
(self : ConfigCategory) -> String

The name the category travels as.

fnConfigCategory::of
(name : String) -> ConfigCategory

The category with that name; unknown names are kept as they came.

fnconnect
(client : &Client, frames : &@peer.Frames) -> Conn

Wires a client to a transport. The caller runs the returned connection, which is what delivers updates and answers the agent's calls.

fnConn::run
(self : Conn) -> Unit

Takes messages in until the other side goes away. Updates reach the client from here, so it has to run in a task of its own while the other tasks call the agent.

fnConn::call
( self : Conn, name : String, params : Json, ) -> Json raise Refused

A call the protocol does not name: send it raw and read the answer raw.

fnConn::notify
( self : Conn, name : String, params : Json, ) -> Unit raise Refused

A notice the protocol does not name.

fnConn::initialize
( self : Conn, request : Initialize, ) -> Initialized raise Refused

Negotiates the version and trades capabilities. Call it once, before anything else.

fnConn::authenticate
( self : Conn, request : Authenticate, ) -> Unit raise Refused

Runs one of the agent's authentication methods.

fnConn::logout
(self : Conn) -> Unit raise Refused

Drops whatever authenticate established.

fnConn::new_session
( self : Conn, request : NewSession, ) -> SessionStarted raise Refused

Starts a session and returns what the agent says about it: identifier, modes, options.

fnConn::load_session
( self : Conn, request : LoadSession, ) -> SessionStarted raise Refused

Reopens a session; the updates that replay its history arrive on run.

fnConn::resume_session
( self : Conn, request : ResumeSession, ) -> SessionStarted raise Refused

Reattaches to a live session without replaying anything.

fnConn::list_sessions
( self : Conn, request : ListSessions, ) -> SessionList raise Refused

The sessions the agent remembers, one page at a time.

fnConn::delete_session
( self : Conn, request : DeleteSession, ) -> Unit raise Refused

Forgets a session.

fnConn::close_session
( self : Conn, request : CloseSession, ) -> Unit raise Refused

Ends a running session, as if session/cancel had been sent.

fnConn::set_mode
( self : Conn, request : SetMode, ) -> Unit raise Refused

Switches the session's mode.

fnConn::set_config_option
( self : Conn, request : SetConfigOption, ) -> Array[ConfigOption] raise Refused

Sets one configuration option and returns the whole list, as the protocol requires.

fnConn::prompt
( self : Conn, request : Prompt, ) -> PromptResult raise Refused

Sends one turn and waits for its answer. Updates arrive through the client's update while this waits, because the connection is being run in another task.

fnConn::cancel
( self : Conn, session_id : String, ) -> Unit raise Refused

Asks the agent to stop the turn running in a session. A notice: nothing comes back, and the turn answers Cancelled on its own.

fnConn::client
(self : Conn) -> &Client

The client this connection feeds.

fnRole::to_string
(self : Role) -> String

The name the role travels as.

fnRole::of
(name : String) -> Role?

The role with that name, or None.

fnTerminalRef::new
(terminal_id : String) -> TerminalRef

A reference to a terminal, as a tool call embeds it.

fnStringFormat::to_string
(self : StringFormat) -> String

The name the format travels as.

fnStringFormat::of
(name : String) -> StringFormat?

The format with that name, or None.

letparse_error
: Int32 = -32700

The text is not JSON.

letinvalid_request
: Int32 = -32600

The value is not a valid message.

letmethod_not_found
: Int32 = -32601

Nobody handles that method.

letinvalid_params
: Int32 = -32602

The parameters are not what the method takes.

letinternal_error
: Int32 = -32603

The handler failed for its own reasons.

letrequest_cancelled
: Int32 = -32800

The caller asked for the work to stop.

letauthentication_required
: Int32 = -32000

The client has to authenticate before this method works.

letresource_not_found
: Int32 = -32002

A path, a session or a resource named in the request does not exist.

fnRefused::new
(code : Int32, message : String, data? : Json) -> Refused

An error object with a code of your choosing.

fnRefused::code
(self : Refused) -> Int32

The code this failure travels as.

fnRefused::message
(self : Refused) -> String

What the other side reads.

fnRefused::data
(self : Refused) -> Json?

Anything else attached to the failure.

fnRefused::failure
(self : Refused) -> @moonjrpc.Failure

The wire form of a failure.

fnfailure_of
(error : Error) -> @moonjrpc.Failure

Turns anything a handler raised into the error object to send: the wire code is kept, and anything that is not a Refused becomes -32603 with no detail, because what a handler trips over is not the caller's to read.

fnrefused_of
(failure : @moonjrpc.Failure) -> Refused

The reverse, for a call that came back with an error object.

letprotocol_version
: Int32 = 1

The protocol version this library speaks. It only changes when the protocol breaks.

fnInitialized::new
() -> Initialized

A first answer for an agent that supports nothing beyond session/new: the version, no capabilities, no authentication.

fnStopReason::to_string
(self : StopReason) -> String

The name the reason travels as.

fnStopReason::of
(name : String) -> StopReason?

The reason with that name, or None.

fnserve
(agent : &Agent, frames : &@peer.Frames) -> @peer.Peer

Serves an agent over any transport: the caller runs the returned peer. Messages are answered in the order they arrive, and batches are refused, because the protocol has none.

fnSession::id
(self : Session) -> String

The session's identifier, the one the client sent with session/new.

fnSession::update
( self : Session, update : SessionUpdate, ) -> Unit raise Refused

Sends one update. Updates are notifications, so they are never answered and never fail the turn by themselves; the connection going away raises Closed.

fnSession::request_permission
( self : Session, ask : Permission, ) -> Outcome raise Refused

Asks the user to allow a tool call. The client answers with the option it picked, or Cancelled when the prompt was dismissed; a client that never answers blocks the turn, so keep the ask in the turn's own task.

fnSession::read_text_file
( self : Session, path : String, line? : Int64, limit? : Int64, ) -> String raise Refused

Reads a text file through the client, sliced from line when one is given.

fnSession::write_text_file
( self : Session, path : String, content : String, ) -> Unit raise Refused

Writes a text file through the client.

fnSession::terminal
( self : Session, command : String, args? : Array[String], env? : Array[EnvVariable], cwd? : String, output_byte_limit? : Int64, ) -> Terminal raise Refused

Runs a command in a terminal the client owns. The returned handle reads, waits for, kills and releases it.

fnSession::elicit
( self : Session, ask : Elicitation, ) -> Answer raise Refused

Asks the user for a few fields or for a visit to a URL. The ask is scoped to this session, and to the tool call it came from when one is given.

fnTerminal::id
(self : Terminal) -> String

The identifier the client gave this terminal.

fnTerminal::output
(self : Terminal) -> TerminalOutput raise Refused

Everything the command has printed so far.

fnTerminal::wait
(self : Terminal) -> ExitStatus raise Refused

Waits for the command to exit and reports how it did.

fnTerminal::kill
(self : Terminal) -> Unit raise Refused

Stops the command without giving the terminal back.

fnTerminal::release
(self : Terminal) -> Unit raise Refused

Gives the terminal back. The client may reuse it for the next command.

fnTerminal::reference
(self : Terminal) -> TerminalRef

The terminal as a tool call refers to it, for ToolCallContent.

fnPlanEntryPriority::to_string
(self : PlanEntryPriority) -> String

The name the priority travels as.

fnPlanEntryPriority::of
(name : String) -> PlanEntryPriority?

The priority with that name, or None.

fnPlanEntryStatus::to_string
(self : PlanEntryStatus) -> String

The name the status travels as.

fnPlanEntryStatus::of
(name : String) -> PlanEntryStatus?

The status with that name, or None.

fnSeverity::to_string
(self : Severity) -> String

The name the severity travels as.

fnSeverity::of
(name : String) -> Severity

The severity with that name; unknown names are kept as they came.

fnCompactionStatus::to_string
(self : CompactionStatus) -> String

The name the state travels as.

fnCompactionStatus::of
(name : String) -> CompactionStatus

The state with that name; unknown names are kept as they came.

fnToolKind::to_string
(self : ToolKind) -> String

The name the kind travels as.

fnToolKind::of
(name : String) -> ToolKind?

The kind with that name, or None.

fnToolCallStatus::to_string
(self : ToolCallStatus) -> String

The name the status travels as.

fnToolCallStatus::of
(name : String) -> ToolCallStatus?

The status with that name, or None.

fnPermissionOptionKind::to_string
(self : PermissionOptionKind) -> String

The name the option kind travels as.

fnPermissionOptionKind::of
(name : String) -> PermissionOptionKind?

The option kind with that name, or None.

Errors1

errorRefused

What a handler raises, and what the other side's error object becomes when a call fails. A variant's code is the JSON-RPC code it travels as: Refused(code~, ..) carries the wire code itself, Unsupported is -32601, Malformed is -32602.

Types and methods117

typePromptCapabilities

Content kinds the agent accepts inside a prompt.

typeMcpCapabilities

MCP transports the agent can connect to.

typeSessionCapabilities

Session methods beyond session/new. Each flag is a promise to answer that method.

typeAgentAuthCapabilities

Authentication the agent offers.

typeAgentCapabilities

Everything the agent says it can do, sent back from initialize.

typeFileSystemCapabilities

Files the client lets the agent read and write on its behalf.

typeClientAuthCapabilities

Whether the client runs terminal commands for the agent.

typeClientSessionCapabilities

The client's support for supplementary session features.

typeElicitationCapabilities

Elicitation kinds the client can show.

typeClientCapabilities

Everything the client says it can do, sent with initialize.

typeImplementation

A name and version, for the log and the about box.

typeAuthMethod

An authentication method the agent offers, one of two shapes tagged by type on the wire; the agent-driven one carries no tag.

typeAuthMethodTerminal

The client runs a command to authenticate.

typeAuthMethodAgent

The agent runs the flow itself once authenticate is called.

typeReadTextFile

A text file to read.

typeFileText

What a read returns.

typeWriteTextFile

A text file to write, whole.

typeTerminalCommand

A command to run in a new terminal.

typeTerminalOpened

The identifier of the terminal the client opened.

typeTerminalRequest

Names an existing terminal, for terminal/output, terminal/wait_for_exit, terminal/kill and terminal/release.

typeExitStatus

How a command ended.

typeTerminalOutput

What a terminal has printed so far, and whether it has exited.

typeSessionMode

One mode the agent can work in.

typeSessionModes

The modes on offer and the one in force.

typeConfigCategory

What a configuration option is about, so a client can place it. Unknown categories are kept.

typeConfigChoice

One value of a dropdown.

typeConfigGroup

Choices under a heading.

typeConfigChoices

The choices of a dropdown, flat or grouped. The two are told apart by whether the first entry carries group.

typeConfigValue

What a configuration option holds: a picked value or a switch.

typeConfigOption

One entry of the session configuration picker.

typeSessionStarted

What session/new and its siblings answer with.

typeSetConfigOptions

The whole option list after one of them changed.

typeConn

A connection to an agent, from the editor's side. run takes messages in; the methods here send them out and wait for their answers.

typeRole

Who a piece of content is for.

typeAnnotations

Hints for how a client shows a piece of content.

typeTextContent

Text the model reads or writes.

typeImageContent

An image, base64 in data.

typeAudioContent

Audio, base64 in data.

typeResourceLink

A resource the client can read, named by URI rather than by value.

typeTextResource

Resource contents carried as text.

typeBlobResource

Resource contents carried as base64 in blob.

typeResource

Either kind of embedded resource contents, told apart by text against blob.

typeEmbeddedResource

A resource carried by value inside a message.

typeContentBlock

One displayable piece of a prompt or of a tool's output, tagged by type on the wire.

typeContent

A standard content block wrapped for a tool call's output.

typeDiff

A file edit, given as the whole file before and after.

typeTerminalRef

A reference to a terminal the client opened, embedded in a tool call.

typeToolCallContent

What a tool call produced, tagged by type on the wire.

typeToolCallLocation

A place in the workspace a tool touched.

typeStringFormat

A string field's format hint.

typeEnumOption

One titled choice of a string field.

typeTextField

A field the user types into.

typeNumberField

A field for a fractional number.

typeIntegerField

A field for a whole number.

typeBooleanField

A field for yes or no.

typeChoiceItems

What a multi-select offers: bare values or titled ones.

typeMultiSelectField

A field for picking several of a set.

typeField

One field of a form, tagged by type on the wire. A kind the protocol does not define yet is kept as it came so a client can still show it.

typeElicitationSchema

The form to render.

typeElicitScope

Which request an elicitation belongs to: a session's turn, or a bare JSON-RPC request.

typeFormRequest

A form for the user to fill in.

typeUrlRequest

A link the user follows.

typeElicitation

An ask, tagged by mode on the wire.

typeAnswer

What the user did with the ask. content holds one value per field, of whatever type the field asked for, so it stays raw.

typeHttpHeader

One header sent to an MCP server.

typeEnvVariable

One environment variable for a spawned MCP server.

typeMcpHttp

An MCP server reached over HTTP.

typeMcpSse

An MCP server reached over the older HTTP plus SSE transport.

typeMcpStdio

An MCP server the client is to launch as a child process.

typeMcpServer

An MCP server a session may use. The wire tells the two HTTP shapes apart by type; the stdio shape carries no tag at all.

typeInitialize

Opens the conversation: versions and capabilities, once per connection.

typeInitialized

The answer to initialize.

typeAuthenticate

Names one of the methods from initialize.

typeNewSession

Starts a conversation. The working directory is where the agent reads and writes.

typeLoadSession

Reopens a session and replays its history as updates.

typeResumeSession

Reattaches to a session without replaying its history.

typeListSessions

Asks for the sessions the agent remembers.

typeSessionInfo

One row of session/list.

typeSessionList

The page of sessions, and the cursor for the next one.

typeDeleteSession

Removes a session from what session/list returns.

typeCloseSession

Ends a session that is still running.

typeSetMode

Picks a mode.

typeConfigValueId

Sets a configuration option. The wire has two shapes, a value id or a boolean, told apart by type.

typeSetConfigOption

Sets one configuration option.

typePrompt

One turn of the conversation.

typeStopReason

Why the agent stopped.

typePromptResult

The answer to a prompt: why the turn ended.

typeCancel

Stops whatever turn is running in a session. A notification, so it is never answered.

typeSession

One session, as the agent sees it inside prompt. Everything here is a call to the client: updates, permission, files, terminals, elicitation.

typeTerminal

A command running in a terminal the client owns. Holding one is not owning a process: release hands the terminal back, and the exit status is only known after wait.

typeContentChunk

One streamed item of content.

typePlanEntryPriority

How urgent a plan entry is.

typePlanEntryStatus

How far a plan entry got.

typePlanEntry

One step of the agent's plan.

typePlan

The whole plan, replacing whatever came before.

typeCommandInput

The text typed after a command's name, offered to the user as a hint.

typeAvailableCommand

A slash command the user may type.

typeAvailableCommands

The command list, replacing whatever came before.

typeModeChanged

The session's mode changed.

typeSessionInfoChanged

The session's metadata changed; only the fields that changed are present.

typeCost

What the turn cost, in whatever currency the agent bills in.

typeUsage

How much of the context window the conversation fills.

typeSeverity

How loud a notice is. Unknown severities are kept as they came.

typeNotice

Something to tell the user that is not part of the conversation.

typeCompactionStatus

Where a context compaction got to. Unknown states are kept as they came.

typeCompaction

A compaction, created the first time its identifier is seen and updated after that.

typeCompactionSummary

One more block of a compaction's retained summary.

typeSessionUpdate

Everything the agent may tell the client mid-turn, tagged by sessionUpdate on the wire.

typeSessionNotification

One update as it travels: the session it belongs to and the update itself.

typeToolKind

What kind of thing a tool does, for a client that wants to pick an icon.

typeToolCallStatus

How far a tool call got.

typeToolCall

A tool call the model has asked for.

typeToolCallUpdate

A later change to a tool call: only what changed is present.

typePermissionOptionKind

What choosing an option means, so a client can group the buttons.

typePermissionOption

One button in a permission prompt.

typePermission

The ask the agent makes: run this tool call, and here is what the user may choose.

typeOutcome

What came back: one option chosen, or the ask dismissed.

Traits2

trait(open) trait Agent

The agent side. Implement what the agent can do and leave the rest: initialize and new_session and prompt are the three every agent has, the others have defaults that report themselves as unsupported.

trait(open) trait Client

The client side. update is the only method the protocol requires; the rest exist so the agent can ask for them, and a client that leaves one out answers -32601 when the agent asks.

moonacp/stdio5 items

Serving an agent on the process's own streams.

Values4

fnserve_stdio
(agent : &@moonacp.Agent) -> Unit

Runs an agent on the process's own stdin and stdout until the client closes stdin. This is the transport an editor uses when it launches an agent: one JSON-RPC message per line, nothing else on stdout, diagnostics on stderr.

fnspawn
( client : &@moonacp.Client, command : Array[String], args? : Array[String], env? : Map[String, String], cwd? : StringView, ) -> Child

Starts command with args and connects to it as a client. The command is an absolute path or something the system can find on PATH; the first array element is the program.

fnChild::conn
(self : Child) -> @moonacp.Conn

The connection to the child, runnable and callable.

fnChild::close
(self : Child) -> Unit

Closes the child's input, which is how an agent learns the client is done: it finishes what it is doing and exits. The read side ends with it, so a task blocked on run comes back.

Types and methods1

typeChild

A child process speaking the protocol on its pipes.

moonacp/asgi3 items

Serving an agent over HTTP streams and a WebSocket.

Values2

fnto_asgi
( agent : &@moonacp.Agent, path~ : String = "/acp", hosts? : Array[String], limits~ : Limits = limits, ) -> @moonasgi.AsgiApp

Serves an agent over ASGI: one path, four verbs, and a WebSocket upgrade. Nothing is global, so several agents can be mounted side by side.

letlimits
: Limits =

The defaults: 1 MiB bodies, 256 buffered messages per stream, a keepalive every 15 seconds, and half a minute for initialize.

Types and methods1

typeLimits

The transport's bounds.

Generated by scripts/gen_api.py. GitHub