Skip to main content
Glama
williamvd4

Playwright Server

by williamvd4

playwright_navigate

Navigate to a specified URL in a browser session for web automation tasks.

Instructions

Navigate to a URL,thip op will auto create a session

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • Implementation of the NavigateToolHandler class with the handle method that performs navigation using Playwright's page.goto() and fetches text content.
    class NavigateToolHandler(ToolHandler):
        async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
            if not self._sessions:
                await NewSessionToolHandler().handle("",{})
                # return [types.TextContent(type="text", text="No active session. Please create a new session first.")]
            session_id = list(self._sessions.keys())[-1]
            page = self._sessions[session_id]["page"]
            url = arguments.get("url")
            if not url.startswith("http://") and not url.startswith("https://"):
                url = "https://" + url
            await page.goto(url)
            text_content=await GetTextContentToolHandler().handle("",{})
            return [types.TextContent(type="text", text=f"Navigated to {url}\npage_text_content[:200]:\n\n{text_content[:200]}")]
  • JSON schema definition for the playwright_navigate tool input, requiring a 'url' string.
    types.Tool(
        name="playwright_navigate",
        description="Navigate to a URL,thip op will auto create a session",
        inputSchema={
            "type": "object",
            "properties": {
                "url": {"type": "string"}
            },
            "required": ["url"]
        }
    ),
  • Dictionary registering the NavigateToolHandler instance under the key 'playwright_navigate' for tool dispatching.
    tool_handlers = {
        "playwright_navigate": NavigateToolHandler(),
        "playwright_screenshot": ScreenshotToolHandler(),
        "playwright_click": ClickToolHandler(),
        "playwright_fill": FillToolHandler(),
        "playwright_evaluate": EvaluateToolHandler(),
        "playwright_click_text": ClickTextToolHandler(),
        "playwright_get_text_content": GetTextContentToolHandler(),
        "playwright_get_html_content": GetHtmlContentToolHandler(),
        "playwright_new_session":NewSessionToolHandler(),
    }
  • MCP server tool call handler that dispatches to the registered tool_handlers based on the tool name.
    @server.call_tool()
    async def handle_call_tool(
        name: str, arguments: dict | None
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """
        Handle tool execution requests.
        Tools can modify server state and notify clients of changes.
        """
        if name in tool_handlers:
            return await tool_handlers[name].handle(name, arguments)
        else:
            raise ValueError(f"Unknown tool: {name}")

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/williamvd4/playwright-plus-python-mcp'

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