ui_swipe
Simulate a swipe gesture on an iOS simulator by providing start and end coordinates, with adjustable duration and step size for precise testing.
Instructions
Swipe on the screen in the iOS Simulator
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| duration | No | Swipe duration in seconds (e.g., 0.1) | |
| udid | No | Udid of target, can also be set with the IDB_UDID env var | |
| x_start | Yes | The starting x-coordinate | |
| y_start | Yes | The starting y-coordinate | |
| x_end | Yes | The ending x-coordinate | |
| y_end | Yes | The ending y-coordinate | |
| delta | No | The size of each step in the swipe (default is 1) |
Implementation Reference
- src/index.ts:446-515 (registration)Registration block for the 'ui_swipe' tool. Calls server.tool() with name, description, Zod schema, metadata, and handler.
if (!isToolFiltered("ui_swipe")) { server.tool( "ui_swipe", "Swipe on the screen in the iOS Simulator", { duration: z .string() .regex(/^\d+(\.\d+)?$/) .optional() .describe("Swipe duration in seconds (e.g., 0.1)"), udid: z .string() .regex(UDID_REGEX) .optional() .describe("Udid of target, can also be set with the IDB_UDID env var"), x_start: z.number().describe("The starting x-coordinate"), y_start: z.number().describe("The starting y-coordinate"), x_end: z.number().describe("The ending x-coordinate"), y_end: z.number().describe("The ending y-coordinate"), delta: z .number() .optional() .describe("The size of each step in the swipe (default is 1)") .default(1), }, { title: "UI Swipe", readOnlyHint: false, openWorldHint: true }, async ({ duration, udid, x_start, y_start, x_end, y_end, delta }) => { try { const actualUdid = await getBootedDeviceId(udid); const { stderr } = await idb( "ui", "swipe", "--udid", actualUdid, ...(duration ? ["--duration", duration] : []), ...(delta ? ["--delta", String(delta)] : []), "--json", // When passing user-provided values to a command, it's crucial to use `--` // to separate the command's options from positional arguments. // This prevents the shell from misinterpreting the arguments as options. "--", String(x_start), String(y_start), String(x_end), String(y_end) ); if (stderr) throw new Error(stderr); return { isError: false, content: [{ type: "text", text: "Swiped successfully" }], }; } catch (error) { return { isError: true, content: [ { type: "text", text: errorWithTroubleshooting( `Error swiping on the screen: ${toError(error).message}` ), }, ], }; } } ); } - src/index.ts:450-470 (schema)Zod schema for ui_swipe defining input params: duration (optional string regex), udid (optional UDID regex), x_start, y_start, x_end, y_end (numbers), delta (optional number default 1).
{ duration: z .string() .regex(/^\d+(\.\d+)?$/) .optional() .describe("Swipe duration in seconds (e.g., 0.1)"), udid: z .string() .regex(UDID_REGEX) .optional() .describe("Udid of target, can also be set with the IDB_UDID env var"), x_start: z.number().describe("The starting x-coordinate"), y_start: z.number().describe("The starting y-coordinate"), x_end: z.number().describe("The ending x-coordinate"), y_end: z.number().describe("The ending y-coordinate"), delta: z .number() .optional() .describe("The size of each step in the swipe (default is 1)") .default(1), }, - src/index.ts:472-513 (handler)Handler function for ui_swipe. Resolves the booted device ID, executes 'idb ui swipe' with provided coordinates and options, returns success or error with troubleshooting link.
async ({ duration, udid, x_start, y_start, x_end, y_end, delta }) => { try { const actualUdid = await getBootedDeviceId(udid); const { stderr } = await idb( "ui", "swipe", "--udid", actualUdid, ...(duration ? ["--duration", duration] : []), ...(delta ? ["--delta", String(delta)] : []), "--json", // When passing user-provided values to a command, it's crucial to use `--` // to separate the command's options from positional arguments. // This prevents the shell from misinterpreting the arguments as options. "--", String(x_start), String(y_start), String(x_end), String(y_end) ); if (stderr) throw new Error(stderr); return { isError: false, content: [{ type: "text", text: "Swiped successfully" }], }; } catch (error) { return { isError: true, content: [ { type: "text", text: errorWithTroubleshooting( `Error swiping on the screen: ${toError(error).message}` ), }, ], }; } } - src/index.ts:128-130 (helper)Helper function 'idb' that wraps the idb CLI command execution.
async function idb(...args: string[]) { return run(getIdbPath(), args); } - src/index.ts:195-208 (helper)Helper function 'getBootedDeviceId' used by ui_swipe to resolve the target device UDID.
async function getBootedDeviceId( deviceId: string | undefined ): Promise<string> { // If deviceId not provided, get the currently booted simulator let actualDeviceId = deviceId; if (!actualDeviceId) { const { id } = await getBootedDevice(); actualDeviceId = id; } if (!actualDeviceId) { throw new Error("No booted simulator found and no deviceId provided"); } return actualDeviceId; }