Skip to main content
Glama

close-terminal

End a specific terminal session by providing its unique ID, enabling efficient terminal management within the iTerm MCP Server environment.

Instructions

Close a specific terminal

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
terminalIdYesID of the terminal to close

Implementation Reference

  • Handler function that retrieves the terminal by ID, kills its process, closes the iTerm window using AppleScript, removes it from the terminals Map, decrements the counter, and returns a success 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`, }, ], }; }
  • Input schema defining the required 'terminalId' parameter as a string.
    { terminalId: z.string().describe("ID of the terminal to close"), },
  • index.js:193-241 (registration)
    Registration of the 'close-terminal' tool with server.tool, including name, description, input schema, and inline 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`, }, ], }; } );

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

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