Skip to main content
Glama

browser_tab_close

Close a browser tab by index or the current tab to manage tab clutter and improve browsing efficiency during web automation tasks.

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 for browser_tab_close tool that closes the tab using context.closeTab and includes a snapshot in the response.
    handle: async (context, params, response) => { await context.closeTab(params.index); response.setIncludeSnapshot(); },
  • Input/output schema definition 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', },
  • Supporting utility method on Context class that performs the actual tab closing 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; }
  • Where tools including browser_tab_close are registered in the MCP ServerBackend via filteredTools(config).
    constructor(config: FullConfig, factories: FactoryList) { this._config = config; this._browserContextFactory = factories[0]; this._tools = filteredTools(config); if (factories.length > 1) this._tools.push(this._defineContextSwitchTool(factories));
  • src/tools.ts:36-52 (registration)
    Collection of all tools, spreading the tabs tools which includes browser_tab_close.
    export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ];

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

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