select_tab
Switch to a specific open browser tab to make it active and bring its window to front for interaction.
Instructions
Switch to a specific tab. Use this when you need to interact with a different open tab. Makes the tab active and brings its window to front.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | Yes | ID of the tab to activate (get this from list_tabs) | |
| apiKey | No | API key for authentication if enabled |
Implementation Reference
- src/tools/tab-management.ts:25-43 (registration)The 'select_tab' tool is registered with the MCP server via server.tool(), using Zod schema for input validation (tabId: number, apiKey: optional string).
server.tool( 'select_tab', 'Switch to a specific tab. Use this when you need to interact with a different open tab. Makes the tab active and brings its window to front.', { tabId: z.number().describe('ID of the tab to activate (get this from list_tabs)'), apiKey: z.string().optional().describe('API key for authentication if enabled'), }, async ({ tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'select_tab', params: { tabId }, apiKey, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: `Activated tab ${tabId}` }] }; } ); - src/tools/tab-management.ts:32-42 (handler)The handler function for 'select_tab' sends a command via WebSocketBridge to the Chrome extension with command 'select_tab' and the tabId parameter, then returns success or error.
async ({ tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'select_tab', params: { tabId }, apiKey, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: `Activated tab ${tabId}` }] }; } - src/tools/tab-management.ts:28-31 (schema)Input schema for 'select_tab' using Zod: requires 'tabId' as a number and accepts optional 'apiKey' as a string.
{ tabId: z.number().describe('ID of the tab to activate (get this from list_tabs)'), apiKey: z.string().optional().describe('API key for authentication if enabled'), }, - src/tools/index.ts:29-31 (registration)The 'registerTabManagementTools' function (which registers 'select_tab') is called from 'registerAllTools' in src/tools/index.ts.
export function registerAllTools(server: McpServer, bridge: WebSocketBridge) { registerNavigationTools(server, bridge); registerTabManagementTools(server, bridge); - src/server.ts:5-11 (registration)The MCP server is created and tools are registered via 'registerAllTools' called from 'createServer' in src/server.ts.
export function createServer(bridge: WebSocketBridge): McpServer { const server = new McpServer({ name: 'browser-genie', version: '1.0.0', }); registerAllTools(server, bridge); - src/websocket-bridge.ts:63-103 (helper)The WebSocketBridge.sendCommand method is the underlying helper that sends the 'select_tab' command as a JSON message over WebSocket to the Chrome extension.
async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> { if (!this.isConnected()) { return { success: false, error: { code: 'NOT_CONNECTED', message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.', }, }; } const id = crypto.randomUUID(); const timeout = cmd.timeout ?? DEFAULT_TIMEOUT; return new Promise<BridgeResponse>((resolve, reject) => { const timer = setTimeout(() => { this.pending.delete(id); resolve({ success: false, error: { code: 'TIMEOUT', message: `Command '${cmd.command}' timed out after ${timeout}ms`, }, }); }, timeout); this.pending.set(id, { resolve, reject, timer }); const message = { id, type: 'request', command: cmd.command, params: cmd.params, tabId: cmd.tabId, apiKey: cmd.apiKey, timestamp: Date.now(), }; this.client!.send(JSON.stringify(message)); }); }