Skip to main content
Glama
williamvd4

Playwright Server

by williamvd4

playwright_click

Automate browser interactions by clicking elements on web pages using CSS selectors for testing and automation workflows.

Instructions

Click an element on the page using CSS selector

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for element to click

Implementation Reference

  • The ClickToolHandler class implements the core logic for the 'playwright_click' tool. It clicks on the element matching the provided CSS selector using Playwright's page.locator().click() method.
    class ClickToolHandler(ToolHandler):
        @update_page_after_click
        async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
            if not self._sessions:
                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"]
            selector = arguments.get("selector")
            await page.locator(selector).click()
            return [types.TextContent(type="text", text=f"Clicked element with selector {selector}")]
  • The JSON schema defining the input for the 'playwright_click' tool, specifying a required 'selector' string parameter.
    types.Tool(
        name="playwright_click",
        description="Click an element on the page using CSS selector",
        inputSchema={
            "type": "object",
            "properties": {
                "selector": {"type": "string", "description": "CSS selector for element to click"}
            },
            "required": ["selector"]
        }
    ),
  • Registration of the 'playwright_click' tool handler in the tool_handlers dictionary, mapping the tool name to an instance of ClickToolHandler.
    "playwright_click": ClickToolHandler(),
  • Decorator applied to the click handler to automatically update the page reference after clicks that may trigger new page loads.
    def update_page_after_click(func):
        async def wrapper(self, name: str, arguments: dict | None):
            if not self._sessions:
                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"]
            
            new_page_future = asyncio.ensure_future(page.context.wait_for_event("page", timeout=3000))
            
            result = await func(self, name, arguments)
            try:
                new_page = await new_page_future
                await new_page.wait_for_load_state()
                self._sessions[session_id]["page"] = new_page
            except:
                pass
                # if page.url != self._sessions[session_id]["page"].url:
                #     await page.wait_for_load_state()
                #     self._sessions[session_id]["page"] = page
            
            return result
        return wrapper
  • The 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}")

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
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 states the basic action but lacks critical details: it doesn't mention error handling (e.g., what happens if the selector doesn't exist), whether it waits for the element to be clickable, if it triggers page navigation, or any side effects like opening new windows. This leaves significant gaps for safe and effective use.

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, clear sentence with zero wasted words. It front-loads the key action ('click') and efficiently conveys the essential information (target and method), making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given the complexity of a browser automation tool with no annotations and no output schema, the description is insufficient. It omits behavioral traits (e.g., error handling, waiting behavior), output details, and guidance on usage relative to siblings. For a tool that interacts with dynamic web pages, more context is needed to ensure reliable agent operation.

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 'selector' fully documented in the schema as 'CSS selector for element to click'. The description adds no additional semantic context beyond implying the parameter is used for clicking, so it meets the baseline of 3 where the schema does the heavy lifting without extra value from the description.

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 action ('click') and target ('element on the page'), and specifies the method ('using CSS selector'). It distinguishes itself from generic clicking by mentioning the CSS selector approach, though it doesn't explicitly differentiate from its sibling 'playwright_click_text' which presumably clicks based on text content rather than selector.

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 like 'playwright_click_text' (for text-based clicking) or other interaction tools such as 'playwright_fill'. There's no mention of prerequisites (e.g., requiring a page to be loaded) or typical use cases, leaving the agent to infer usage from context alone.

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