@mobilenext/mobile-mcp 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/android.js CHANGED
@@ -186,14 +186,34 @@ class AndroidRobot {
186
186
  async tap(x, y) {
187
187
  this.adb("shell", "input", "tap", `${x}`, `${y}`);
188
188
  }
189
+ async setOrientation(orientation) {
190
+ // Android uses numbers for orientation:
191
+ // 0 - Portrait
192
+ // 1 - Landscape
193
+ const orientationValue = orientation === "portrait" ? 0 : 1;
194
+ // Set orientation using content provider
195
+ this.adb("shell", "content", "insert", "--uri", "content://settings/system", "--bind", "name:s:user_rotation", "--bind", `value:i:${orientationValue}`);
196
+ // Force the orientation change
197
+ this.adb("shell", "settings", "put", "system", "accelerometer_rotation", "0");
198
+ }
199
+ async getOrientation() {
200
+ const rotation = this.adb("shell", "settings", "get", "system", "user_rotation").toString().trim();
201
+ return rotation === "0" ? "portrait" : "landscape";
202
+ }
189
203
  }
190
204
  exports.AndroidRobot = AndroidRobot;
191
205
  const getConnectedDevices = () => {
192
- return (0, child_process_1.execFileSync)(getAdbPath(), ["devices"])
193
- .toString()
194
- .split("\n")
195
- .filter(line => !line.startsWith("List of devices attached"))
196
- .filter(line => line.trim() !== "")
197
- .map(line => line.split("\t")[0]);
206
+ try {
207
+ return (0, child_process_1.execFileSync)(getAdbPath(), ["devices"])
208
+ .toString()
209
+ .split("\n")
210
+ .filter(line => !line.startsWith("List of devices attached"))
211
+ .filter(line => line.trim() !== "")
212
+ .map(line => line.split("\t")[0]);
213
+ }
214
+ catch (error) {
215
+ console.error("Could not execute adb command, maybe ANDROID_HOME is not set?");
216
+ return [];
217
+ }
198
218
  };
199
219
  exports.getConnectedDevices = getConnectedDevices;
package/lib/ios.js CHANGED
@@ -132,6 +132,14 @@ class IosRobot {
132
132
  (0, fs_1.unlinkSync)(tmpFilename);
133
133
  return buffer;
134
134
  }
135
+ async setOrientation(orientation) {
136
+ const wda = await this.wda();
137
+ await wda.setOrientation(orientation);
138
+ }
139
+ async getOrientation() {
140
+ const wda = await this.wda();
141
+ return await wda.getOrientation();
142
+ }
135
143
  }
136
144
  exports.IosRobot = IosRobot;
137
145
  class IosManager {
@@ -100,6 +100,14 @@ class Simctl {
100
100
  const wda = await this.wda();
101
101
  return wda.getElementsOnScreen();
102
102
  }
103
+ async setOrientation(orientation) {
104
+ const wda = await this.wda();
105
+ return wda.setOrientation(orientation);
106
+ }
107
+ async getOrientation() {
108
+ const wda = await this.wda();
109
+ return wda.getOrientation();
110
+ }
103
111
  }
104
112
  exports.Simctl = Simctl;
105
113
  class SimctlManager {
package/lib/server.js CHANGED
@@ -124,7 +124,7 @@ const createMcpServer = () => {
124
124
  const x = Number((element.rect.x + element.rect.width / 2)).toFixed(3);
125
125
  const y = Number((element.rect.y + element.rect.height / 2)).toFixed(3);
126
126
  return {
127
- text: element.label,
127
+ text: element.label || element.name,
128
128
  coordinates: { x, y }
129
129
  };
130
130
  });
@@ -193,6 +193,18 @@ const createMcpServer = () => {
193
193
  };
194
194
  }
195
195
  });
196
+ tool("mobile_set_orientation", "Change the screen orientation of the device", {
197
+ orientation: zod_1.z.enum(["portrait", "landscape"]).describe("The desired orientation"),
198
+ }, async ({ orientation }) => {
199
+ requireRobot();
200
+ await robot.setOrientation(orientation);
201
+ return `Changed device orientation to ${orientation}`;
202
+ });
203
+ tool("mobile_get_orientation", "Get the current screen orientation of the device", {}, async () => {
204
+ requireRobot();
205
+ const orientation = await robot.getOrientation();
206
+ return `Current device orientation is ${orientation}`;
207
+ });
196
208
  return server;
197
209
  };
198
210
  exports.createMcpServer = createMcpServer;
@@ -207,5 +207,25 @@ class WebDriverAgent {
207
207
  });
208
208
  });
209
209
  }
210
+ async setOrientation(orientation) {
211
+ await this.withinSession(async (sessionUrl) => {
212
+ const url = `${sessionUrl}/orientation`;
213
+ await fetch(url, {
214
+ method: "POST",
215
+ headers: { "Content-Type": "application/json" },
216
+ body: JSON.stringify({
217
+ orientation: orientation.toUpperCase()
218
+ })
219
+ });
220
+ });
221
+ }
222
+ async getOrientation() {
223
+ return this.withinSession(async (sessionUrl) => {
224
+ const url = `${sessionUrl}/orientation`;
225
+ const response = await fetch(url);
226
+ const json = await response.json();
227
+ return json.value.toLowerCase();
228
+ });
229
+ }
210
230
  }
211
231
  exports.WebDriverAgent = WebDriverAgent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mobilenext/mobile-mcp",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Mobile MCP",
5
5
  "repository": {
6
6
  "type": "git",