Skip to main content
Glama

close_tab

Automatically close a specific tab in Firefox using the Firefox MCP Server. Simplify browser automation by targeting tabs with their unique ID for efficient control and debugging.

Instructions

Close a specific tab

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tabIdYes

Implementation Reference

  • The main handler function for the 'close_tab' tool. It closes the specified tab's page, removes it from the pages map, clears associated debug buffers, updates the active tab if necessary, and returns a success message.
    async closeTab(args) {
      const { tabId } = args;
      
      if (!this.pages.has(tabId)) {
        throw new Error(`Tab '${tabId}' not found`);
      }
    
      const page = this.pages.get(tabId);
      await page.close();
      this.pages.delete(tabId);
      
      // Clear debug buffers
      this.clearTabDebugBuffers(tabId);
    
      // If this was the active tab, clear active tab
      if (this.activeTabId === tabId) {
        this.activeTabId = this.pages.size > 0 ? Array.from(this.pages.keys())[0] : null;
      }
    
      return {
        content: [{
          type: 'text',
          text: `Tab '${tabId}' closed and debug buffers cleared.${this.activeTabId ? ` Active tab is now '${this.activeTabId}'` : ''}`
        }]
      };
    }
  • Dispatch/registration in the tool request handler switch statement, which calls the closeTab method when 'close_tab' is invoked.
    case 'close_tab':
      return await this.closeTab(args);
  • Tool schema definition in the listTools response, specifying the name, description, and input schema requiring 'tabId'.
    name: 'close_tab',
    description: 'Close a specific tab',
    inputSchema: {
      type: 'object',
      properties: { tabId: { type: 'string' } },
      required: ['tabId']
    }
  • Helper method called by closeTab to clear debug buffers associated with the closed tab.
    clearTabDebugBuffers(tabId) {
      this.consoleLogs.delete(tabId);
      this.jsErrors.delete(tabId);
      this.networkActivity.delete(tabId);
      this.wsMessages.delete(tabId);
      this.performanceMetrics.delete(tabId);
    }

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/JediLuke/firefox-mcp-server'

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