read_terminal_output
Extract specific lines of terminal output from the active iTerm session to analyze or process command results. Integrates with iTerm MCP Server for efficient shell command execution.
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 for the 'read_terminal_output' tool. It extracts the number of lines requested, calls TtyOutputReader.call to get the output, and returns it as text content.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:42-55 (registration)Registration of the 'read_terminal_output' tool in the list of available tools, including its name, description, and input schema.{ name: "read_terminal_output", description: "Reads the output from the active iTerm terminal", inputSchema: { type: "object", properties: { linesOfOutput: { type: "integer", description: "The number of lines of output to read." }, }, required: ["linesOfOutput"] } },
- src/TtyOutputReader.ts:7-14 (helper)The TtyOutputReader.call static method, which retrieves the terminal buffer and returns the last N lines if specified.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)The TtyOutputReader.retrieveBuffer static method, which uses AppleScript via osascript to fetch the contents of the current iTerm 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(); } }