select_page
Switch between browser tabs by index, URL, or title to control which webpage is currently active for automation tasks.
Instructions
Select the active tab by index (preferred), or by matching URL/title. Index takes precedence when multiple parameters are provided.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pageIdx | No | The index of the page to select (e.g., 0, 1, 2). Use list_pages first to see all available page indices. Most reliable method. | |
| title | No | Select page by title (partial match, case-insensitive). Example: "Google" will match "Google Search - About" | |
| url | No | Select page by URL (partial match, case-insensitive). Example: "github.com" will match "https://github.com/user/repo" |
Implementation Reference
- src/tools/pages.ts:170-219 (handler)Core implementation of the select_page tool handler. Selects Firefox tab by index (highest priority), URL substring, or title substring. Refreshes tab list, validates selection, calls firefox.selectTab().export async function handleSelectPage(args: unknown): Promise<McpToolResponse> { try { const { pageIdx, url, title } = args as { pageIdx?: number; url?: string; title?: string }; const { getFirefox } = await import('../index.js'); const firefox = await getFirefox(); // Refresh tabs to get latest list await firefox.refreshTabs(); const tabs = firefox.getTabs(); let selectedIdx: number; // Priority 1: Select by index if (typeof pageIdx === 'number') { selectedIdx = pageIdx; } // Priority 2: Select by URL pattern else if (url && typeof url === 'string') { const urlLower = url.toLowerCase(); const foundIdx = tabs.findIndex((tab) => tab.url?.toLowerCase().includes(urlLower)); if (foundIdx === -1) { throw new Error(`No page matching URL "${url}"`); } selectedIdx = foundIdx; } // Priority 3: Select by title pattern else if (title && typeof title === 'string') { const titleLower = title.toLowerCase(); const foundIdx = tabs.findIndex((tab) => tab.title?.toLowerCase().includes(titleLower)); if (foundIdx === -1) { throw new Error(`No page matching title "${title}"`); } selectedIdx = foundIdx; } else { throw new Error('Provide pageIdx, url, or title'); } // Validate the selected index if (!tabs[selectedIdx]) { throw new Error(`Page [${selectedIdx}] not found`); } // Select the tab await firefox.selectTab(selectedIdx); return successResponse(`✅ selected [${selectedIdx}]`); } catch (error) { return errorResponse(error as Error); }
- src/tools/pages.ts:48-69 (schema)Input schema definition for the select_page tool, defining optional parameters pageIdx, url, title.export const selectPageTool = { name: 'select_page', description: 'Select active tab by index, URL, or title. Index takes precedence.', inputSchema: { type: 'object', properties: { pageIdx: { type: 'number', description: 'Tab index (0-based, most reliable)', }, url: { type: 'string', description: 'URL substring (case-insensitive)', }, title: { type: 'string', description: 'Title substring (case-insensitive)', }, }, required: [], }, };
- src/index.ts:111-111 (registration)Registers 'select_page' tool name to handleSelectPage function in the MCP server toolHandlers Map.['select_page', tools.handleSelectPage],
- src/index.ts:155-155 (registration)Includes selectPageTool schema in the allTools array returned by listTools MCP handler.tools.selectPageTool,
- src/tools/index.ts:6-17 (registration)Re-exports selectPageTool schema and handleSelectPage handler from pages.js for centralized tool access.export { listPagesTool, newPageTool, navigatePageTool, selectPageTool, closePageTool, handleListPages, handleNewPage, handleNavigatePage, handleSelectPage, handleClosePage, } from './pages.js';