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
| Property | Type | Description |
|---|---|---|
protocolVersion | int | |
agentInfo | AgentInfo | |
agentCapabilities | Map<String, Object?> | |
transport | JsonRpcTransport | |
delegate | AcpServerDelegate | |
config | AcpServerConfig | |
out | final | |
diffRaw | final | |
parts | final | |
out | return |
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<bool> Function(ToolCall call) requestPermission,
List<ContentPart> 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<void> 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<void> serve()
Drives the dispatch loop until the inbound stream closes.
AcpServerConfig
Static configuration for the ACP server.
Constructor
const AcpServerConfig({
this.protocolVersion = 1,
this.agentInfo = const AgentInfo(name: 'glue', title: 'Glue'),
this.agentCapabilities = const {},
})Properties
| Property | Type | Description |
|---|---|---|
protocolVersion | int | |
agentInfo | AgentInfo | |
agentCapabilities | Map<String, Object?> |
AcpServer
The ACP agent server. Construct, then call [serve] to drive the dispatch loop until the transport closes.
Constructor
AcpServer({
required this.transport,
required this.delegate,
this.config = const AcpServerConfig(),
})Properties
| Property | Type | Description |
|---|---|---|
transport | JsonRpcTransport | |
delegate | AcpServerDelegate | |
config | AcpServerConfig |
Methods
Future<void> serve()
Drives the dispatch loop until the inbound stream closes.