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
| Name | Required | Description | Default |
|---|---|---|---|
| terminalId | Yes | ID of the terminal to close |
Implementation Reference
- index.js:199-240 (handler)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`, }, ], }; }
- index.js:196-198 (schema)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`, }, ], }; } );