mouse_click
Clicks a mouse button. Optionally moves the pointer to specified x,y coordinates before clicking.
Instructions
Click a mouse button. If x and y are provided, the pointer moves there first; otherwise clicks at the current pointer location.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| button | No | Default: left. | |
| x | No | ||
| y | No |
Implementation Reference
- server.js:232-245 (handler)The main handler function for the mouse_click tool. It validates the xdotool binary, resolves the button code (left/middle/right), optionally moves the mouse to (x,y) coordinates, then executes the click via xdotool.
async function mouseClick(args) { const missing = requireBin('xdotool'); if (missing) return errorResult(missing); const button = buttonCode(args.button || 'left'); if (!button) return errorResult(`unknown button "${args.button}" (expected left|middle|right)`); const cmd = []; if (typeof args.x === 'number' && typeof args.y === 'number') { cmd.push('mousemove', String(args.x), String(args.y)); } cmd.push('click', button); const r = await run(BIN.xdotool, cmd); if (r.code !== 0) return errorResult(`mouse_click failed: ${r.stderr || r.stdout}`); return textResult({ button: args.button || 'left', x: args.x ?? null, y: args.y ?? null }); } - server.js:449-461 (schema)Schema/registration definition for the mouse_click tool. Defines the tool name, description, and inputSchema with optional button (left/middle/right), x, and y fields.
{ name: 'mouse_click', description: 'Click a mouse button. If x and y are provided, the pointer moves there first; otherwise clicks at the current pointer location.', annotations: { title: 'Click mouse', destructiveHint: true }, inputSchema: { type: 'object', properties: { button: { type: 'string', enum: ['left', 'middle', 'right'], description: 'Default: left.' }, x: { type: 'number' }, y: { type: 'number' }, }, }, }, - server.js:560-560 (registration)Registration of the mouse_click handler in the HANDLERS map, mapping the tool name 'mouse_click' to the mouseClick function.
mouse_click: mouseClick, - server.js:98-103 (helper)Helper function that maps human-readable button names ('left', 'middle', 'right') to xdotool numeric button codes ('1', '2', '3'). Used by mouse_click and other mouse tools.
function buttonCode(name, isScroll = false) { if (isScroll) { return { up: '4', down: '5', left: '6', right: '7' }[name] || null; } return { left: '1', middle: '2', right: '3' }[name] || null; }