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"),
      })
    ),
Behavior5/5

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

With no annotations provided, the description carries full burden and excels at behavioral disclosure. It explains the HIGH RISK due to index shifting when tabs are reordered/closed, warns about targeting wrong windows, and explicitly labels it as 'LEGACY DANGER' and 'STRONGLY DEPRECATED' - providing crucial behavioral context beyond what parameters alone would indicate.

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 perfectly structured and concise: it starts with a warning emoji and 'LEGACY DANGER', states the purpose, explains the risk, provides deprecation guidance, and gives the specific condition for use. Every sentence earns its place with critical information.

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

Completeness5/5

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

For a 2-parameter tool with no annotations and no output schema, the description provides complete context: purpose, risks, deprecation status, alternative tool, and specific usage condition. It compensates for the lack of structured safety annotations by explicitly warning about the dangerous behavior.

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

Parameters4/5

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

With 100% schema description coverage, the baseline is 3. The description adds meaningful context by explaining why the parameters are dangerous ('HIGH RISK of closing wrong tabs due to index shifting'), which provides semantic understanding beyond the schema's technical descriptions of the parameters.

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

Purpose5/5

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

The description clearly states the verb 'Close' and resource 'a specific tab using window/tab index', making the purpose explicit. It distinguishes from sibling tools by naming 'close_tab_by_id' as the preferred alternative, establishing clear differentiation.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance: 'STRONGLY DEPRECATED: Use close_tab_by_id instead. Only use if Tab ID is unavailable.' This clearly states when not to use this tool and names the alternative, with a specific condition for when it might be appropriate.

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

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