Skip to main content
Glama
cloudflare

Cloudflare Playwright MCP

Official
by cloudflare

browser_tab_close

Destructive

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),
    ];
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations provide destructiveHint=true and readOnlyHint=false, indicating this is a destructive write operation. The description 'Close a tab' aligns with this destructive behavior but doesn't add additional context beyond what annotations already convey. No contradiction exists, but minimal value is added beyond annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at three words, front-loading the core action without any unnecessary elaboration. Every word earns its place, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (destructive operation with one optional parameter), no output schema, and rich annotations, the description is minimally adequate. It states what the tool does but lacks details on effects (e.g., what happens to browser state) or error conditions, leaving gaps despite annotation support.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% with a clear parameter description for 'index'. The description doesn't add any parameter information beyond what's in the schema, but with full schema coverage, the baseline score of 3 is appropriate as the schema handles the parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Close a tab' clearly states the action (close) and resource (tab), making the purpose immediately understandable. It distinguishes from siblings like browser_close (closes browser) and browser_tab_list/select/new (other tab operations), but doesn't explicitly mention this distinction in the description itself.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to close a tab versus using browser_close, or how it relates to browser_tab_select or browser_tab_new. The agent must infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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