Skip to main content
Glama

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

Implementation Reference

  • 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(); },
  • 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', },
  • 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, ];
  • Local export of tabs tools array for inclusion in central registry.
    export default [ listTabs, newTab, selectTab, closeTab, ];

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/nzjami/mcpPlaywright'

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