Skip to main content
Glama
VikashLoomba

MCP-Server-Playwright

browser_click_text

Click web page elements by their visible text content to automate interactions in a browser environment.

Instructions

Click an element on the page by its text content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesText content of the element to click

Implementation Reference

  • Handler for the 'browser_click_text' tool. Uses Playwright's page.getByText() to locate and click an element by its text content. Includes error handling and retry logic for strict mode violations.
    case ToolName.BrowserClickText:
      try {
        await page.getByText(args.text).click();
        return {
          content: [{
            type: "text",
            text: `Clicked element with text: ${args.text}`,
          }],
          isError: false,
        };
      } catch (error) {
        if((error as Error).message.includes("strict mode violation")) {
            console.log("Strict mode violation, retrying on first element...");
            try {
                await page.getByText(args.text).first().click();
                return {
                    content: [{
                        type: "text",
                        text: `Clicked element with text: ${args.text}`,
                    }],
                    isError: false,
                };
            } catch (error) {
                return {
                    content: [{
                        type: "text",
                        text: `Failed (twice) to click element with text ${args.text}: ${(error as Error).message}`,
                    }],
                    isError: true,
                };
            }
        }
        return {
          content: [{
            type: "text",
            text: `Failed to click element with text ${args.text}: ${(error as Error).message}`,
          }],
          isError: true,
        };
      }
  • Input schema definition for the 'browser_click_text' tool, specifying a required 'text' string parameter.
    {
      name: ToolName.BrowserClickText,
      description: "Click an element on the page by its text content",
      inputSchema: {
        type: "object",
        properties: {
          text: { type: "string", description: "Text content of the element to click" },
        },
        required: ["text"],
      },
    },
  • index.ts:644-646 (registration)
    Registers the general tool call handler which dispatches to specific tool implementations including 'browser_click_text' via handleToolCall.
    server.setRequestHandler(CallToolRequestSchema, async (request) =>
      handleToolCall(request.params.name as ToolName, request.params.arguments ?? {})
    );
  • index.ts:640-642 (registration)
    Registers the list tools handler that exposes the 'browser_click_text' tool (via the TOOLS array) to clients.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: TOOLS,
    }));
  • Enum defining tool names, including BrowserClickText = 'browser_click_text' used throughout the code.
    enum ToolName {
      BrowserNavigate = "browser_navigate",
      BrowserScreenshot = "browser_screenshot",
      BrowserClick = "browser_click",
      BrowserClickText = "browser_click_text",
      BrowserFill = "browser_fill",
      BrowserSelect = "browser_select",
      BrowserSelectText = "browser_select_text",
      BrowserHover = "browser_hover",
      BrowserHoverText = "browser_hover_text",
      BrowserEvaluate = "browser_evaluate"
    }
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 of behavioral disclosure. It states the action ('click') but lacks details on what happens after clicking (e.g., page navigation, errors if text not found, or interaction effects). For a tool with no annotations, 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, direct sentence with zero wasted words, making it highly concise and front-loaded. It efficiently conveys the core action without unnecessary elaboration, earning full marks for brevity and clarity.

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 low complexity (1 parameter, no output schema, no annotations), the description is minimally adequate but incomplete. It covers the basic action but lacks context on usage, behavioral outcomes, or error handling, which would enhance completeness for an interactive browser tool.

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 input schema has 100% description coverage, with the single parameter 'text' clearly documented. The description adds no additional meaning beyond the schema, such as examples or constraints (e.g., case sensitivity). With high schema coverage, 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 action ('click') and target ('element on the page by its text content'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'browser_click' (which likely clicks by selector) or 'browser_hover_text' (which hovers rather than clicks), missing full sibling distinction.

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 scenarios where clicking by text is preferred over other methods (e.g., 'browser_click' for selectors) or prerequisites like needing the text to be visible or unique, leaving the agent with no usage context.

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/VikashLoomba/MCP-Server-Playwright'

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