pilot_tab_close
Close a browser tab by its ID, or the current tab if no ID is given. Use to remove popups or unwanted tabs.
Instructions
Close a browser tab by its ID, or close the currently active tab if no ID is specified. Use when the user wants to close a popup, remove an unwanted tab, or clean up after finishing work in a tab.
Parameters:
id: Tab ID to close (omit to close the current active tab). Use pilot_tabs to list tab IDs.
Returns: Confirmation that the tab was closed.
Errors:
"No such tab": The provided tab ID does not exist. Run pilot_tabs to see valid IDs.
"Cannot close last tab": The last remaining tab cannot be closed.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | Tab ID to close |
Implementation Reference
- src/tools/tabs.ts:70-98 (handler)The handler function for the 'pilot_tab_close' tool. Takes an optional tab ID, ensures a browser is available, then closes the tab via extension message or direct browser method.
server.tool( 'pilot_tab_close', `Close a browser tab by its ID, or close the currently active tab if no ID is specified. Use when the user wants to close a popup, remove an unwanted tab, or clean up after finishing work in a tab. Parameters: - id: Tab ID to close (omit to close the current active tab). Use pilot_tabs to list tab IDs. Returns: Confirmation that the tab was closed. Errors: - "No such tab": The provided tab ID does not exist. Run pilot_tabs to see valid IDs. - "Cannot close last tab": The last remaining tab cannot be closed.`, { id: z.number().optional().describe('Tab ID to close') }, async ({ id }) => { await bm.ensureBrowser(); try { const ext = bm.getExtension(); if (ext) { await ext.send('close_tab', { tabId: id }); return { content: [{ type: 'text' as const, text: `Closed tab${id ? ` ${id}` : ''}` }] }; } await bm.closeTab(id); return { content: [{ type: 'text' as const, text: `Closed tab${id ? ` ${id}` : ''}` }] }; } catch (err) { return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } } ); - src/tools/tabs.ts:83-83 (schema)Input schema for 'pilot_tab_close': an optional numeric 'id' parameter described as 'Tab ID to close'.
{ id: z.number().optional().describe('Tab ID to close') }, - src/tools/register.ts:43-83 (registration)'pilot_tab_close' is listed in the STANDARD_TOOLS set, meaning it is available in the 'standard' and 'full' profiles.
'pilot_tabs', 'pilot_tab_new', 'pilot_tab_close', 'pilot_tab_select', // page reading 'pilot_page_text', 'pilot_page_html', // visual 'pilot_annotated_screenshot', // iframe 'pilot_frames', 'pilot_frame_select', 'pilot_frame_reset', // session + config 'pilot_auth', 'pilot_block', 'pilot_find', ]); const PROFILE_TOOLS: Record<ToolProfile, Set<string> | null> = { core: CORE_TOOLS, standard: STANDARD_TOOLS, full: null, // null = no filter, register everything }; function createFilteredServer(server: McpServer, allowed: Set<string>): McpServer { const originalTool = server.tool.bind(server); const filtered = Object.create(server) as McpServer; filtered.tool = ((...args: unknown[]) => { const name = args[0] as string; if (!allowed.has(name)) return; return (originalTool as Function).apply(server, args); }) as typeof server.tool; return filtered; } export function registerAllTools(server: McpServer, bm: BrowserManager, profile: ToolProfile = 'full'): void { const allowed = PROFILE_TOOLS[profile]; const effectiveServer = allowed ? createFilteredServer(server, allowed) : server; registerNavigationTools(effectiveServer, bm); registerSnapshotTools(effectiveServer, bm); registerInteractionTools(effectiveServer, bm); registerPageTools(effectiveServer, bm); registerInspectionTools(effectiveServer, bm); registerVisualTools(effectiveServer, bm); registerTabTools(effectiveServer, bm); - src/tools/register.ts:9-9 (registration)The registerTabTools function is imported from './tabs.js' and called in registerAllTools.
import { registerTabTools } from './tabs.js'; - src/tools/register.ts:83-83 (registration)registerTabTools is invoked during registration, which triggers the server.tool() call defining the handler.
registerTabTools(effectiveServer, bm);