MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / execute

Method execute

src/tools/computer/use.ts:160–188  ·  view source on GitHub ↗
(args: z.infer<typeof ClickArgs>, _ctx: ToolContext)

Source from the content-addressed store, hash-verified

158 argsSchema = ClickArgs;
159
160 async execute(args: z.infer<typeof ClickArgs>, _ctx: ToolContext): Promise<ToolResult> {
161 if (!isMacos()) return macosOnly(this.name);
162 try {
163 const cliclickPath = await which('cliclick');
164 const count = args.count ?? 1;
165 const button = args.button ?? 'left';
166 if (cliclickPath) {
167 // cliclick syntax: c:x,y for single left, dc:x,y for double, rc:x,y for right
168 let cmd: string;
169 if (button === 'right') cmd = `rc:${args.x},${args.y}`;
170 else if (count === 2) cmd = `dc:${args.x},${args.y}`;
171 else if (count === 3) cmd = `tc:${args.x},${args.y}`;
172 else cmd = `c:${args.x},${args.y}`;
173 await runCmd(cliclickPath, [cmd], { timeoutMs: 5000 });
174 return { content: `Clicked at (${args.x}, ${args.y}) via cliclick — ${button} button × ${count}` };
175 }
176 // Fallback: AppleScript. Slower (~500ms latency) but no install needed.
177 // Note: AppleScript click via System Events requires Accessibility permission.
178 const script = button === 'right'
179 ? `tell application "System Events" to do shell script "echo right-click via applescript not directly supported; install cliclick for right-click"`
180 : `tell application "System Events" to click at {${args.x}, ${args.y}}`;
181 await runCmd('osascript', ['-e', script], { timeoutMs: 5000 });
182 return {
183 content: `Clicked at (${args.x}, ${args.y}) via AppleScript — ${button} button${count > 1 ? `\n⚠ Note: AppleScript click doesn't support multi-click reliably. Install cliclick: brew install cliclick` : ''}`,
184 };
185 } catch (e: any) {
186 return { content: `[COMPUTER_USE_ERROR] click failed: ${e?.message ?? e}`, isError: true };
187 }
188 }
189}
190
191// ─────────────────────────────────────────────────────────────────────────────

Callers

nothing calls this directly

Calls 4

isMacosFunction · 0.85
macosOnlyFunction · 0.85
runCmdFunction · 0.85
whichFunction · 0.70

Tested by

no test coverage detected