Skip to main content
Glama

write_to_terminal

Execute commands or write text directly to your active iTerm terminal session through the iTerm MCP server.

Instructions

Writes text to the active iTerm terminal - often used to run a command in the terminal

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesThe command to run or text to write to the terminal

Implementation Reference

  • Handler for the 'write_to_terminal' tool: executes the command via CommandExecutor, measures output lines using TtyOutputReader, and returns a descriptive message.
    case "write_to_terminal": {
      let executor = new CommandExecutor();
      const command = String(request.params.arguments?.command);
      const beforeCommandBuffer = await TtyOutputReader.retrieveBuffer();
      const beforeCommandBufferLines = beforeCommandBuffer.split("\n").length;
      
      await executor.executeCommand(command);
      
      const afterCommandBuffer = await TtyOutputReader.retrieveBuffer();
      const afterCommandBufferLines = afterCommandBuffer.split("\n").length;
      const outputLines = afterCommandBufferLines - beforeCommandBufferLines
    
      return {
        content: [{
          type: "text",
          text: `${outputLines} lines were output after sending the command to the terminal. Read the last ${outputLines} lines of terminal contents to orient yourself. Never assume that the command was executed or that it was successful.`
        }]
      };
    }
  • Tool specification including name, description, and input schema for 'write_to_terminal'.
    {
      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"]
      }
    },
  • src/index.ts:25-72 (registration)
    Registration of all tools including 'write_to_terminal' via the ListToolsRequestHandler.
    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: "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 implementation in CommandExecutor.executeCommand: escapes command and uses osascript to write to iTerm2 current session, waits for completion.
    async executeCommand(command: string): Promise<string> {
      const escapedCommand = this.escapeForAppleScript(command);
      
      try {
        await execPromise(`/usr/bin/osascript -e 'tell application "iTerm2" to tell current session of current window to write text "${escapedCommand}"'`);
        
        // Wait until iterm reports that processing is done
        while (await this.isProcessing()) {
          await sleep(100);
        }
        
        const ttyPath = await this.retrieveTtyPath();
        while (await this.isWaitingForUserInput(ttyPath) === false) {
          await sleep(100);
        }
    
        // Give a small delay for output to settle
        await sleep(200);
        
        const afterCommandBuffer = await TtyOutputReader.retrieveBuffer()
        return afterCommandBuffer
      } catch (error: unknown) {
        throw new Error(`Failed to execute command: ${(error as Error).message}`);
      }
    }
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. It mentions the tool writes to the 'active' terminal and can run commands, but doesn't address important behavioral aspects like whether this requires specific permissions, whether it waits for command completion, what happens if no terminal is active, or potential side effects of command execution. The description is insufficient for a mutation tool with zero annotation coverage.

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

Conciseness5/5

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

The description is extremely concise (one sentence) with zero wasted words. It's front-loaded with the core functionality ('writes text to the active iTerm terminal') followed by a usage hint. Every element earns its place in this minimal description.

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?

For a mutation tool with no annotations, no output schema, and a single parameter, the description is incomplete. It doesn't address important contextual aspects like error conditions, what constitutes 'active' terminal, whether the tool blocks until command completion, or what happens after command execution. The description provides basic functionality but lacks sufficient operational context.

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 description coverage is 100%, so the schema already fully documents the single 'command' parameter. The description adds marginal value by suggesting the parameter can contain either 'text to write' or 'command to run', but doesn't provide additional syntax, format, or constraint details beyond what the schema provides. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's purpose with specific verbs ('writes text', 'run a command') and identifies the target resource ('active iTerm terminal'). It distinguishes from sibling 'read_terminal_output' by focusing on output rather than input, though it doesn't explicitly contrast with 'send_control_character'.

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

Usage Guidelines3/5

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

The description provides implied usage context ('often used to run a command in the terminal'), suggesting this is for executing commands rather than just writing text. However, it doesn't explicitly state when to use this tool versus 'send_control_character' or provide any exclusion criteria or prerequisites for usage.

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

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