browser_tab_close
Close a specific browser tab by index or the current tab if no index is provided, simplifying tab management in Playwright MCP server automation workflows.
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:116-126 (handler)The handler function that executes the browser_tab_close tool logic by calling context.closeTab with the provided index.handle: async (context, params) => { await context.closeTab(params.index); const code = [ `// <internal code to close tab ${params.index}>`, ]; return { code, captureSnapshot, waitForNetwork: false }; },
- src/tools/tabs.ts:106-114 (schema)Schema definition including name, description, input schema for optional tab index, and type as destructive.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:129-133 (helper)Helper method in Context class that implements the tab closing logic using Playwright page.close() and returns updated tabs list.async closeTab(index: number | undefined) { const tab = index === undefined ? this._currentTab : this._tabs[index - 1]; await tab?.page.close(); return await this.listTabsMarkdown(); }
- src/tools.ts:35-50 (registration)Registration of tools including tabs(true) which provides the browser_tab_close tool in the snapshotTools array.export const snapshotTools: Tool<any>[] = [ ...common(true), ...console, ...dialogs(true), ...files(true), ...install, ...keyboard(true), ...navigate(true), ...network, ...pdf, ...screenshot, ...snapshot, ...tabs(true), ...testing, ...wait(true), ];