browser_tab_close
Close a browser tab by index or the current tab to manage tab clutter and improve browsing efficiency during web automation tasks.
Instructions
Close a tab
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index | No | The index of the tab to close. Closes current tab if not provided. |
Implementation Reference
- src/tools/tabs.ts:90-93 (handler)The handler function for browser_tab_close tool that closes the tab using context.closeTab and includes a snapshot in the response.handle: async (context, params, response) => { await context.closeTab(params.index); response.setIncludeSnapshot(); },
- src/tools/tabs.ts:80-89 (schema)Input/output schema definition for the browser_tab_close tool.schema: { name: 'browser_tab_close', title: 'Close a tab', description: 'Close a tab', inputSchema: z.object({ index: z.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'), }), type: 'destructive', },
- src/context.ts:108-115 (helper)Supporting utility method on Context class that performs the actual tab closing using Playwright's page.close().async closeTab(index: number | undefined): Promise<string> { const tab = index === undefined ? this._currentTab : this._tabs[index]; if (!tab) throw new Error(`Tab ${index} not found`); const url = tab.page.url(); await tab.page.close(); return url; }
- src/browserServerBackend.ts:47-52 (registration)Where tools including browser_tab_close are registered in the MCP ServerBackend via filteredTools(config).constructor(config: FullConfig, factories: FactoryList) { this._config = config; this._browserContextFactory = factories[0]; this._tools = filteredTools(config); if (factories.length > 1) this._tools.push(this._defineContextSwitchTool(factories));
- src/tools.ts:36-52 (registration)Collection of all tools, spreading the tabs tools which includes browser_tab_close.export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ];