Skip to main content
Glama

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

Implementation Reference

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

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/lewisvoncken/playwright-mcp'

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