moveMouse
Move the mouse cursor to specific coordinates on screen for browser automation tasks like web scraping, testing, and interaction.
Instructions
Move mouse to coordinates
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"x": "<x>",
"y": "<y>"
},
"name": "moveMouse"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x | Yes | ||
| y | Yes |
Implementation Reference
- src/controllers/playwright.ts:151-164 (handler)Core handler function that performs the actual mouse movement using Playwright's page.mouse.move method. Updates current mouse position and includes error handling.
async moveMouse(x: number, y: number): Promise<void> { try { if (!this.isInitialized()) { throw new Error('Browser not initialized'); } this.log('Moving mouse to', { x, y }); await this.state.page?.mouse.move(x, y); this.currentMousePosition = { x, y }; this.log('Mouse move complete'); } catch (error: any) { console.error('Mouse move error:', error); throw new BrowserError('Failed to move mouse', 'Check if coordinates are within viewport'); } } - src/server.ts:625-636 (handler)MCP tool call handler in the server's request handler. Validates inputs and delegates to the Playwright controller's moveMouse method.
case 'moveMouse': { if (typeof args.x !== 'number' || typeof args.y !== 'number') { return { content: [{ type: "text", text: "X and Y coordinates are required" }], isError: true }; } await playwrightController.moveMouse(args.x, args.y); return { content: [{ type: "text", text: "Mouse moved successfully" }] }; } - src/server.ts:56-67 (schema)Defines the tool schema including name, description, and input validation schema for x and y coordinates.
const MOVE_MOUSE_TOOL: Tool = { name: "moveMouse", description: "Move mouse to coordinates", inputSchema: { type: "object", properties: { x: { type: "number" }, y: { type: "number" } }, required: ["x", "y"] } }; - src/server.ts:514-553 (registration)Registers the moveMouse tool (as MOVE_MOUSE_TOOL) in the tools dictionary passed to MCP server capabilities.
const tools = { openBrowser: OPEN_BROWSER_TOOL, navigate: NAVIGATE_TOOL, type: TYPE_TOOL, click: CLICK_TOOL, moveMouse: MOVE_MOUSE_TOOL, scroll: SCROLL_TOOL, screenshot: SCREENSHOT_TOOL, getPageSource: GET_PAGE_SOURCE_TOOL, getPageText: GET_PAGE_TEXT_TOOL, getPageTitle: GET_PAGE_TITLE_TOOL, getPageUrl: GET_PAGE_URL_TOOL, getScripts: GET_SCRIPTS_TOOL, getStylesheets: GET_STYLESHEETS_TOOL, getMetaTags: GET_META_TAGS_TOOL, getLinks: GET_LINKS_TOOL, getImages: GET_IMAGES_TOOL, getForms: GET_FORMS_TOOL, getElementContent: GET_ELEMENT_CONTENT_TOOL, getElementHierarchy: GET_ELEMENT_HIERARCHY_TOOL, executeJavaScript: EXECUTE_JAVASCRIPT_TOOL, goForward: GO_FORWARD_TOOL, hover: HOVER_TOOL, dragAndDrop: DRAG_AND_DROP_TOOL, selectOption: SELECT_OPTION_TOOL, pressKey: PRESS_KEY_TOOL, waitForText: WAIT_FOR_TEXT_TOOL, waitForSelector: WAIT_FOR_SELECTOR_TOOL, resize: RESIZE_TOOL, handleDialog: HANDLE_DIALOG_TOOL, getConsoleMessages: GET_CONSOLE_MESSAGES_TOOL, getNetworkRequests: GET_NETWORK_REQUESTS_TOOL, uploadFiles: UPLOAD_FILES_TOOL, evaluateWithReturn: EVALUATE_WITH_RETURN_TOOL, takeScreenshot: TAKE_SCREENSHOT_TOOL, mouseMove: MOUSE_MOVE_TOOL, mouseClick: MOUSE_CLICK_TOOL, mouseDrag: MOUSE_DRAG_TOOL, closeBrowser: CLOSE_BROWSER_TOOL };