switch_tab
Switch between browser tabs to make a specific tab active for automated interactions like navigation, content extraction, or form filling.
Instructions
Switch to a different tab, making it the active tab for subsequent operations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | Yes | Tab ID to switch to |
Implementation Reference
- dist/tabs.js:183-202 (handler)Core implementation of switching to the specified tab: retrieves the page from state, sets it as active tab ID, brings the page to front, returns tab info on success or tabNotFound error.export async function switchTab(tabId) { const page = state.tabs.get(tabId); if (!page) { return err(tabNotFound(tabId)); } state.activeTabId = tabId; try { // Bring page to front await page.bringToFront(); return ok({ id: tabId, url: page.url(), title: await page.title(), isActive: true, }); } catch (error) { return err(tabNotFound(tabId)); } }
- dist/schemas.js:15-17 (schema)Zod schema defining the input for the switch_tab tool: requires a tabId string.export const switchTabSchema = z.object({ tabId: z.string().describe('Tab ID to switch to'), });
- dist/tools/tab-tools.js:31-34 (registration)Registers the 'switch_tab' MCP tool on the server, using the switchTabSchema for input validation and an inline async handler that delegates to switchTab and wraps the result with handleResult.server.tool('switch_tab', 'Switch to a different tab, making it the active tab for subsequent operations.', switchTabSchema.shape, async ({ tabId }) => { const result = await switchTab(tabId); return handleResult(result); });