Skip to main content
Glama
ziux

Playwright Server MCP

by ziux

playwright_new_session

Create and manage new browser sessions to open windows and optionally navigate to specified URLs using browser automation capabilities.

Instructions

创建新的浏览器会话,打开一个浏览器窗口并可选择性地访问指定网址

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlNo需要访问的初始网址,可选参数,不填则只打开浏览器

Implementation Reference

  • NewSessionToolHandler class implements the core logic for the 'playwright_new_session' tool, launching a new Chromium browser instance, creating a page, managing sessions, and optionally navigating to a URL.
    class NewSessionToolHandler(ToolHandler):
        name = "playwright_new_session"
        description = "创建新的浏览器会话,打开一个浏览器窗口并可选择性地访问指定网址"
        inputSchema = [
            Property(name="url", typ="string", description="需要访问的初始网址,可选参数,不填则只打开浏览器", required=False)
        ]
        
        async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
            logger.info("开始创建新的浏览器会话")
            try:
                self._playwright = await async_playwright().start()
                logger.debug("Playwright 实例已创建")
                
                browser = await self._playwright.chromium.launch(headless=False)
                logger.debug("浏览器已启动")
                
                page = await browser.new_page()
                logger.debug("新页面已创建")
                
                session_id = str(uuid.uuid4())
                self._sessions[session_id] = {"browser": browser, "page": page}
                logger.info(f"会话已创建,ID: {session_id}")
                
                url = arguments.get("url")
                if 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}")
                return [types.TextContent(type="text", text="succ")]
            except Exception as e:
                logger.error(f"创建会话失败: {str(e)}", exc_info=True)
                return [types.TextContent(type="text", text=f"创建会话失败: {str(e)}")]
  • Defines the input schema for the tool, with an optional 'url' parameter of type string.
    inputSchema = [
        Property(name="url", typ="string", description="需要访问的初始网址,可选参数,不填则只打开浏览器", required=False)
    ]
  • Registers the NewSessionToolHandler instance in tool_handler_list and creates tool_handlers dictionary mapped by name, used by MCP server for list_tools() and call_tool().
    tool_handler_list = [
        NavigateToolHandler(),
        # ScreenshotToolHandler(),
        EvaluateToolHandler(),
        GetTextContentToolHandler(),
        GetHtmlContentToolHandler(),
        NewSessionToolHandler(),
        ActionToolHandler()
    ]
    
    # 根据每个处理程序的 name 属性创建字典
    tool_handlers = {handler.name: handler for handler in tool_handler_list}
  • Imports the NewSessionToolHandler class required for registration.
    from playwright_server.tools.handles import NavigateToolHandler, ScreenshotToolHandler, EvaluateToolHandler, GetTextContentToolHandler, GetHtmlContentToolHandler, NewSessionToolHandler
  • ToolHandler base class method to_tool() converts the handler's name, description, and inputSchema into MCP Tool object for registration in list_tools().
    @classmethod
    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]
            }
        )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions creating a session and optionally visiting a URL, but doesn't describe what type of browser is opened (e.g., headless vs. headed), session lifecycle (e.g., how long it persists, how to close it), authentication needs, or performance implications. For a session creation tool with zero annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that clearly states the core functionality: session creation, window opening, and optional URL navigation. There's no wasted verbiage or redundant information, making it appropriately front-loaded and concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (session creation with optional navigation), no annotations, no output schema, and 100% schema coverage for the single parameter, the description is minimally adequate. It covers the basic purpose but lacks details about session management, browser configuration, or integration with sibling tools, leaving room for improvement in completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the single parameter 'url' well-documented in the schema as '需要访问的初始网址,可选参数,不填则只打开浏览器' (initial URL to visit, optional parameter, if not filled then only opens browser). The description adds no additional parameter semantics beyond what's already in the schema, so the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '创建新的浏览器会话,打开一个浏览器窗口并可选择性地访问指定网址' (Create a new browser session, open a browser window and optionally visit a specified URL). It specifies the verb ('创建新的浏览器会话' - create new browser session) and resource ('浏览器窗口' - browser window), but doesn't explicitly differentiate from sibling tools like 'playwright_navigate' which might also involve URL navigation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'playwright_navigate' (for navigation within existing sessions) or 'playwright_action' (for performing actions), nor does it specify prerequisites or appropriate contexts for session creation versus using existing sessions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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