Skip to main content
Glama
tab-tools.ts1.7 kB
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { listTabsSchema, newTabSchema, closeTabSchema, switchTabSchema } from '../schemas.js'; import { createTab, closeTab, listTabs, switchTab, getActiveTabId } from '../tabs.js'; import { handleResult, ok } from '../errors.js'; /** * Register tab management tools */ export function registerTabTools(server: McpServer): void { // List all tabs server.tool( 'list_tabs', 'List all open browser tabs with their IDs, URLs, and titles', listTabsSchema.shape, async () => { const tabs = await listTabs(); return handleResult(ok({ tabs })); } ); // Create new tab server.tool( 'new_tab', 'Open a new browser tab, optionally navigating to a URL. The new tab becomes active.', newTabSchema.shape, async ({ url }) => { const result = await createTab(url); return handleResult(result); } ); // Close tab server.tool( 'close_tab', 'Close a browser tab. If no tabId provided, closes the active tab.', closeTabSchema.shape, async ({ tabId }) => { const targetId = tabId ?? getActiveTabId(); const result = await closeTab(tabId); if (result.success) { return handleResult(ok({ closedTabId: targetId, newActiveTabId: getActiveTabId(), })); } return handleResult(result); } ); // Switch tab 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); } ); }

Implementation Reference

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/andytango/puppeteer-mcp'

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