click
Click an element using its snapshot reference or CSS selector. Use snapshot first to discover element refs.
Instructions
Click an element. Provide either ref (from snapshot) or CSS selector. Use snapshot first to discover element refs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | Yes | Tab ID from create_tab | |
| ref | No | Element ref from snapshot (e.g. 'e1', 'e2') | |
| selector | No | CSS selector (e.g. 'button.submit', '#login') |
Implementation Reference
- src/tools/interaction.ts:8-45 (handler)Registration and handler for the 'click' tool. Defines the tool with server.tool('click', ...), parses input (tabId, ref, selector), validates that either ref or selector is provided, then calls deps.client.click() and returns the result (success, navigated, refsAvailable).
export function registerInteractionTools(server: McpServer, deps: ToolDeps): void { server.tool( "click", "Click an element. Provide either ref (from snapshot) or CSS selector. Use snapshot first to discover element refs.", { tabId: z.string().min(1).describe("Tab ID from create_tab"), ref: z.string().min(1).optional().describe("Element ref from snapshot (e.g. 'e1', 'e2')"), selector: z.string().min(1).optional().describe("CSS selector (e.g. 'button.submit', '#login')") }, async (input: unknown) => { try { const parsed = z .object({ tabId: z.string().min(1).describe("Tab ID from create_tab"), ref: z.string().min(1).optional().describe("Element ref from snapshot (e.g. 'e1', 'e2')"), selector: z.string().min(1).optional().describe("CSS selector (e.g. 'button.submit', '#login')") }) .refine((data) => Boolean(data.ref || data.selector), { message: "Either 'ref' or 'selector' is required" }) .parse(input); const tracked = getTrackedTab(parsed.tabId); const result = await deps.client.click(parsed.tabId, { ref: parsed.ref, selector: parsed.selector }, tracked.userId); incrementToolCall(parsed.tabId); return okResult({ success: result.success, navigated: result.navigated, refsAvailable: result.refsAvailable }); } catch (error) { return toErrorResult(error); } } ); - src/tools/interaction.ts:12-16 (schema)Input schema for the 'click' tool: tabId (required), ref (optional), selector (optional) with validation that at least one of ref/selector is provided.
{ tabId: z.string().min(1).describe("Tab ID from create_tab"), ref: z.string().min(1).optional().describe("Element ref from snapshot (e.g. 'e1', 'e2')"), selector: z.string().min(1).optional().describe("CSS selector (e.g. 'button.submit', '#login')") }, - src/server.ts:42-42 (registration)Registration point - registerInteractionTools(server, deps) is called to register the click tool on the MCP server.
registerInteractionTools(server, deps); - src/client.ts:86-92 (helper)ClickRawResponseSchema - Zod schema for parsing the raw API response from the click endpoint.
const ClickRawResponseSchema = z .object({ success: z.boolean().optional(), navigated: z.boolean().optional(), refsAvailable: z.boolean().optional() }) .passthrough(); - src/client.ts:407-418 (helper)client.click() method - sends a POST request to /tabs/{tabId}/click with ref/selector params and userId, returns parsed ClickResponse.
async click(tabId: string, params: ClickParams, userId: string): Promise<ClickResponse> { const response = await this.requestJson(`/tabs/${encodeURIComponent(tabId)}/click`, { method: "POST", body: JSON.stringify({ ...params, userId }) }, ClickRawResponseSchema); return { success: response.success ?? true, navigated: response.navigated ?? false, refsAvailable: response.refsAvailable }; }