Skip to main content
Glama
andytango
by andytango

close_tab

Close browser tabs in Puppeteer automation. Specify a tab ID or close the active tab to manage browser sessions and resources.

Instructions

Close a browser tab. If no tabId provided, closes the active tab.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • Registers the 'close_tab' MCP tool with server.tool(), including description, input schema, and the handler function that determines the target tab, calls closeTab, and returns closed tab info.
    server.tool(
      'close_tab',
      'Close a browser tab. If no tabId provided, closes the active tab.',
      closeTabSchema.shape,
      async ({ tabId }) => {
        const targetId = tabId ?? getActiveTabId();
        const result = await closeTab(tabId);
    
        if (result.success) {
          return handleResult(ok({
            closedTabId: targetId,
            newActiveTabId: getActiveTabId(),
          }));
        }
    
        return handleResult(result);
      }
    );
  • Core handler logic for closing a tab: retrieves the Puppeteer Page, calls page.close(), handles errors and state updates for tabs and active tab.
    export async function closeTab(tabId?: string): Promise<Result<void>> {
      const targetId = tabId ?? state.activeTabId;
    
      if (!targetId) {
        return err(noActiveTab());
      }
    
      const page = state.tabs.get(targetId);
      if (!page) {
        return err(tabNotFound(targetId));
      }
    
      try {
        await page.close();
        // Page close handler will update state
        return ok(undefined);
      } catch (error) {
        // Page may already be closed
        state.tabs.delete(targetId);
        if (state.activeTabId === targetId) {
          const remaining = state.tabs.keys().next();
          state.activeTabId = remaining.done ? null : remaining.value;
        }
        return ok(undefined);
      }
    }
  • Zod schema defining the input for close_tab tool: optional tabId string.
    export const closeTabSchema = z.object({
      tabId: tabIdSchema,
    });
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses the tool's behavior (closing tabs, defaulting to active tab) but lacks details on permissions needed, whether the action is reversible, potential side effects (e.g., losing unsaved data), or error handling. It adds basic context but misses deeper behavioral traits.

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 front-loaded with the core purpose in the first sentence and adds conditional behavior in the second. Every sentence earns its place with no wasted words, making it highly efficient and easy to parse.

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

Completeness3/5

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

Given the tool's moderate complexity (destructive action with one parameter) and no annotations or output schema, the description is minimally adequate. It covers the basic operation but lacks information on return values, error cases, or integration with sibling tools, leaving gaps for an AI agent to infer 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?

Schema description coverage is 100%, so the schema already documents the 'tabId' parameter. The description adds value by explaining the default behavior (closes active tab if not specified), which clarifies semantics beyond the schema's technical details. However, it does not elaborate on parameter format or constraints.

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 browser tab') and the resource ('browser tab'), distinguishing it from siblings like 'list_tabs', 'new_tab', or 'switch_tab'. It precisely defines the verb and target, making the purpose unambiguous.

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

Usage Guidelines4/5

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

The description provides clear context for when to use it (to close a tab) and specifies behavior based on parameter presence (closes active tab if no tabId). However, it does not explicitly state when not to use it or mention alternatives like 'switch_tab' for changing tabs without closing, which could help differentiate usage scenarios.

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

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/andytango/puppeteer-mcp'

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