rotate
Change the screen orientation of a device to portrait or landscape for mobile app testing.
Instructions
Change l'orientation de l'écran du device (portrait ou landscape).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| orientation | Yes | Orientation souhaitée |
Implementation Reference
- src/index.ts:59-59 (registration)Registration of the rotate tool via registerRotate(server) on the MCP server
registerRotate(server); - src/tools/device-actions.ts:50-87 (handler)Main handler for the 'rotate' tool. Takes an 'orientation' parameter (portrait|landscape), resolves the device, uses AppleScript key codes for iOS Simulator (Cmd+Left/Right) or calls androidRotate for Android.
export function registerRotate(server: McpServer): void { server.tool( "rotate", "Change l'orientation de l'écran du device (portrait ou landscape).", { orientation: z.enum(["portrait", "landscape"]).describe("Orientation souhaitée"), }, async ({ orientation }) => { const result = await resolveDevice(); if ("error" in result) return { content: [{ type: "text", text: result.error }], isError: true }; const dev = result.device; try { if (dev.platform === "ios") { // Simulator shortcuts: Cmd+Left = rotate left, Cmd+Right = rotate right await execFileAsync("osascript", ["-e", 'tell application "Simulator" to activate', ]); await new Promise((r) => setTimeout(r, 300)); // Landscape = Cmd+Right (keycode 124), Portrait = Cmd+Left (keycode 123) const keyCode = orientation === "landscape" ? 124 : 123; await execFileAsync("osascript", ["-e", `tell application "System Events" to key code ${keyCode} using {command down}`, ]); } else { await androidRotate(orientation); } logAction("rotate", `Écran tourné en ${orientation}`, false, dev.platform, dev.id, dev.name); return { content: [{ type: "text", text: `Écran tourné en ${orientation}.` }] }; } catch (err) { const msg = err instanceof Error ? err.message : String(err); return { content: [{ type: "text", text: `Erreur rotate: ${msg}` }], isError: true }; } } ); } - src/tools/device-actions.ts:54-56 (schema)Schema definition for the rotate tool using zod: orientation is a z.enum(['portrait', 'landscape'])
{ orientation: z.enum(["portrait", "landscape"]).describe("Orientation souhaitée"), }, - src/platforms/android/adb.ts:418-424 (helper)Android helper that disables auto-rotate via adb shell settings and sets user_rotation to 0 (portrait) or 1 (landscape)
export async function androidRotate(orientation: "portrait" | "landscape"): Promise<void> { // Disable auto-rotate first await adb(["shell", "settings", "put", "system", "accelerometer_rotation", "0"]); // 0 = portrait, 1 = landscape const value = orientation === "landscape" ? "1" : "0"; await adb(["shell", "settings", "put", "system", "user_rotation", value]); }