Skip to main content
Glama

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
NameRequiredDescriptionDefault
xYesX coordinate
yYesY coordinate
buttonNoleft
actionNoMouse action to performclick
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • 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))); } } );
  • 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, });
  • 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))); } }

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/andytango/puppeteer-mcp'

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