close_tab_by_id
Close a specific Chrome tab by its unique ID, unaffected by tab reordering, window changes, or index shifting. Use the tab ID from the get_tabs output for precise control.
Instructions
🔥 PREFERRED METHOD: Close a specific tab in Google Chrome using its unique tab ID. IMMUNE to tab reordering, window changes, and index shifting. Extract the Tab ID from [Tab ID: 1234567890] in get_tabs output. Example: if tab shows '[Tab ID: 1594670961]', use tabId: 1594670961
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | Yes | The exact Tab ID number from [Tab ID: xxxxx] in get_tabs output - NOT the display number |
Implementation Reference
- src/index.ts:107-137 (handler)Core handler function that executes the logic to close a Chrome tab by its unique ID using AppleScript via osascript.async function closeChromeTabById(tabId: number): Promise<void> { const script = ` tell application "Google Chrome" set targetTabID to "${tabId}" set tabFound to false repeat with w in (every window) repeat with t in (every tab of w) if (id of t) as string = targetTabID then close t set tabFound to true exit repeat end if end repeat if tabFound then exit repeat end repeat if not tabFound then error "Tab with ID " & targetTabID & " not found" end if end tell `; try { await execAsync(`osascript -e '${script}'`); } catch (error) { throw new Error( `Failed to close Chrome tab with ID ${tabId}: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:241-248 (registration)Registration of the 'close_tab_by_id' tool in the tools list, including name, description, and input schema.name: "close_tab_by_id", description: "🔥 PREFERRED METHOD: Close a specific tab in Google Chrome using its unique tab ID. IMMUNE to tab reordering, window changes, and index shifting. Extract the Tab ID from [Tab ID: 1234567890] in get_tabs output. Example: if tab shows '[Tab ID: 1594670961]', use tabId: 1594670961", inputSchema: zodToJsonSchema( z.object({ tabId: z.number().int().positive().describe("The exact Tab ID number from [Tab ID: xxxxx] in get_tabs output - NOT the display number"), }) ), },
- src/index.ts:329-340 (handler)Dispatch handler in the tool call request handler that invokes closeChromeTabById with the provided tabId argument.if (name === "close_tab_by_id") { const { tabId } = request.params.arguments as { tabId: number }; await closeChromeTabById(tabId); return { content: [ { type: "text", text: `✅ Successfully closed tab with ID ${tabId}`, }, ], }; }
- src/index.ts:243-247 (schema)Zod schema definition for the input parameters (tabId) of the close_tab_by_id tool.inputSchema: zodToJsonSchema( z.object({ tabId: z.number().int().positive().describe("The exact Tab ID number from [Tab ID: xxxxx] in get_tabs output - NOT the display number"), }) ),