Skip to main content
Glama

switch_page

Navigate to a specified browser page by providing its unique ID, enabling efficient page management in automated browser tasks.

Instructions

Switch to a different browser page

Input Schema

NameRequiredDescriptionDefault
page_idYes

Input Schema (JSON Schema)

{ "properties": { "page_id": { "type": "string" } }, "required": [ "page_id" ], "type": "object" }

Implementation Reference

  • The core handler logic for the 'switch_page' tool. It extracts the page_id from arguments, validates its presence and existence in the pages dictionary, updates the global current_page_id to switch the active page, and returns a confirmation message.
    elif name == "switch_page": page_id = arguments.get("page_id") if not page_id: raise ValueError("Page ID is required") if page_id not in pages: raise ValueError(f"Page ID '{page_id}' not found") current_page_id = page_id return [types.TextContent(type="text", text=f"Switched to page: {page_id}")]
  • The tool schema definition registered in handle_list_tools(), specifying the input schema requiring a 'page_id' string parameter.
    types.Tool( name="switch_page", description="Switch to a different browser page", inputSchema={ "type": "object", "properties": { "page_id": {"type": "string"}, }, "required": ["page_id"], }, ),
  • The registration of all tools including 'switch_page' via the MCP list_tools() endpoint implementation.
    @server.list_tools() async def handle_list_tools() -> list[types.Tool]: """ List available Playwright browser automation tools. """ return [ types.Tool( name="navigate", description="Navigate to a URL", inputSchema={ "type": "object", "properties": { "url": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["url"], }, ), types.Tool( name="click", description="Click on an element by selector", inputSchema={ "type": "object", "properties": { "selector": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["selector"], }, ), types.Tool( name="type", description="Type text into an input element", inputSchema={ "type": "object", "properties": { "selector": {"type": "string"}, "text": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["selector", "text"], }, ), types.Tool( name="get_text", description="Get text content from an element", inputSchema={ "type": "object", "properties": { "selector": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["selector"], }, ), types.Tool( name="get_page_content", description="Get the current page HTML content", inputSchema={ "type": "object", "properties": { "page_id": {"type": "string"}, }, }, ), types.Tool( name="take_screenshot", description="Take a screenshot of the current page", inputSchema={ "type": "object", "properties": { "page_id": {"type": "string"}, "selector": {"type": "string"}, }, }, ), types.Tool( name="new_page", description="Create a new browser page", inputSchema={ "type": "object", "properties": { "page_id": {"type": "string"}, }, "required": ["page_id"], }, ), types.Tool( name="switch_page", description="Switch to a different browser page", inputSchema={ "type": "object", "properties": { "page_id": {"type": "string"}, }, "required": ["page_id"], }, ), types.Tool( name="get_pages", description="List all available browser pages", inputSchema={ "type": "object", "properties": {}, }, ), types.Tool( name="wait_for_selector", description="Wait for an element to be visible on the page", inputSchema={ "type": "object", "properties": { "selector": {"type": "string"}, "page_id": {"type": "string"}, "timeout": {"type": "number"}, }, "required": ["selector"], }, ), ]

Other Tools

Related Tools

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/misanthropic-ai/playwrite-mcp'

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