browser_tab_close
Close specific or current browser tabs during automation using Playwright MCP. Simplifies tab management for efficient web interactions without requiring visual models.
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 handle function for the browser_tab_close tool, which invokes context.closeTab to perform the tab closure and returns a mock code snippet.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)The Zod input schema and metadata (name, title, description, type) 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:148-152 (helper)The Context.closeTab method that selects the tab by index or current, closes the Playwright page, and returns the updated tabs markdown 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/tabs.ts:129-134 (registration)The tabs module registers browser_tab_close by including closeTab(captureSnapshot) in the exported array of tab tools.export default (captureSnapshot: boolean) => [ listTabs, newTab(captureSnapshot), selectTab(captureSnapshot), closeTab(captureSnapshot), ];