Skip to content

Agent Client Protocol (ACP)

microharness includes a zero-dependency Agent Client Protocol (ACP) server (core/acp.py) speaking newline-delimited JSON-RPC 2.0 over stdio. Editors and orchestrators such as Zed, JetBrains IDEs, and T3 Code can launch microharness as a headless coding agent backend while keeping AgentLoop completely protocol-agnostic.


Launching the ACP Server

Run microharness acp (or pass --acp):

# Default workspace & configured provider/model
uv run microharness acp

# Explicit provider, model, and interactive permission prompts
uv run microharness acp --provider openrouter --model anthropic/claude-5.5-sonnet --permission-mode ask

# Sandboxed / offline-hardened ACP backend
uv run microharness acp --sandbox --no-network-tools --no-mcp

Stream Separation (stdout vs. stderr)

  • stdout is reserved strictly for newline-delimited JSON-RPC 2.0 responses, notifications, and server-to-client requests.
  • stderr receives all diagnostic logs, warnings, model connection banners, and plugin notices (sys.stdout is redirected to sys.stderr before CLI/model/harness setup).

Setting Up in T3 Code & Other ACP Clients

Install microharness once so ACP clients can launch it from any workspace directory without uv run environment-resolution overhead:

# From PyPI (once released)
uv tool install microharness

# Or track a local git checkout cleanly
uv tool install --editable /path/to/microharness

Ensure global credentials and default model configuration exist in ~/.microharness/auth.json and ~/.microharness/config.json:

microharness auth login openrouter   # or google-ai-studio / openai / etc.

In T3 Code (Local command):

  • Executable: /Users/<you>/.local/bin/microharness (use the full path from which microharness, since desktop apps may not inherit shell PATH)
  • Arguments (one argument per row):
  • acp
  • (Optional) --permission-mode and ask to route mutating tool approvals to T3 Code cards
  • (Optional) --no-mcp to skip connecting configured MCP servers during session/new for faster session startup

Option 2: Direct from a Local Checkout (uv run)

If you prefer running directly from the repository without uv tool install, always pass --directory so uv resolves the microharness project regardless of the ACP client's working directory:

  • Executable: /path/to/uv (e.g., /Users/<you>/.local/bin/uv)
  • Arguments:
  • run
  • --directory
  • /path/to/microharness
  • microharness
  • acp

Avoid bare uv run microharness acp in ACP clients

Passing uv + ["run", "microharness", "acp"] without --directory causes test sessions and external workspaces to fail ("The ACP agent could not create a test session") because uv run looks for pyproject.toml in the client's working directory instead of the microharness checkout. Calling the installed microharness binary directly also avoids uv run startup checks.


Supported Protocol Surface (ACP v1)

Lifecycle & Session Methods

Method Direction Behavior
initialize Client → Agent Negotiates protocolVersion (1), returns agentInfo (microharness, package version) and agentCapabilities (loadSession, sessionCapabilities.close, sessionCapabilities.list, promptCapabilities.image, promptCapabilities.embeddedContext, mcpCapabilities.http/sse).
session/new Client → Agent Validates an absolute workspace cwd, sanitizes client-supplied mcpServers, initializes an isolated Harness + AgentLoop session returning {sessionId, models, modes, configOptions}, and emits initial available_commands_update and usage_update notifications.
session/load Client → Agent Resumes a persisted session from runs_dir (trace.json / trajectory.jsonl via load_session), replays text and image conversation history via session/update, emits available_commands_update + usage_update, and returns {models, modes, configOptions}.
session/list Client → Agent Lists active and persisted sessions (supporting optional cwd workspace filtering and cursor pagination) with sessionId, cwd, title, and ISO-8601 updatedAt.
session/set_config_option Client → Agent Dynamically switches session model, thought_level (off, low, medium, high, xhigh, max), mode (auto, ask, read-only), or cache_ttl (5m, 1h, off) and emits config_option_update (plus usage_update on model switches; legacy session/set_model and session/set_mode are also supported).
session/prompt Client → Agent Maps text, image (base64 data / mimeType or HTTP/data uri), resource, and resource_link prompt blocks into Message content, dispatches built-in slash commands (/compact, /undo, /status, /new) and custom commands / skills (/skill, /agent, /<command>), streams live session/update notifications on a worker thread, and returns {stopReason, usage?} (end_turn, cancelled, max_turn_requests, or refusal, plus per-turn inputTokens, outputTokens, totalTokens, and optional cachedReadTokens when reported).
session/cancel Client → Agent (Notification) Triggers cooperative mid-turn cancellation (CancellableModel.set_cancel_probe), aborts pending reverse requests for the session, drops incomplete tool turns cleanly, and resolves the active session/prompt with stopReason: "cancelled".
session/close Client → Agent Cancels any active turn on the session, tears down ToolProviders and Environment, and finalizes trace.json / trace.md.

Live Streaming (session/update)

  • available_commands_update: Emitted when a session is created or loaded, advertising built-in ACP commands (compact, undo, status, new, skill, agent) alongside discovered project/global commands and skills.
  • agent_thought_chunk: Emitted from StreamingModel STREAM_REASONING deltas (or non-streaming assistant reasoning fields), as well as child subagent step action summaries (↳ [agent] ...).
  • agent_message_chunk: Emitted from StreamingModel STREAM_TEXT deltas (or non-streaming assistant content).
  • tool_call / tool_call_update: Emitted via PRE_TOOL / POST_TOOL hooks with core/tracer.py action titles, ACP kind (read, edit, search, execute, think, fetch, other), locations, rawInput, rawOutput, status (pending → in_progress → completed / failed), structured diff content blocks (path, oldText, newText) on successful edit_file / write_file calls, and live terminal content blocks (terminalId) when delegating bash to client terminals.
  • usage_update: Emitted on session start/load, after each step, on cancellation rollback, and when switching models with calibrated active context occupancy (used) and the active model's context window capacity (size).

Permissions, Client Callbacks & Security Guards

session/request_permission (--permission-mode ask)

When running with --permission-mode ask, GuardedEnvironment.confirm_action issues a bidirectional session/request_permission request to the client with four options (allow_once, allow_always, reject_once, reject_always).

  • allow_always and reject_always are cached per action within the session.
  • Denials, cancelled outcomes, timeouts, malformed responses, and stdin disconnects fail closed.

Client fs/* & terminal/* Delegation

When the client advertises clientCapabilities.fs.readTextFile, clientCapabilities.fs.writeTextFile, or clientCapabilities.terminal (and neither --sandbox nor --docker is active):

  • AcpClientEnvironment delegates workspace file reads/writes (fs/read_text_file, fs/write_text_file) and shell execution (terminal/create, terminal/wait_for_exit, terminal/output, terminal/kill, terminal/release) to the client.
  • Environment.resolve_read_path / resolve_path path-traversal checks and GuardedEnvironment (read-only / ask) checks still execute before any client callback is issued, and reads outside the workspace (such as spilled logs or ~/.microharness/skills/) stay local.

Client-Supplied mcpServers Trust Boundary

sanitize_acp_mcp_servers validates mcpServers passed in session/new / session/load:

  • Rejects reserved internal bypass keys (scope, allow_in_sandbox, sandbox, required) and env: / bearer env: secret indirections.
  • Validates http/https URLs and stdio command/args/env schemas.
  • Respects --no-mcp, --no-network-tools, --sandbox/--docker, and --trust-project-tools (project .microharness/config.json servers and .microharness/tools/*.py remain blocked unless --trust-project-tools is set).

Declarative Defaults

Operational ACP defaults live in core/defaults.json:

Key Default Description
acp_protocol_version 1 Negotiated ACP protocol version
acp_request_timeout 300.0 Timeout (seconds) for server-to-client requests
acp_max_steps_per_turn 30 Default step budget per session/prompt turn
acp_max_sessions 32 Maximum concurrent active sessions per ACP process
acp_max_message_bytes 10485760 Maximum incoming JSON-RPC frame size (10 MiB)
acp_cancel_join_timeout 5.0 Grace timeout (seconds) when joining worker threads on close/EOF
acp_session_list_limit 50 Page size returned per session/list response
acp_session_scan_limit 500 Maximum persisted sessions scanned per session/list call