read_terminal_output
Extract terminal output from iTerm by specifying the number of lines, enabling direct access to command results for analysis or automation.
Instructions
Reads the output from the active iTerm terminal
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| linesOfOutput | Yes | The number of lines of output to read. |
Implementation Reference
- src/index.ts:95-105 (handler)The handler function for the "read_terminal_output" tool within the CallToolRequestSchema switch statement. It parses the linesOfOutput parameter and invokes TtyOutputReader.call to fetch the terminal output.case "read_terminal_output": { const linesOfOutput = Number(request.params.arguments?.linesOfOutput) || 25 const output = await TtyOutputReader.call(linesOfOutput) return { content: [{ type: "text", text: output }] }; }
- src/index.ts:45-54 (schema)Input schema definition for the "read_terminal_output" tool, specifying linesOfOutput as a required number.inputSchema: { type: "object", properties: { linesOfOutput: { type: "number", description: "The number of lines of output to read." }, }, required: ["linesOfOutput"] }
- src/index.ts:42-55 (registration)Registration of the "read_terminal_output" tool in the ListToolsRequestSchema handler's tools array.{ name: "read_terminal_output", description: "Reads the output from the active iTerm terminal", inputSchema: { type: "object", properties: { linesOfOutput: { type: "number", description: "The number of lines of output to read." }, }, required: ["linesOfOutput"] } },
- src/TtyOutputReader.ts:7-14 (helper)TtyOutputReader.call method, which retrieves the full terminal buffer and slices the last N lines.static async call(linesOfOutput?: number) { const buffer = await this.retrieveBuffer(); if (!linesOfOutput) { return buffer; } const lines = buffer.split('\n'); return lines.slice(-linesOfOutput - 1).join('\n'); }
- src/TtyOutputReader.ts:16-32 (helper)retrieveBuffer method that uses AppleScript executed via osascript to read the contents of the current iTerm2 terminal session.static async retrieveBuffer(): Promise<string> { const ascript = ` tell application "iTerm2" tell front window tell current session of current tab set numRows to number of rows set allContent to contents return allContent end tell end tell end tell `; const { stdout: finalContent } = await execPromise(`osascript -e '${ascript}'`); return finalContent.trim(); } }