Skip to main content
Glama
b3nw
by b3nw

Click Element

browser_click

Simulate mouse clicks on web page elements using CSS selectors for automated browser interaction and testing.

Instructions

Click on an element specified by selector

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYes

Implementation Reference

  • The handler function that implements the core logic of the browser_click tool. It validates the selector input using Zod, ensures the Playwright browser is connected, retrieves the current page, executes page.click(selector), and returns a success message or error response in MCP format.
    async (params: any) => {
      try {
        const input = z.object({
          selector: z.string()
        }).parse(params);
        await this.playwright.ensureConnected();
        
        const page = this.playwright.getPage();
        await page.click(input.selector);
        
        return {
          content: [{
            type: 'text',
            text: `Successfully clicked element: ${input.selector}`
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `Click failed: ${error instanceof Error ? error.message : String(error)}`
          }],
          isError: true
        };
      }
    }
  • src/server.ts:155-190 (registration)
    The registration of the 'browser_click' tool in the MCP server using registerTool, including tool metadata (title, description), inline input schema, and the handler function.
    this.server.registerTool(
      'browser_click',
      {
        title: 'Click Element',
        description: 'Click on an element specified by selector',
        inputSchema: {
          selector: z.string()
        }
      },
      async (params: any) => {
        try {
          const input = z.object({
            selector: z.string()
          }).parse(params);
          await this.playwright.ensureConnected();
          
          const page = this.playwright.getPage();
          await page.click(input.selector);
          
          return {
            content: [{
              type: 'text',
              text: `Successfully clicked element: ${input.selector}`
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: 'text',
              text: `Click failed: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
  • Zod input schema definition for the browser_click tool parameters (selector: string). Matches the inline schema used in registration.
    export const BrowserClickInputSchema = z.object({
      selector: z.string()
    });
  • Helper method in PlaywrightManager called by the handler to ensure the browser connection is active before performing the click operation.
    async ensureConnected(): Promise<void> {
      const connected = await this.isConnected();
      if (!connected) {
        await this.cleanup();
        await this.connect();
      }
    }
  • Helper method in PlaywrightManager to retrieve the current Playwright Page instance used for executing page.click().
    getPage(): Page {
      if (!this.page) {
        throw new Error('Playwright not connected. Call connect() first.');
      }
      return this.page;
    }
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 action ('click') but doesn't mention potential side effects (e.g., page navigation, form submissions), error handling, or performance considerations. This leaves significant gaps for a mutation tool in a browser 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, front-loading the core action. It's appropriately sized for a simple tool, making it easy 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?

For a mutation tool with no annotations, no output schema, and minimal parameter guidance, the description is incomplete. It doesn't address return values, error cases, or integration with sibling tools, leaving the agent with insufficient context for reliable use in a browser automation scenario.

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 description adds minimal meaning beyond the input schema, which has 0% description coverage for the single 'selector' parameter. It implies the selector specifies the element to click but doesn't explain selector syntax, types (e.g., CSS, XPath), or validation. Given the low schema coverage, this is inadequate compensation, but it provides a baseline understanding.

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 on') and target ('an element specified by selector'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like browser_evaluate or browser_type, which might also interact with elements, so it doesn't reach the highest score.

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 browser_evaluate for JavaScript interactions or browser_type for text input. It lacks explicit context, exclusions, or prerequisites, offering only a basic functional statement.

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/b3nw/playwright-mcp-server'

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