mouse
Control mouse actions at specific coordinates in a browser, including moving, clicking, and pressing buttons, to automate web interactions through the Puppeteer MCP Server.
Instructions
Perform mouse actions at specific coordinates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x | Yes | X coordinate | |
| y | Yes | Y coordinate | |
| button | No | left | |
| action | No | Mouse action to perform | click |
| tabId | No | Tab ID to operate on (uses active tab if not specified) |
Implementation Reference
- src/tools/input.ts:58-101 (registration)Registers the 'mouse' tool on the MCP server, including the input schema reference, description, and the full handler function that uses Puppeteer to perform mouse move, click, down, or up actions at specified coordinates.server.tool( 'mouse', 'Perform mouse actions at specific coordinates', mouseSchema.shape, async ({ x, y, button, action, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; const mouseButton = (button ?? 'left') as MouseButton; const mouseAction = (action ?? 'click') as MouseAction; try { switch (mouseAction) { case 'move': await page.mouse.move(x, y); break; case 'click': await page.mouse.click(x, y, { button: mouseButton }); break; case 'down': await page.mouse.move(x, y); await page.mouse.down({ button: mouseButton }); break; case 'up': await page.mouse.move(x, y); await page.mouse.up({ button: mouseButton }); break; } return handleResult(ok({ action: mouseAction, x, y, button: mouseButton, })); } catch (error) { return handleResult(err(normalizeError(error))); } } );
- src/schemas.ts:94-100 (schema)Zod schema defining the input parameters for the mouse tool: coordinates (x,y), optional button and action, and tabId.export const mouseSchema = z.object({ x: z.number().describe('X coordinate'), y: z.number().describe('Y coordinate'), button: z.enum(['left', 'right', 'middle']).optional().default('left'), action: z.enum(['move', 'click', 'down', 'up']).optional().default('click').describe('Mouse action to perform'), tabId: tabIdSchema, });
- src/tools/input.ts:62-99 (handler)The core handler logic for the mouse tool, which gets the page for the tab, determines button and action, and dispatches to Puppeteer's mouse API based on the action type.async ({ x, y, button, action, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; const mouseButton = (button ?? 'left') as MouseButton; const mouseAction = (action ?? 'click') as MouseAction; try { switch (mouseAction) { case 'move': await page.mouse.move(x, y); break; case 'click': await page.mouse.click(x, y, { button: mouseButton }); break; case 'down': await page.mouse.move(x, y); await page.mouse.down({ button: mouseButton }); break; case 'up': await page.mouse.move(x, y); await page.mouse.up({ button: mouseButton }); break; } return handleResult(ok({ action: mouseAction, x, y, button: mouseButton, })); } catch (error) { return handleResult(err(normalizeError(error))); } }