close_tab
Close a specific browser tab by window and tab index, but use with caution due to high risk of targeting the wrong tab if tabs are reordered or closed. Recommended alternative: close_tab_by_id.
Instructions
⚠️ LEGACY DANGER: Close a specific tab using window/tab index. HIGH RISK of closing wrong tabs due to index shifting when tabs are reordered/closed. STRONGLY DEPRECATED: Use close_tab_by_id instead. Only use if Tab ID is unavailable.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabIndex | Yes | DANGEROUS: Tab index (1-based) - changes when tabs are reordered | |
| windowIndex | Yes | DANGEROUS: Window index (1-based) - can target wrong window |
Implementation Reference
- src/index.ts:355-369 (handler)Handler logic for the 'close_tab' tool within the tools/call request handler. Extracts windowIndex and tabIndex from arguments, calls the closeChromeTabByIndex helper function, and returns a success message.if (name === "close_tab") { const { windowIndex, tabIndex } = request.params.arguments as { windowIndex: number; tabIndex: number; }; await closeChromeTabByIndex(windowIndex, tabIndex); return { content: [ { type: "text", text: `⚠️ LEGACY: Successfully closed tab at window ${windowIndex}, tab ${tabIndex}. Consider using close_tab_by_id for better reliability.`, }, ], }; }
- src/index.ts:175-198 (helper)Helper function that implements the core logic for closing a Chrome tab by window index and tab index using AppleScript executed via osascript.async function closeChromeTabByIndex( windowIndex: number, tabIndex: number ): Promise<void> { const script = ` tell application "Google Chrome" try set targetWindow to window ${windowIndex} set targetTab to tab ${tabIndex} of targetWindow close targetTab on error errMsg return "Error: " & errMsg end try end tell `; try { await execAsync(`osascript -e '${script}'`); } catch (error) { throw new Error( `Failed to close Chrome tab: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:258-267 (registration)Registration of the 'close_tab' tool in the list of available tools returned by tools/list, including name, description, and input schema.{ name: "close_tab", description: "⚠️ LEGACY DANGER: Close a specific tab using window/tab index. HIGH RISK of closing wrong tabs due to index shifting when tabs are reordered/closed. STRONGLY DEPRECATED: Use close_tab_by_id instead. Only use if Tab ID is unavailable.", inputSchema: zodToJsonSchema( z.object({ windowIndex: z.number().int().positive().describe("DANGEROUS: Window index (1-based) - can target wrong window"), tabIndex: z.number().int().positive().describe("DANGEROUS: Tab index (1-based) - changes when tabs are reordered"), }) ), },
- src/index.ts:261-266 (schema)Zod schema definition for the input parameters of the 'close_tab' tool: windowIndex and tabIndex.inputSchema: zodToJsonSchema( z.object({ windowIndex: z.number().int().positive().describe("DANGEROUS: Window index (1-based) - can target wrong window"), tabIndex: z.number().int().positive().describe("DANGEROUS: Tab index (1-based) - changes when tabs are reordered"), }) ),