Skip to main content
Glama
kazuph

MCP Browser Tabs Server

by kazuph

close_tab_by_id

Close a specific Chrome tab by its unique ID, unaffected by tab reordering, window changes, or index shifting. Use the tab ID from the get_tabs output for precise control.

Instructions

🔥 PREFERRED METHOD: Close a specific tab in Google Chrome using its unique tab ID. IMMUNE to tab reordering, window changes, and index shifting. Extract the Tab ID from [Tab ID: 1234567890] in get_tabs output. Example: if tab shows '[Tab ID: 1594670961]', use tabId: 1594670961

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tabIdYesThe exact Tab ID number from [Tab ID: xxxxx] in get_tabs output - NOT the display number

Implementation Reference

  • Core handler function that executes the logic to close a Chrome tab by its unique ID using AppleScript via osascript.
    async function closeChromeTabById(tabId: number): Promise<void> {
      const script = `
        tell application "Google Chrome"
          set targetTabID to "${tabId}"
          set tabFound to false
          
          repeat with w in (every window)
            repeat with t in (every tab of w)
              if (id of t) as string = targetTabID then
                close t
                set tabFound to true
                exit repeat
              end if
            end repeat
            if tabFound then exit repeat
          end repeat
          
          if not tabFound then
            error "Tab with ID " & targetTabID & " not found"
          end if
        end tell
      `;
    
      try {
        await execAsync(`osascript -e '${script}'`);
      } catch (error) {
        throw new Error(
          `Failed to close Chrome tab with ID ${tabId}: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • src/index.ts:241-248 (registration)
    Registration of the 'close_tab_by_id' tool in the tools list, including name, description, and input schema.
      name: "close_tab_by_id",
      description: "🔥 PREFERRED METHOD: Close a specific tab in Google Chrome using its unique tab ID. IMMUNE to tab reordering, window changes, and index shifting. Extract the Tab ID from [Tab ID: 1234567890] in get_tabs output. Example: if tab shows '[Tab ID: 1594670961]', use tabId: 1594670961",
      inputSchema: zodToJsonSchema(
        z.object({
          tabId: z.number().int().positive().describe("The exact Tab ID number from [Tab ID: xxxxx] in get_tabs output - NOT the display number"),
        })
      ),
    },
  • Dispatch handler in the tool call request handler that invokes closeChromeTabById with the provided tabId argument.
    if (name === "close_tab_by_id") {
      const { tabId } = request.params.arguments as { tabId: number };
      await closeChromeTabById(tabId);
      return {
        content: [
          {
            type: "text",
            text: `✅ Successfully closed tab with ID ${tabId}`,
          },
        ],
      };
    }
  • Zod schema definition for the input parameters (tabId) of the close_tab_by_id tool.
    inputSchema: zodToJsonSchema(
      z.object({
        tabId: z.number().int().positive().describe("The exact Tab ID number from [Tab ID: xxxxx] in get_tabs output - NOT the display number"),
      })
    ),
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively communicates key behavioral traits: the destructive nature ('Close'), the robustness ('IMMUNE to tab reordering, window changes, and index shifting'), and the specific data source requirement ('Extract the Tab ID from get_tabs output'). It doesn't mention error conditions or what happens if the tab doesn't exist.

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 front-loaded with the core purpose in the first sentence, followed by important behavioral context, then specific implementation guidance with a concrete example. Every sentence earns its place with no wasted words, and the structure flows logically from general to specific.

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

Completeness4/5

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

For a single-parameter destructive tool with no annotations and no output schema, the description does an excellent job covering purpose, usage context, parameter semantics, and key behavioral traits. The only minor gap is the lack of information about return values or error conditions, but given the tool's simplicity and the comprehensive parameter coverage, this is acceptable.

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 significant value by explaining where the tabId comes from ('Extract the Tab ID from [Tab ID: 1234567890] in get_tabs output'), providing a concrete example with format, and clarifying what it is NOT ('NOT the display number'). This goes well beyond what the schema provides.

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 specific action ('Close a specific tab'), resource ('in Google Chrome'), and mechanism ('using its unique tab ID'). It explicitly distinguishes this tool from its sibling 'close_tab' by emphasizing the ID-based approach and immunity to tab reordering.

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 guidance on when to use this tool ('PREFERRED METHOD'), when not to use it (vs. index-based alternatives), and references the exact alternative sibling tool 'get_tabs' as the source for obtaining the required tab ID. It clearly establishes the prerequisite relationship with get_tabs.

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