Skip to main content
Glama
ferrislucas

iTerm MCP Server

by ferrislucas

read_terminal_output

Retrieve output from the active iTerm terminal by specifying the number of lines to read.

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 function for the 'read_terminal_output' tool. It reads the 'linesOfOutput' argument, calls TtyOutputReader.call() with it, and returns the terminal 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
        }]
      };
    }
  • The TtyOutputReader class with the 'call' method that retrieves terminal output by fetching the full buffer via AppleScript and optionally slicing to the requested number of lines.
    import { exec } from 'node:child_process';
    import { promisify } from 'node:util';
    
    const execPromise = promisify(exec);
    
    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');
      }
    
      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();
      }
    }
  • Schema/registration definition for the 'read_terminal_output' tool, including its description, input schema with 'linesOfOutput' (integer), and that it is required.
    {
      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/index.ts:25-71 (registration)
    The tool registration via ListToolsRequestSchema handler, where 'read_terminal_output' is listed among the available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      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: "integer",
                  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, or special sequences like ']' for telnet escape)",
            inputSchema: {
              type: "object",
              properties: {
                letter: {
                  type: "string",
                  description: "The letter corresponding to the control character (e.g., 'C' for Control-C, ']' for telnet escape)"
                },
              },
              required: ["letter"]
            }
          }
        ]
      };
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure, yet it states nothing about side effects (e.g., whether reading clears output), output format, maximum lines, or error behavior. The agent lacks critical information about how the tool behaves at runtime.

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

Conciseness4/5

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

The description is highly concise: a single sentence with no waste. It is appropriately front-loaded. However, it could afford to include a tiny bit more context without harming conciseness, hence not a perfect 5.

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

Completeness2/5

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

Given the tool's simplicity (single required parameter, no output schema), the description is insufficient. It omits essential context such as whether the read is destructive, how the terminal session is identified ('active' is ambiguous), and any limitations on the number of lines. The agent lacks enough information to use the tool confidently.

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

Parameters3/5

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

Schema coverage is 100% because the only parameter ('linesOfOutput') is described in the schema. The description adds no additional meaning beyond the schema's 'The number of lines of output to read.' so it meets the baseline but does not enhance parameter understanding.

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

Purpose5/5

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

The description clearly states the action ('reads') and the specific resource ('output from the active iTerm terminal'). It distinctively separates this tool from its siblings ('send_control_character' and 'write_to_terminal') which perform write operations, making the tool's purpose unambiguous.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus its siblings. It does not mention prerequisites, alternatives, or conditions under which this tool should be chosen. The agent receives no decision support beyond the basic action.

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

Install Server

Other 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