Skip to main content
Glama
blackwhite084

Playwright Server MCP

playwright_click

Click web page elements using CSS selectors for browser automation and testing with Playwright.

Instructions

Click an element on the page using CSS selector

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for element to click

Implementation Reference

  • ClickToolHandler class implementing the core logic for the playwright_click tool by clicking the Playwright page locator for the given selector.
    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}")]
  • Pydantic/JSON schema definition for the input arguments of the playwright_click tool.
    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"]
        }
    ),
  • Dictionary registering all tool names to their handler instances, including playwright_click to ClickToolHandler().
    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(),
    }
  • Decorator applied to the click handler's handle method to detect and update to new pages after potential navigation triggered by the click.
    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
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.

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

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