transports
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| HttpTransport aclientp.transports Configuration for the Streamable HTTP & WebSocket server transport (experimental). |
||
| StdioTransport aclientp.transports Configuration for stdio transport. |
||
| StreamTransport aclientp.transports Configuration for custom stream transport. |
||
| WebSocketTransport aclientp.transports Configuration for WebSocket server transport. |
🛈 DocStrings¶
Transport abstractions for ACP agents.
This module provides transport configuration classes and utilities for running ACP agents over different transports (stdio, WebSocket, etc.).
V1AgentSource
¶
V1AgentSource = Agent | Callable[[AgentSideConnection], Agent]
A v1 agent, or a factory receiving its connection.
V2AgentSource
¶
V2AgentSource = Agent | Callable[[AgentSideConnection], Agent]
A v2 agent, or a factory receiving its connection.
HttpTransport
dataclass
¶
Configuration for the Streamable HTTP & WebSocket server transport (experimental).
Serves ACP on one endpoint per the transport RFD: Streamable HTTP (POST/GET/DELETE)
and WebSocket upgrade. Each client connection gets its own agent instance. Requires
the bridge extra (starlette, uvicorn).
Attributes:
| Name | Type | Description |
|---|---|---|
host |
str
|
Host to bind to. |
port |
int
|
Port to listen on. |
path |
str
|
Endpoint path. |
authenticate |
Authenticate | None
|
Identifies callers (None rejects with 401); connections belong to their creator. None accepts every caller, for local use only. |
allow_origins |
list[str]
|
CORS origins for browser clients. |
max_buffered_bytes |
int
|
Output a connection may hold for its client before the agent's writes wait. |
max_output_stall |
float
|
Seconds a client may take no output while over that limit before its connection is closed. |
Source code in src/aclientp/transports.py
StdioTransport
dataclass
¶
Configuration for stdio transport.
This is the default transport for ACP agents, communicating over stdin/stdout streams.
Source code in src/aclientp/transports.py
StreamTransport
dataclass
¶
Configuration for custom stream transport.
Allows passing pre-created streams for the agent to use.
Attributes:
| Name | Type | Description |
|---|---|---|
reader |
ByteReceiveStream
|
Stream to read incoming messages from. |
writer |
ByteSendStream
|
Stream to write outgoing messages to. |
Source code in src/aclientp/transports.py
WebSocketTransport
dataclass
¶
Configuration for WebSocket server transport.
Runs an ACP agent as a WebSocket server that accepts client connections. Each client connection gets its own agent instance.
Attributes:
| Name | Type | Description |
|---|---|---|
host |
str
|
Host to bind the WebSocket server to. |
port |
int
|
Port for the WebSocket server. |
Source code in src/aclientp/transports.py
default_environment
¶
Return a trimmed environment based on MCP best practices.
Source code in src/aclientp/transports.py
serve
async
¶
serve(
agent: V1AgentSource | None = None,
transport: Transport = "stdio",
*,
v2_agent: V2AgentSource | None = None,
shutdown_event: Event | None = None,
debug_file: str | None = None,
observers: list[StreamObserver] | None = None,
) -> None
Run an ACP agent with the specified transport.
This is the main entry point for running ACP agents. It handles transport setup and lifecycle management automatically.
With only agent, every client is served by that v1 agent. With v2_agent,
each client connection is routed on initialize
(:class:~aclientp.router.RoutedAgentConnection): clients asking for v2 or later
get the v2 agent, others the v1 agent (if given).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
V1AgentSource | None
|
The v1 agent, or a factory that takes an AgentSideConnection and returns one. |
None
|
transport
|
Transport
|
Transport configuration. Can be: - "stdio" or StdioTransport(): Use stdin/stdout - "websocket" or WebSocketTransport(...): Run WebSocket server - StreamTransport(...): Use custom streams |
'stdio'
|
v2_agent
|
V2AgentSource | None
|
The v2 agent, or a factory that takes a v2 AgentSideConnection and returns one. |
None
|
shutdown_event
|
Event | None
|
Optional event to signal shutdown. If not provided, runs until cancelled. |
None
|
debug_file
|
str | None
|
Optional file path for debug message logging. |
None
|
observers
|
list[StreamObserver] | None
|
Observers of the raw messages of each connection. |
None
|
Example
# Stdio (default)
await serve(MyAgent())
# WebSocket server
await serve(MyAgent(), WebSocketTransport(host="0.0.0.0", port=9000))
# v1 and v2 clients on one endpoint
await serve(MyAgent(), v2_agent=MyV2Agent)
# With shutdown control
shutdown = asyncio.Event()
task = asyncio.create_task(serve(MyAgent(), shutdown_event=shutdown))
# ... later ...
shutdown.set()
await task
Source code in src/aclientp/transports.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
spawn_stdio_transport
async
¶
spawn_stdio_transport(
command: str,
*args: str,
env: Mapping[str, str] | None = None,
cwd: str | Path | None = None,
stderr: int | None = PIPE,
shutdown_timeout: float = 2.0,
log_stderr: bool = False,
stderr_log_level: int = WARNING,
on_stderr: Callable[[str], object] | None = None,
) -> AsyncGenerator[tuple[ByteReceiveStream, ByteSendStream, Process]]
Launch a subprocess and expose its stdio streams as anyio streams.
This mirrors the defensive shutdown behaviour used by the MCP Python SDK: close stdin first, wait for graceful exit, then escalate to terminate/kill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The command to execute. |
required |
*args
|
str
|
Arguments for the command. |
()
|
env
|
Mapping[str, str] | None
|
Environment variables (merged with defaults). |
None
|
cwd
|
str | Path | None
|
Working directory for the subprocess. |
None
|
stderr
|
int | None
|
How to handle stderr (default: subprocess.PIPE). |
PIPE
|
shutdown_timeout
|
float
|
Timeout for graceful shutdown. |
2.0
|
log_stderr
|
bool
|
If True, read stderr in background and log each line. |
False
|
stderr_log_level
|
int
|
Log level for stderr output (default WARNING). |
WARNING
|
on_stderr
|
Callable[[str], object] | None
|
Called with each stderr line (read in background), e.g. to show it in a UI. |
None
|
With stderr=PIPE (the default), stderr is always read in the background, so
an agent writing a lot to it can never block on a full pipe: lines go to
on_stderr and / or the log, and are discarded otherwise. To read
process.stderr yourself, pass another stderr (e.g. a file) instead.