Skip to main content
Glama
cloudflare

Cloudflare Playwright MCP

Official
by cloudflare

browser_click

Simulate single or double clicks on web page elements using human-readable descriptions or exact references. Integrates with Playwright for automated browser testing and Cloudflare Workers.

Instructions

Perform click on a web page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
buttonNoButton to click, defaults to left
doubleClickNoWhether to perform a double click instead of a single click
elementYesHuman-readable element description used to obtain permission to interact with the element
refYesExact target element reference from the page snapshot

Implementation Reference

  • The main handler function that performs the click or double-click action on the target element using Playwright locators derived from the page snapshot. Generates corresponding code snippets and executes the action.
    handle: async (context, params) => { const tab = context.currentTabOrDie(); const locator = tab.snapshotOrDie().refLocator(params); const code: string[] = []; if (params.doubleClick) { code.push(`// Double click ${params.element}`); code.push(`await page.${await generateLocator(locator)}.dblclick();`); } else { code.push(`// Click ${params.element}`); code.push(`await page.${await generateLocator(locator)}.click();`); } return { code, action: () => params.doubleClick ? locator.dblclick() : locator.click(), captureSnapshot: true, waitForNetwork: true, }; },
  • Zod schemas defining the input parameters for the browser_click tool: elementSchema for element description and ref, extended by clickSchema with optional doubleClick boolean.
    const elementSchema = z.object({ element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'), ref: z.string().describe('Exact target element reference from the page snapshot'), }); const clickSchema = elementSchema.extend({ doubleClick: z.coerce.boolean().optional().describe('Whether to perform a double click instead of a single click'), });
  • Tool registration using defineTool, specifying name 'browser_click', schema, capability, and handler. This Tool object is exported and included in snapshotTools for MCP server registration.
    const click = defineTool({ capability: 'core', schema: { name: 'browser_click', title: 'Click', description: 'Perform click on a web page', inputSchema: clickSchema, type: 'destructive', }, handle: async (context, params) => { const tab = context.currentTabOrDie(); const locator = tab.snapshotOrDie().refLocator(params); const code: string[] = []; if (params.doubleClick) { code.push(`// Double click ${params.element}`); code.push(`await page.${await generateLocator(locator)}.dblclick();`); } else { code.push(`// Click ${params.element}`); code.push(`await page.${await generateLocator(locator)}.click();`); } return { code, action: () => params.doubleClick ? locator.dblclick() : locator.click(), captureSnapshot: true, waitForNetwork: true, }; }, });
  • src/tools.ts:35-50 (registration)
    Collects all snapshot tools including those from snapshot.ts (containing browser_click) into snapshotTools array, used for registration in the MCP connection.
    export const snapshotTools: Tool<any>[] = [ ...common(true), ...console, ...dialogs(true), ...files(true), ...install, ...keyboard(true), ...navigate(true), ...network, ...pdf, ...screenshot, ...snapshot, ...tabs(true), ...testing, ...wait(true), ];
  • Selects and filters tools including browser_click based on config, passes to Context, and registers handlers for listTools and callTool in the MCP server.
    const allTools = config.vision ? visionTools : snapshotTools; const tools = allTools.filter(tool => !config.capabilities || tool.capability === 'core' || config.capabilities.includes(tool.capability)); const context = new Context(tools, config, browserContextFactory);

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

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