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}")
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions clicking but doesn't disclose behavioral traits such as whether it waits for the element to be clickable, handles dynamic content, throws errors if the selector doesn't match, or if it triggers page navigation. For a mutation tool with zero annotation coverage, this is a significant gap in safety and operational context.

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 with zero waste. It's front-loaded with the core action and method, making it easy to parse quickly. Every word earns its place without redundancy.

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 web automation click action, no annotations, and no output schema, the description is incomplete. It lacks crucial context like error handling, interaction effects (e.g., page changes), or performance considerations. This is inadequate for a mutation tool that could fail or cause unintended side effects.

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?

Schema description coverage is 100%, with the parameter 'selector' fully documented in the schema as 'CSS selector for element to click'. The description adds no additional meaning beyond this, such as examples of valid selectors or constraints. Baseline 3 is appropriate since the schema does the heavy lifting.

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 ('an element on the page') with the method ('using CSS selector'). It distinguishes itself from siblings like playwright_click_text (which likely clicks based on text content) and playwright_fill (which fills forms). However, it doesn't explicitly mention it's for web automation/Playwright context beyond the tool name.

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?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a page to be loaded first via playwright_navigate), when to prefer playwright_click_text for text-based selection, or any constraints like element visibility. The description only states what it does, not when to use it.

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

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