Skip to content

Server

Category: Acp

Source: server.dart

ACP agent server.

Owns the JSON-RPC dispatch loop. Routes incoming initialize, session/new, session/prompt, and session/cancel to a pluggable [AcpServerDelegate]; emits session/update notifications and session/request_permission requests as the delegate runs.

The server itself has no dependency on glue_harness — the delegate is the wiring point. A test can stand up an [AcpServer] with a fake delegate and exercise the full protocol without the real agent loop. The cli's glue acp --stdio provides a production delegate that uses [AgentCore] + SessionManager from glue_harness.

Classes

abstract AcpServerDelegate

Adapter the server calls into for everything that needs harness state. Implementations live above this package (e.g. in the cli).

Properties

PropertyTypeDescription
protocolVersionint
agentInfoAgentInfo
agentCapabilitiesMap<String, Object?>
transportJsonRpcTransport
delegateAcpServerDelegate
configAcpServerConfig
outfinal
diffRawfinal
partsfinal
outreturn

Methods

Future<String> createSession(SessionNewParams params)

Create a new session for the given client params; return its id. The server uses [SessionNewParams.cwd] and mcpServers as opaque inputs — interpretation is up to the delegate.

`Stream<AgentEvent> prompt({
required String sessionId,
required String userMessage,
required Future&lt;bool&gt; Function(ToolCall call) requestPermission,
List&lt;ContentPart&gt; userContentParts = const [],

})`

Run a single prompt turn. Yields [AgentEvent]s as the agent produces them. The server translates events into session/update notifications and synthesises tool-call lifecycle updates around the permission gate.

When a [Tool] call needs permission, the server invokes [requestPermission] (which the delegate routes to its permission gate). The future resolves to true to allow, false to deny.

[userContentParts] carries multimodal input attached to the prompt (images, resource_links). Empty when the client sent only text. Implementations are free to ignore parts they can't represent — but ideally pass them through to the LLM.

void cancelPrompt(String sessionId)

Cancel the active prompt on [sessionId], if any. Best-effort.

UsageReport usageSummary(String sessionId)

Returns a per-role token-usage breakdown for [sessionId]. Surfaces the same data the CLI shows under /usage, in a structure ACP clients can consume directly. Tokens only — no cost / pricing.

Future&lt;void&gt; closeSession(String sessionId)

Close any resources held for [sessionId]. Called on connection teardown.

`const AcpServerConfig({
this.protocolVersion = 1,
this.agentInfo = const AgentInfo(name: 'glue', title: 'Glue'),
this.agentCapabilities = const {},

})`

Future&lt;void&gt; serve()

Drives the dispatch loop until the inbound stream closes.

AcpServerConfig

Static configuration for the ACP server.

Constructor

dart
const AcpServerConfig({
    this.protocolVersion = 1,
    this.agentInfo = const AgentInfo(name: 'glue', title: 'Glue'),
    this.agentCapabilities = const {},
  })

Properties

PropertyTypeDescription
protocolVersionint
agentInfoAgentInfo
agentCapabilitiesMap&lt;String, Object?&gt;

AcpServer

The ACP agent server. Construct, then call [serve] to drive the dispatch loop until the transport closes.

Constructor

dart
AcpServer({
    required this.transport,
    required this.delegate,
    this.config = const AcpServerConfig(),
  })

Properties

PropertyTypeDescription
transportJsonRpcTransport
delegateAcpServerDelegate
configAcpServerConfig

Methods

Future&lt;void&gt; serve()

Drives the dispatch loop until the inbound stream closes.

Released under the MIT License.