Skip to main content
Glama
kazuph

MCP Browser Tabs Server

by kazuph

close_tab

Close a specific browser tab by window and tab index, but use with caution due to high risk of targeting the wrong tab if tabs are reordered or closed. Recommended alternative: close_tab_by_id.

Instructions

⚠️ LEGACY DANGER: Close a specific tab using window/tab index. HIGH RISK of closing wrong tabs due to index shifting when tabs are reordered/closed. STRONGLY DEPRECATED: Use close_tab_by_id instead. Only use if Tab ID is unavailable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tabIndexYesDANGEROUS: Tab index (1-based) - changes when tabs are reordered
windowIndexYesDANGEROUS: Window index (1-based) - can target wrong window

Implementation Reference

  • Handler logic for the 'close_tab' tool within the tools/call request handler. Extracts windowIndex and tabIndex from arguments, calls the closeChromeTabByIndex helper function, and returns a success message.
    if (name === "close_tab") {
      const { windowIndex, tabIndex } = request.params.arguments as {
        windowIndex: number;
        tabIndex: number;
      };
      await closeChromeTabByIndex(windowIndex, tabIndex);
      return {
        content: [
          {
            type: "text",
            text: `⚠️ LEGACY: Successfully closed tab at window ${windowIndex}, tab ${tabIndex}. Consider using close_tab_by_id for better reliability.`,
          },
        ],
      };
    }
  • Helper function that implements the core logic for closing a Chrome tab by window index and tab index using AppleScript executed via osascript.
    async function closeChromeTabByIndex(
      windowIndex: number,
      tabIndex: number
    ): Promise<void> {
      const script = `
        tell application "Google Chrome"
          try
            set targetWindow to window ${windowIndex}
            set targetTab to tab ${tabIndex} of targetWindow
            close targetTab
          on error errMsg
            return "Error: " & errMsg
          end try
        end tell
      `;
    
      try {
        await execAsync(`osascript -e '${script}'`);
      } catch (error) {
        throw new Error(
          `Failed to close Chrome tab: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • src/index.ts:258-267 (registration)
    Registration of the 'close_tab' tool in the list of available tools returned by tools/list, including name, description, and input schema.
    {
      name: "close_tab",
      description: "⚠️ LEGACY DANGER: Close a specific tab using window/tab index. HIGH RISK of closing wrong tabs due to index shifting when tabs are reordered/closed. STRONGLY DEPRECATED: Use close_tab_by_id instead. Only use if Tab ID is unavailable.",
      inputSchema: zodToJsonSchema(
        z.object({
          windowIndex: z.number().int().positive().describe("DANGEROUS: Window index (1-based) - can target wrong window"),
          tabIndex: z.number().int().positive().describe("DANGEROUS: Tab index (1-based) - changes when tabs are reordered"),
        })
      ),
    },
  • Zod schema definition for the input parameters of the 'close_tab' tool: windowIndex and tabIndex.
    inputSchema: zodToJsonSchema(
      z.object({
        windowIndex: z.number().int().positive().describe("DANGEROUS: Window index (1-based) - can target wrong window"),
        tabIndex: z.number().int().positive().describe("DANGEROUS: Tab index (1-based) - changes when tabs are reordered"),
      })
    ),

Tool Definition Quality

Score is being calculated. Check back soon.

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/kazuph/mcp-browser-tabs'

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