Skip to main content
Glama

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
NameRequiredDescriptionDefault
indexNoThe index of the tab to close. Closes current tab if not provided.

Implementation Reference

  • 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 }; },
  • 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', },
  • 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), ];

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Angeluis001/playwright-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server