Skip to main content
Glama

browser_tabs

Manage browser tabs in Playwright MCP by listing, creating, closing, or selecting tabs for web automation tasks.

Instructions

List, create, close, or select a browser tab.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesOperation to perform
indexNoTab index, used for close/select. If omitted for close, current tab is closed.

Implementation Reference

  • Implementation of the 'browser_tab_list' tool handler, which lists all open browser tabs.
    const listTabs: Tool = {
      capability: 'tabs',
      schema: {
        name: 'browser_tab_list',
        description: 'List browser tabs',
        inputSchema: zodToJsonSchema(z.object({})),
      },
      handle: async context => {
        return {
          content: [{
            type: 'text',
            text: await context.listTabs(),
          }],
        };
      },
    };
  • Implementation of the 'browser_tab_select' tool handler, which selects a browser tab by index.
    const selectTabSchema = z.object({
      index: z.number().describe('The index of the tab to select'),
    });
    
    const selectTab: ToolFactory = captureSnapshot => ({
      capability: 'tabs',
      schema: {
        name: 'browser_tab_select',
        description: 'Select a tab by index',
        inputSchema: zodToJsonSchema(selectTabSchema),
      },
      handle: async (context, params) => {
        const validatedParams = selectTabSchema.parse(params);
        await context.selectTab(validatedParams.index);
        const currentTab = await context.ensureTab();
        return await currentTab.run(async () => {
          const code = [
            `// <internal code to select tab ${validatedParams.index}>`,
          ];
          return { code };
        }, { captureSnapshot });
      },
    });
  • Implementation of the 'browser_tab_new' tool handler, which opens a new browser tab.
    const newTabSchema = z.object({
      url: z.string().optional().describe('The URL to navigate to in the new tab. If not provided, the new tab will be blank.'),
    });
    
    const newTab: Tool = {
      capability: 'tabs',
      schema: {
        name: 'browser_tab_new',
        description: 'Open a new tab',
        inputSchema: zodToJsonSchema(newTabSchema),
      },
      handle: async (context, params) => {
        const validatedParams = newTabSchema.parse(params);
        await context.newTab();
        if (validatedParams.url)
          await context.currentTab().navigate(validatedParams.url);
        return await context.currentTab().run(async () => {
          const code = [
            `// <internal code to open a new tab>`,
          ];
          return { code };
        }, { captureSnapshot: true });
      },
    };
  • Implementation of the 'browser_tab_close' tool handler, which closes a browser tab.
    const closeTabSchema = z.object({
      index: z.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'),
    });
    
    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(),
          }],
        };
      },
    });
  • src/index.ts:37-47 (registration)
    Registration of the browser tabs tools (from tabs(true)) into the snapshotTools array used by the MCP server.
    const snapshotTools: Tool[] = [
      ...common(true),
      ...console,
      ...files(true),
      ...install,
      ...keyboard(true),
      ...navigate(true),
      ...pdf,
      ...snapshot,
      ...tabs(true),
    ];

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