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
| Name | Required | Description | Default |
|---|---|---|---|
| pageIdx | Yes | The index of the page to close |
Implementation Reference
- src/tools/pages.ts:222-248 (handler)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); } }
- src/tools/pages.ts:71-84 (schema)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,
- src/tools/index.ts:11-17 (registration)Re-export of closePageTool and handleClosePage from pages.ts for central import in index.ts.closePageTool, handleListPages, handleNewPage, handleNavigatePage, handleSelectPage, handleClosePage, } from './pages.js';