Skip to main content
Glama

close_page

Close browser tabs by index to manage multiple pages during automation testing and web scraping workflows.

Instructions

Close the tab at the given index. Use list_pages to find valid indices.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageIdxYesThe index of the page to close

Implementation Reference

  • Handler function for 'close_page' tool. Validates pageIdx argument, refreshes tab list, verifies tab exists, closes the tab via firefox.closeTab(pageIdx), and returns success or error response.
    export async function handleClosePage(args: unknown): Promise<McpToolResponse> { try { const { pageIdx } = args as { pageIdx: number }; if (typeof pageIdx !== 'number') { throw new Error('pageIdx parameter is required and must be a number'); } const { getFirefox } = await import('../index.js'); const firefox = await getFirefox(); // Refresh tabs to get latest list await firefox.refreshTabs(); const tabs = firefox.getTabs(); const pageToClose = tabs[pageIdx]; if (!pageToClose) { throw new Error(`Page with index ${pageIdx} not found`); } await firefox.closeTab(pageIdx); return successResponse(`✅ closed [${pageIdx}]`); } catch (error) { return errorResponse(error as Error); } }
  • Tool schema definition for 'close_page', specifying name, description, and input schema requiring a numeric 'pageIdx'.
    export const closePageTool = { name: 'close_page', description: 'Close tab by index.', inputSchema: { type: 'object', properties: { pageIdx: { type: 'number', description: 'Tab index to close', }, }, required: ['pageIdx'], }, };
  • src/index.ts:112-112 (registration)
    Registration of the 'close_page' handler in the toolHandlers Map used for executing tools.
    ['close_page', tools.handleClosePage],
  • src/index.ts:156-156 (registration)
    Inclusion of closePageTool in the allTools array returned by list_tools.
    tools.closePageTool,
  • Re-export of closePageTool and handleClosePage from pages.ts for central import in index.ts.
    closePageTool, handleListPages, handleNewPage, handleNavigatePage, handleSelectPage, handleClosePage, } from './pages.js';

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/freema/firefox-devtools-mcp'

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