Skip to main content
Glama
cloudflare

Cloudflare Playwright MCP

Official
by cloudflare

browser_tab_close

Automatically close a specific browser tab by its index or the current tab using Cloudflare Playwright MCP, enabling precise control during automated browser testing.

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 function that executes the browser_tab_close tool: closes the tab via context.closeTab, generates internal code comment, and sets execution flags.
    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 for the browser_tab_close tool, including name, title, 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.coerce.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'), }), type: 'destructive', },
  • src/tools.ts:27-66 (registration)
    Global registration of tabs tools (including browser_tab_close) into snapshotTools and visionTools arrays by spreading the tabs export with captureSnapshot true/false.
    import tabs from './tools/tabs.js'; import screenshot from './tools/screenshot.js'; import testing from './tools/testing.js'; import vision from './tools/vision.js'; import wait from './tools/wait.js'; import type { Tool } from './tools/tool.js'; 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), ]; export const visionTools: Tool<any>[] = [ ...common(false), ...console, ...dialogs(false), ...files(false), ...install, ...keyboard(false), ...navigate(false), ...network, ...pdf, ...tabs(false), ...testing, ...vision, ...wait(false), ];
  • Core helper method on Context class that implements tab closing logic using Playwright's 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(); }
  • Local registration of the closeTab tool factory 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/cloudflare/playwright-mcp'

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