Skip to main content
Glama
aiterm-mcp
by kitepon

stream_read

Read raw stream-json output lines from a Claude or Codex agent seat using a cursor, optionally waiting for new lines or state changes such as pending answer requests.

Instructions

machine席(agent_launch harness:claude-machine のClaude席、またはcodex-machineのCodex席)の出力をデータで読む。claude -p stream-json(Codexは codex app-server のJSON-RPC)のstdoutの行を、解釈も整形もせず、そのまま返す(assistant・user・system・result・rate_limit_event・control_request(can_use_tool、AskUserQuestionを含む)など)。cursorは前回の返りのcursor(省略はこの起動のstreamの先頭)。wait_msを付けると、新しい行か状態の変化まで待つ。state.pendingは答えを待つ要求で、stream_offset/stream_endはその行のstream内の位置(cursorは<launch_id>:<stream_end>)。resume・wakeは新しい起動(launch_id)で、前の起動のcursorも、その起動のfileが残る間(席をcloseするまで)は読める。無ければSTREAM_CURSOR_STALE。vendorとharnessは返した起動の値。

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "session_id": "<session_id>"
    },
    "name": "stream_read"
  }
}

Input Schema

NameRequiredDescriptionDefault
cursorNo前回の返りのcursor。省略は先頭
remoteNo別端末のAitermで実行する時のSSH接続情報。hostだけならssh_configの接続名として使う。Aitermは接続情報を保存・管理しない。passphraseは会話記録に残るため、ssh-agentかpassphrase_env(環境変数名)を推奨する。
wait_msNo新しい行か状態の変化まで待つ(既定0)
max_linesNo既定200
session_idYes

Output Schema

NameRequiredDescriptionDefault
linesYesclaudeのstdoutの行そのまま(JSON文字列)
stateYes
at_endYes
cursorYes
schemaYes
vendorNoVendor of the returned launch; absent on old remotes
harnessNoHarness of the returned launch; absent on old remotes
launch_idYes
session_idYes
current_launch_idYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed3 schema fields changedv0.70.127
    • addedOutput schema / properties / harness
      Added value: +{
      +  "description": "Harness of the returned launch; absent on old remotes",
      +  "type": "string"
      +}
    • addedOutput schema / properties / state / properties / pending / items / properties / method
      Added value: +{
      +  "type": "string"
      +}
    • addedOutput schema / properties / vendor
      Added value: +{
      +  "description": "Vendor of the returned launch; absent on old remotes",
      +  "enum": [
      +    "claude",
      +    "codex",
      +    "cursor",
      +    "grok",
      +    "antigravity"
      +  ],
      +  "type": "string"
      +}
  2. Changed1 schema field changedv0.70.112
    • addedInput schema / properties / remote / properties / ssh
      Added value: +{
      +  "additionalProperties": false,
      +  "description": "Pinned ssh: {known_hosts_file, host_key_alias?, identity_agent | identity_file, strict_host_key?: true} (absolute paths). Strict host checking against that file with that one identity, no user ssh config. Not combinable with identity_file, ssh_options, passphrase or passphrase_env. Needs Aiterm 0.70.101 on the other computer.",
      +  "properties": {
      +    "host_key_alias": {
      +      "pattern": "^(?!-)[A-Za-z0-9._%:\\[\\]-]{1,255}$",
      +      "type": "string"
      +    },
      +    "identity_agent": {
      +      "pattern": "^(\\/|[A-Za-z]:[\\\\/])[^\\s\"'`]*$",
      +      "type": "string"
      +    },
      +    "identity_file": {
      +      "pattern": "^(\\/|[A-Za-z]:[\\\\/])[^\\s\"'`]*$",
      +      "type": "string"
      +    },
      +    "known_hosts_file": {
      +      "pattern": "^(\\/|[A-Za-z]:[\\\\/])[^\\s\"'`]*$",
      +      "type": "string"
      +    },
      +    "strict_host_key": {
      +      "const": true,
      +      "type": "boolean"
      +    }
      +  },
      +  "required": [
      +    "known_hosts_file"
      +  ],
      +  "type": "object"
      +}
  3. Addedv0.70.91

TDQS

A3.7/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden, and it does well: it discloses that lines come back verbatim with no interpretation or formatting, enumerates the line types (assistant, user, system, result, rate_limit_event, control_request including can_use_tool and AskUserQuestion), names the stale-cursor error, and explains that resume/wake spawn a new launch_id whose predecessor's cursor stays readable only until the seat is closed. It stops short of stating whether reads are non-destructive or safe to issue concurrently from multiple callers.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Purpose is front-loaded in the opening clause, and almost every sentence carries load, but the text is one dense run-on block that mixes parameter semantics, cursor lifecycle, and error codes without structure. A short bulleted separation of the parameters from the stream-lifecycle rules would preserve the content and make it far faster to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An output schema exists, so return values need not be described, yet the description still usefully explains the `state.pending`, `stream_offset`, and `stream_end` fields and what `vendor` and `harness` report. For a 5-parameter tool with a nested remote/ssh object, the main unexplained element is the required `session_id`; everything else an agent needs to poll correctly is present.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is already 80%, so a 3 would be the baseline, but the description adds real meaning beyond the schema: `cursor` is the previous call's cursor value, its format is `<launch_id>:<stream_end>`, omitting it means the head of this launch's stream, and `wait_ms` blocks until a new line or state change. `session_id` (the required parameter) and `max_lines` are not explained in the prose, though the schema covers `max_lines`.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

It names a specific verb and resource: read the machine seat's output, i.e. the raw stdout lines of `claude -p stream-json` (or Codex's `codex app-server` JSON-RPC), returned uninterpreted. That is concrete and far from a tautology. It does not explicitly distinguish itself from sibling readers such as `pty_read` or `image_read`, so an agent must infer that this reads agent-launch streams rather than terminal buffers.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives useful operational guidance: omit `cursor` to start at the stream head, add `wait_ms` to block until a new line or state change arrives, and expect `STREAM_CURSOR_STALE` when a prior launch's file is gone. It never states when an agent should choose this tool over `stream_send` for the write side, or over `pty_read` or `agent_approval` when handling `state.pending` requests, so the choice among siblings is left implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.