Classes
ChildProcess
15
▼
A persistent child process that speaks JSON-RPC on stdin/stdout.
Thread-safe: a lock serializes al…
ChildProcess
15
▼
A persistent child process that speaks JSON-RPC on stdin/stdout.
Thread-safe: a lock serializes all calls to the same child. Auto-reconnects if the child process dies.
Methods
protocol_mode
0
str
▼
Return the negotiated child protocol mode for diagnostics.
property
protocol_mode
0
str
▼
def protocol_mode(self) -> str
Returns
str
protocol_version
0
str | None
▼
Return the negotiated child protocol version, if known.
property
protocol_version
0
str | None
▼
def protocol_version(self) -> str | None
Returns
str | None
last_error
0
str
▼
Return the last child JSON-RPC or transport error seen by the gateway.
property
last_error
0
str
▼
def last_error(self) -> str
Returns
str
ensure_alive
0
▼
Spawn or reconnect if the child process is dead.
ensure_alive
0
▼
def ensure_alive(self) -> None
send_call
3
dict[str, Any]
▼
Send a JSON-RPC request and return the result. Thread-safe.
*timeout* override…
send_call
3
dict[str, Any]
▼
def send_call(self, method: str, params: dict[str, Any], *, timeout: float | None = None) -> dict[str, Any]
Send a JSON-RPC request and return the result. Thread-safe.
timeout overrides the instancerequest_timeoutfor this call.
Parameters
| Name | Type | Description |
|---|---|---|
method |
— |
|
params |
— |
|
timeout |
— |
Default:None
|
Returns
dict[str, Any]
fetch_tools
0
list[dict[str, Any]]
▼
Fetch tools/list from the child process.
fetch_tools
0
list[dict[str, Any]]
▼
def fetch_tools(self) -> list[dict[str, Any]]
Returns
list[dict[str, Any]]
is_idle
0
bool
▼
Check if the child has been idle longer than idle_timeout.
is_idle
0
bool
▼
def is_idle(self) -> bool
Returns
bool
kill
0
▼
Kill the child process.
kill
0
▼
def kill(self) -> None
Internal Methods 7 ▼
__init__
4
▼
__init__
4
▼
def __init__(self, name: str, command: list[str], *, idle_timeout: float = 300.0, request_timeout: float = 30.0) -> None
Parameters
| Name | Type | Description |
|---|---|---|
name |
— |
|
command |
— |
|
idle_timeout |
— |
Default:300.0
|
request_timeout |
— |
Default:30.0
|
_spawn
0
▼
Start the child process with persistent pipes.
_spawn
0
▼
def _spawn(self) -> None
_ensure_initialized
0
▼
Negotiate enough protocol context for child calls.
Milo still speaks the initi…
_ensure_initialized
0
▼
def _ensure_initialized(self) -> None
Negotiate enough protocol context for child calls.
Milo still speaks the initialization-based 2025-11-25 protocol, but
newer MCP revisions probe withserver/discoverand may omit
initializeentirely. The gateway can therefore talk to both eras.
_graceful_kill
0
▼
SIGTERM with grace period, then SIGKILL if needed.
Must be called while holdin…
_graceful_kill
0
▼
def _graceful_kill(self) -> None
SIGTERM with grace period, then SIGKILL if needed.
Must be called while holdingself._lock.
_write_line
1
▼
Write a line to the child's stdin.
_write_line
1
▼
def _write_line(self, line: str) -> None
Parameters
| Name | Type | Description |
|---|---|---|
line |
— |
_read_response
2
dict[str, Any]
▼
Read frames until the response matching *req_id* arrives.
_read_response
2
dict[str, Any]
▼
def _read_response(self, req_id: int, *, timeout: float | None = None) -> dict[str, Any]
Parameters
| Name | Type | Description |
|---|---|---|
req_id |
— |
|
timeout |
— |
Default:None
|
Returns
dict[str, Any]
_read_line
1
str
▼
Read a line from the child's stdout with timeout.
Uses a background thread so …
_read_line
1
str
▼
def _read_line(self, *, timeout: float | None = None) -> str
Read a line from the child's stdout with timeout.
Uses a background thread so we can enforce a deadline even when the child blocks without writing a newline.
Parameters
| Name | Type | Description |
|---|---|---|
timeout |
— |
Default:None
|
Returns
str