mouse_drag
Drag mouse cursor from point (x1, y1) to (x2, y2) while holding a specified button (left, middle, or right).
Instructions
Drag from (x1, y1) to (x2, y2) while holding the given button (default left).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x1 | Yes | ||
| y1 | Yes | ||
| x2 | Yes | ||
| y2 | Yes | ||
| button | No | Default: left. |
Implementation Reference
- server.js:248-264 (handler)The main handler function for the mouse_drag tool. Validates inputs, then uses xdotool to mousemove to (x1,y1), mousedown, mousemove to (x2,y2), and mouseup to perform a drag operation.
async function mouseDrag(args) { const missing = requireBin('xdotool'); if (missing) return errorResult(missing); const button = buttonCode(args.button || 'left'); if (!button) return errorResult(`unknown button "${args.button}"`); for (const k of ['x1', 'y1', 'x2', 'y2']) { if (typeof args[k] !== 'number') return errorResult(`${k} is required (number)`); } const r = await run(BIN.xdotool, [ 'mousemove', String(args.x1), String(args.y1), 'mousedown', button, 'mousemove', String(args.x2), String(args.y2), 'mouseup', button, ]); if (r.code !== 0) return errorResult(`mouse_drag failed: ${r.stderr || r.stdout}`); return textResult({ from: { x: args.x1, y: args.y1 }, to: { x: args.x2, y: args.y2 }, button: args.button || 'left' }); } - server.js:462-475 (schema)The tool schema/registration entry defining the name, description, annotations, and inputSchema for the mouse_drag tool in the TOOLS array.
{ name: 'mouse_drag', description: 'Drag from (x1, y1) to (x2, y2) while holding the given button (default left).', annotations: { title: 'Drag mouse', destructiveHint: true }, inputSchema: { type: 'object', properties: { x1: { type: 'number' }, y1: { type: 'number' }, x2: { type: 'number' }, y2: { type: 'number' }, button: { type: 'string', enum: ['left', 'middle', 'right'], description: 'Default: left.' }, }, required: ['x1', 'y1', 'x2', 'y2'], }, }, - server.js:561-561 (registration)The mapping of the tool name 'mouse_drag' to its handler function 'mouseDrag' in the HANDLERS dispatch object.
mouse_drag: mouseDrag, - server.js:98-103 (helper)Helper function that maps button names ('left','middle','right') to xdotool button codes ('1','2','3'), used by mouse_drag to determine the button argument.
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; }