Skip to main content
Glama

browser_tab_close

Close a specific or current browser tab by index during web automation with Playwright MCP, ensuring precise tab management in browser 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 handle function for the browser_tab_close tool. It validates the input parameters using closeTabSchema, closes the specified tab (or current tab if index not provided) via context.closeTab(), handles the current tab response, and either executes a code snippet or lists remaining tabs.
    handle: async (context, params) => { const validatedParams = closeTabSchema.parse(params); await context.closeTab(validatedParams.index); const currentTab = context.currentTab(); if (currentTab) { return await currentTab.run(async () => { const code = [ `// <internal code to close tab ${validatedParams.index}>`, ]; return { code }; }, { captureSnapshot }); } return { content: [{ type: 'text', text: await context.listTabs(), }], }; },
  • Zod schema for input validation of browser_tab_close tool, defining an optional 'index' number parameter.
    const closeTabSchema = z.object({ index: z.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'), });
  • Full definition of the browser_tab_close tool as a ToolFactory, including capability, schema with name 'browser_tab_close', and handle function.
    const closeTab: ToolFactory = captureSnapshot => ({ capability: 'tabs', schema: { name: 'browser_tab_close', description: 'Close a tab', inputSchema: zodToJsonSchema(closeTabSchema), }, handle: async (context, params) => { const validatedParams = closeTabSchema.parse(params); await context.closeTab(validatedParams.index); const currentTab = context.currentTab(); if (currentTab) { return await currentTab.run(async () => { const code = [ `// <internal code to close tab ${validatedParams.index}>`, ]; return { code }; }, { captureSnapshot }); } return { content: [{ type: 'text', text: await context.listTabs(), }], }; }, });
  • Export of the tabs tools factory function, which instantiates and returns the closeTab tool among others.
    export default (captureSnapshot: boolean) => [ listTabs, newTab, 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/markbustamante77/mcp'

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