Skip to main content
Glama
ferrislucas

iTerm MCP Server

by ferrislucas

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
NameRequiredDescriptionDefault
linesOfOutputYesThe number of lines of output to read.

Implementation Reference

  • 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"] } },
  • 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'); }
  • 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(); } }

Other Tools

Related Tools

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/ferrislucas/iterm-mcp'

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