Skip to main content
Glama
rishabkoul
by rishabkoul

close-terminal

Close a specific iTerm2 terminal session by providing its terminal ID to manage terminal resources and maintain a clean workspace.

Instructions

Close a specific terminal

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
terminalIdYesID of the terminal to close

Implementation Reference

  • Handler function for the 'close-terminal' tool. Retrieves the terminal by ID from the global map, kills the background process, executes AppleScript to close the iTerm window, removes it from the map, decrements the counter, and returns a confirmation message.
      async ({ terminalId }) => {
        const terminal = terminals.get(terminalId);
        if (!terminal) {
          return {
            content: [
              {
                type: "text",
                text: `Terminal ${terminalId} not found`,
              },
            ],
          };
        }
    
        // Close both GUI and background process
        terminal.process.kill();
    
        const script = `
          tell application "iTerm2"
            close current window
          end tell
        `;
    
        try {
          await executeITermScript(script);
        } catch (error) {
          console.error("Failed to close iTerm window:", error);
        }
    
        terminals.delete(terminalId);
    
        // Safely decrement the terminal counter
        terminalCounter = Math.max(0, terminalCounter - 1);
    
        return {
          content: [
            {
              type: "text",
              text: `Terminal ${terminalId} closed`,
            },
          ],
        };
      }
    );
  • Zod schema defining the input parameter 'terminalId' as a required string for the 'close-terminal' tool.
    {
      terminalId: z.string().describe("ID of the terminal to close"),
    },
  • index.js:193-241 (registration)
    MCP server registration of the 'close-terminal' tool, including name, description, input schema, and handler function.
    server.tool(
      "close-terminal",
      "Close a specific terminal",
      {
        terminalId: z.string().describe("ID of the terminal to close"),
      },
      async ({ terminalId }) => {
        const terminal = terminals.get(terminalId);
        if (!terminal) {
          return {
            content: [
              {
                type: "text",
                text: `Terminal ${terminalId} not found`,
              },
            ],
          };
        }
    
        // Close both GUI and background process
        terminal.process.kill();
    
        const script = `
          tell application "iTerm2"
            close current window
          end tell
        `;
    
        try {
          await executeITermScript(script);
        } catch (error) {
          console.error("Failed to close iTerm window:", error);
        }
    
        terminals.delete(terminalId);
    
        // Safely decrement the terminal counter
        terminalCounter = Math.max(0, terminalCounter - 1);
    
        return {
          content: [
            {
              type: "text",
              text: `Terminal ${terminalId} closed`,
            },
          ],
        };
      }
    );
  • Helper function used by the 'close-terminal' handler (and others) to execute AppleScript commands for iTerm2 terminal operations, including activation and script execution.
    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;
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. 'Close a specific terminal' implies a destructive action (termination of a terminal session), but it doesn't specify whether this is reversible, what happens to unsaved work, or if there are permission requirements. The description lacks critical behavioral context for a mutation tool.

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 that states the core functionality without unnecessary words. It's front-loaded with the essential action and resource, making it immediately scannable and zero waste.

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 destructive tool with no annotations and no output schema, the description is insufficient. It doesn't explain what 'close' entails behaviorally (e.g., termination effects, error conditions), return values, or integration with sibling tools. The agent lacks complete context to use this tool safely and effectively.

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%, with the single parameter 'terminalId' fully documented in the schema. The description adds no additional parameter semantics beyond what's in the schema (e.g., format examples, source of IDs, or validation rules). Baseline 3 is appropriate when the schema does all the parameter documentation.

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 action ('close') and resource ('a specific terminal'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'list-terminals' or 'open-terminal', but the verb 'close' inherently distinguishes it from those operations.

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., needing an open terminal), exclusions, or relationships to sibling tools like 'open-terminal' or 'read-output'. The agent must infer usage context 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