Skip to main content
Glama
ziux

Playwright Server MCP

by ziux

playwright_navigate

Automate web browser navigation to a specified URL; creates a new session if none exists. Simplify web interactions with Playwright Server MCP‘s browser control capabilities.

Instructions

浏览器导航到指定网址,如果没有活跃的浏览器会话,会自动创建一个新会话

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes需要访问的网址,如不包含http或https前缀将自动添加https://

Implementation Reference

  • The core handler function that executes the playwright_navigate tool: checks for active session, navigates to the provided URL using page.goto(), fetches page text content, and returns success message.
    async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        logger.info("开始浏览器导航操作")
        if not self._sessions:
            logger.warning("没有活跃的会话,正在创建新会话")
            await NewSessionToolHandler().handle("",{})
            # return [types.TextContent(type="text", text="No active session. Please create a new session first.")]
        try:
            page = self.get_page()
            url = arguments.get("url")
            if not url.startswith("http://") and not url.startswith("https://"):
                url = "https://" + url
            logger.info(f"正在导航到 URL: {url}")
            await page.goto(url)
            logger.debug(f"导航完成, 当前URL: {page.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]}")]
        except Exception as e:
            logger.error(f"导航失败: {str(e)}", exc_info=True)
            return [types.TextContent(type="text", text=f"导航失败: {str(e)}")]
  • Tool metadata including name, description, and inputSchema defining the 'url' parameter for the playwright_navigate tool.
    class NavigateToolHandler(ToolHandler):
        name = "playwright_navigate"
        description = "浏览器导航到指定网址,如果没有活跃的浏览器会话,会自动创建一个新会话"
        inputSchema = [
            Property(name="url", typ="string", description="需要访问的网址,如不包含http或https前缀将自动添加https://")
        ]
  • Instantiates NavigateToolHandler and registers it in tool_handler_list and tool_handlers dict, which is used in list_tools() and call_tool() for MCP server.
    tool_handler_list = [
        NavigateToolHandler(),
        # ScreenshotToolHandler(),
        EvaluateToolHandler(),
        GetTextContentToolHandler(),
        GetHtmlContentToolHandler(),
        NewSessionToolHandler(),
        ActionToolHandler()
    ]
    
    # 根据每个处理程序的 name 属性创建字典
    tool_handlers = {handler.name: handler for handler in tool_handler_list}
  • The to_tool classmethod in base ToolHandler converts handler metadata to MCP Tool object, used during registration in list_tools().
    def to_tool(cls) -> types.Tool:
        return types.Tool(
            name=cls.name,
            description=cls.description,
            inputSchema={
                "type": "object",
                "properties": {
                        property.name: {
                        "type": property.typ,
                        "description": property.description
                    }
                    for property in cls.inputSchema
                },
                "required": [property.name for property in cls.inputSchema if property.required]
            }
        )
  • MCP server endpoint that lists tools by calling to_tool() on registered handlers, exposing playwright_navigate.
    @server.list_tools()
    async def handle_list_tools() -> list[types.Tool]:
        """
        List available tools.
        Each tool specifies its arguments using JSON Schema validation.
        """
        logger.debug("处理 list_tools 请求")
        return [
            tool_handler.to_tool() for tool_handler in tool_handlers.values()
        ]
Install Server

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

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