Skip to main content
Glama

read_terminal_output

Extract terminal output from iTerm to analyze command results or error messages. Specify how many lines to read for focused debugging or monitoring.

Instructions

Reads the output from the active iTerm terminal

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
linesOfOutputYesThe number of lines of output to read.

Implementation Reference

  • MCP server handler for the 'read_terminal_output' tool. Extracts 'linesOfOutput' from arguments (default 25), calls TtyOutputReader.call(), and returns the output 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 }] }; }
  • Schema definition for the 'read_terminal_output' tool, specifying input as object with required 'linesOfOutput' number.
    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/index.ts:26-72 (registration)
    Tool registration in ListToolsRequestSchema handler, where 'read_terminal_output' is listed among available tools.
    return { tools: [ { name: "write_to_terminal", description: "Writes text to the active iTerm terminal - often used to run a command in the terminal", inputSchema: { type: "object", properties: { command: { type: "string", description: "The command to run or text to write to the terminal" }, }, required: ["command"] } }, { 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"] } }, { name: "send_control_character", description: "Sends a control character to the active iTerm terminal (e.g., Control-C)", inputSchema: { type: "object", properties: { letter: { type: "string", description: "The letter corresponding to the control character (e.g., 'C' for Control-C)" }, }, required: ["letter"] } } ] }; });
  • Core helper method TtyOutputReader.call() that retrieves full terminal buffer and returns the last N lines (or all if unspecified). Called directly by the tool handler.
    export default class TtyOutputReader { 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'); }
  • Supporting helper TtyOutputReader.retrieveBuffer() that uses AppleScript via osascript to fetch the full contents of the current iTerm2 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(); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lite/iterm-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server