8000 feat: change posture for folding and unfolding by ruijie89 · Pull Request #1 · ruijie89/mobile-mcp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: change posture for folding and unfolding #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { execFileSync } from "child_process";

import * as xml from "fast-xml-parser";

import { ActionableError, Button, InstalledApp, Robot, ScreenElement, ScreenElementRect, ScreenSize, SwipeDirection, Orientation } from "./robot";
import { ActionableError, Button, InstalledApp, Robot, ScreenElement, ScreenElementRect, ScreenSize, SwipeDirection, Orientation, PostureStates } from "./robot";

export interface AndroidDevice {
deviceId: string;
Expand Down Expand Up @@ -318,6 +318,19 @@ export class AndroidRobot implements Robot {
return rotation === "0" ? "portrait" : "landscape";
}

public async changeDevicePosture(posture: PostureStates): Promise<void> {
switch (posture) {
case "fold": {
this.adb("emu", "fold");
break;
}
case "unfold": {
this.adb("emu", "unfold");
break;
}
}
}

private async getUiAutomatorDump(): Promise<string> {
for (let tries = 0; tries < 10; tries++) {
const dump = this.adb("exec-out", "uiautomator", "dump", "/dev/tty").toString();
Expand Down
6 changes: 5 additions & 1 deletion src/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { execFileSync } from "child_process";
import { Socket } from "net";

import { WebDriverAgent } from "./webdriver-agent";
import { ActionableError, Button, InstalledApp, Robot, ScreenSize, SwipeDirection, ScreenElement, Orientation } from "./robot";
import { ActionableError, Button, InstalledApp, Robot, ScreenSize, SwipeDirection, ScreenElement, Orientation, PostureStates } from "./robot";

const WDA_PORT = 8100;
const IOS_TUNNEL_PORT = 60105;
Expand Down Expand Up @@ -195,6 +195,10 @@ export class IosRobot implements Robot {
const wda = await this.wda();
return await wda.getOrientation();
}

public async changeDevicePosture(posture: PostureStates): Promise<void> {
throw new ActionableError("Posture changing is not supported for iOS");
}
}

export class IosManager {
Expand Down
6 changes: 5 additions & 1 deletion src/iphone-simulator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execFileSync } from "child_process";

import { WebDriverAgent } from "./webdriver-agent";
import { ActionableError, Button, InstalledApp, Robot, ScreenElement, ScreenSize, SwipeDirection, Orientation } from "./robot";
import { ActionableError, Button, InstalledApp, Robot, ScreenElement, ScreenSize, SwipeDirection, Orientation, PostureStates } from "./robot";

export interface Simulator {
name: string;
Expand Down Expand Up @@ -134,6 +134,10 @@ export class Simctl implements Robot {
const wda = await this.wda();
return wda.getOrientation();
}

public async changeDevicePosture(posture: PostureStates): Promise<void> {
throw new ActionableError("Posture changing is not supported for iOS");
}
}

export class SimctlManager {
Expand Down
7 changes: 7 additions & 0 deletions src/robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class ActionableError extends Error {

export type Orientation = "portrait" | "landscape";

export type PostureStates = "fold" | "unfold";

export interface Robot {
/**
* Get the screen size of the device in pixels.
Expand Down Expand Up @@ -120,4 +122,9 @@ export interface Robot {
* Get the current screen orientation.
*/
getOrientation(): Promise<Orientation>;

/**
* Fold or unfold a device. Possible actions: (fold, unfold)
*/
changeDevicePosture(posture: PostureStates): Promise<void>;
}
13 changes: 13 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,19 @@ export const createMcpServer = (): McpServer => {
}
);

tool(
"mobile_change_posture",
"Fold or unfold the device.",
{
posture: z.enum(["fold", "unfold"]).describe("The desired posture")
},
async ({ posture }) => {
requireRobot();
await robot!.changeDevicePosture(posture);
return `Changed device posture to ${posture}`;
}
);

// async check for latest agent version
checkForLatestAgentVersion().then();

Expand Down
0