browser_tab_close
Close a specific browser tab by index or the current tab if no index is provided. Part of Playwright MCP for streamlined browser automation.
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)Handler for the browser_tab_close tool that closes the tab via 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-88 (schema)Input schema and metadata 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:114-121 (helper)Core logic for closing a browser tab 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/tools.ts:36-52 (registration)Central registration of all tools, including the tabs tools (with browser_tab_close) via spread of imported tabs array.export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ];
- src/tools/tabs.ts:96-101 (registration)Local export of tabs tools array for inclusion in central registry.export default [ listTabs, newTab, selectTab, closeTab, ];