Skip to main content
Glama
rishabkoul
by rishabkoul

open-terminal

Open a new terminal instance in iTerm2 to execute commands and manage terminal sessions directly from AI assistants.

Instructions

Open a new terminal instance

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • index.js:48-101 (handler)
    The inline handler function for the 'open-terminal' tool. It generates a unique terminal ID, spawns a background shell process with output collection, executes AppleScript to open a new iTerm2 tab, stores the terminal state, and returns a success message.
    server.tool("open-terminal", "Open a new terminal instance", {}, async () => {
      const terminalId = `terminal-${terminalCounter++}`;
    
      // Create both GUI terminal and background process for output collection
      const shell = process.platform === "win32" ? "cmd.exe" : "/bin/bash";
      const terminal = spawn(shell, [], {
        stdio: ["pipe", "pipe", "pipe"],
        shell: true,
      });
    
      const output = [];
    
      terminal.stdout.on("data", (data) => {
        output.push(data.toString());
      });
    
      terminal.stderr.on("data", (data) => {
        output.push(data.toString());
      });
    
      // Create iTerm window
      const script = `
        tell application "iTerm2"
          activate
          tell current window
            create tab with default profile
            tell current session
              write text "echo Terminal ${terminalId} ready"
            end tell
          end tell
        end tell
      `;
    
      try {
        await executeITermScript(script);
        terminals.set(terminalId, {
          process: terminal,
          output,
          id: terminalId,
        });
    
        return {
          content: [
            {
              type: "text",
              text: `Terminal opened with ID: ${terminalId}`,
            },
          ],
        };
      } catch (error) {
        terminal.kill(); // Clean up background process if iTerm fails
        throw error;
      }
    });
  • Helper function used by open-terminal (and other tools) to execute AppleScript for interacting with iTerm/iTerm2 application.
    async function executeITermScript(script) {
      const execPromise = promisify(exec);
    
      // Simple launch script
      const launchScript = `
        tell application "iTerm"
          activate
        end tell
      `;
    
      try {
        // First try to launch/activate iTerm
        await execPromise(`osascript -e '${launchScript}'`);
    
        // Wait a brief moment
        await new Promise((resolve) => setTimeout(resolve, 1000));
    
        // Now execute the actual script with iTerm instead of iTerm2
        const modifiedScript = script.replace(/iTerm2/g, "iTerm");
        const { stdout } = await execPromise(`osascript -e '${modifiedScript}'`);
        return stdout.trim();
      } catch (error) {
        console.error("iTerm AppleScript error:", error);
        throw error;
      }
    }
  • Global state management for active terminals and counter, used to track and identify terminals created by open-terminal.
    const terminals = new Map();
    let terminalCounter = 0;
  • index.js:48-101 (registration)
    Registration of the 'open-terminal' tool on the MCP server, including empty schema {} and inline handler.
    server.tool("open-terminal", "Open a new terminal instance", {}, async () => {
      const terminalId = `terminal-${terminalCounter++}`;
    
      // Create both GUI terminal and background process for output collection
      const shell = process.platform === "win32" ? "cmd.exe" : "/bin/bash";
      const terminal = spawn(shell, [], {
        stdio: ["pipe", "pipe", "pipe"],
        shell: true,
      });
    
      const output = [];
    
      terminal.stdout.on("data", (data) => {
        output.push(data.toString());
      });
    
      terminal.stderr.on("data", (data) => {
        output.push(data.toString());
      });
    
      // Create iTerm window
      const script = `
        tell application "iTerm2"
          activate
          tell current window
            create tab with default profile
            tell current session
              write text "echo Terminal ${terminalId} ready"
            end tell
          end tell
        end tell
      `;
    
      try {
        await executeITermScript(script);
        terminals.set(terminalId, {
          process: terminal,
          output,
          id: terminalId,
        });
    
        return {
          content: [
            {
              type: "text",
              text: `Terminal opened with ID: ${terminalId}`,
            },
          ],
        };
      } catch (error) {
        terminal.kill(); // Clean up background process if iTerm fails
        throw error;
      }
    });
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Open a new terminal instance' implies a creation/mutation operation, it doesn't specify whether this requires specific permissions, what environment the terminal opens in, whether it's interactive or headless, or what happens on success/failure. For a tool with zero annotation coverage, this leaves significant behavioral gaps.

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 a single, efficient sentence with zero wasted words. It's front-loaded with the core action and resource, making it immediately scannable. Every word earns its place by conveying essential purpose without redundancy.

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

Completeness3/5

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

Given the tool's simplicity (0 parameters, no output schema, no annotations), the description is minimally complete. It states what the tool does but lacks context about the terminal environment, behavioral expectations, or relationship to sibling tools. For a tool that presumably creates a new interactive session, more guidance would be helpful, but the bare description meets minimum viability.

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

Parameters4/5

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

The tool has 0 parameters with 100% schema description coverage (empty schema), so there are no parameters to document. The description appropriately doesn't mention any parameters, which is correct for this case. Baseline for 0 parameters is 4, as the description doesn't need to compensate for any schema gaps.

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 'Open a new terminal instance' clearly states the action (open) and resource (terminal instance), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling 'list-terminals' beyond the obvious verb difference, nor does it specify what type of terminal (e.g., system terminal, embedded terminal) is being opened.

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 alternatives. It doesn't mention prerequisites (e.g., whether a terminal must be closed first), when to use 'open-terminal' versus 'execute-command' directly, or what happens if multiple terminals are already open. The agent must infer usage from the tool name alone.

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/rishabkoul/iTerm-MCP-Server'

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