Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

click

Automate web interactions by clicking elements using CSS selectors for browser automation tasks like testing and data extraction.

Instructions

Click an element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYes

Implementation Reference

  • The core handler function implementing the click tool logic using Playwright's page.click for the given selector.
    async click(selector?: string): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } if (selector) { this.log('Clicking element', selector); await this.state.page.click(selector); } else { this.log('Clicking at position', this.currentMousePosition); await this.state.page.mouse.click(this.currentMousePosition.x, this.currentMousePosition.y); } this.log('Click complete'); } catch (error: any) { console.error('Click error:', error); throw new BrowserError( 'Failed to click', selector ? 'Check if the element exists and is visible' : 'Check if mouse position is valid' ); } }
  • Schema definition for the 'click' tool, specifying name, description, and required 'selector' input.
    const CLICK_TOOL: Tool = { name: "click", description: "Click an element", inputSchema: { type: "object", properties: { selector: { type: "string" } }, required: ["selector"] } };
  • MCP callTool handler case for 'click' that validates the selector argument and invokes the Playwright controller.
    case 'click': { if (!args.selector) { return { content: [{ type: "text", text: "Selector is required" }], isError: true }; } await playwrightController.click(args.selector as string); return { content: [{ type: "text", text: "Click successful" }] }; }
  • src/server.ts:555-565 (registration)
    Server initialization that registers the tools object (including 'click' tool) in MCP capabilities.
    const server = new Server( { name: "playmcp-browser", version: "1.0.0", }, { capabilities: { tools, }, } );
  • src/server.ts:518-518 (registration)
    Specific registration of the 'click' tool in the tools dictionary used for MCP server capabilities.
    click: CLICK_TOOL,

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/jomon003/PlayMCP'

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