@mobilenext/mobile-mcp 1.0.1 → 1.0.2

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.
@@ -2,6 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MobileDevice = void 0;
4
4
  const mobilecli_1 = require("./mobilecli");
5
+ const flattenUIElement = (element) => {
6
+ const screenElement = {
7
+ type: element.type,
8
+ label: element.label,
9
+ text: element.text,
10
+ name: element.name,
11
+ value: element.value,
12
+ identifier: element.identifier,
13
+ rect: element.rect,
14
+ focused: element.focused,
15
+ };
16
+ if (!element.children) {
17
+ return [screenElement];
18
+ }
19
+ return [screenElement, ...element.children.flatMap(child => flattenUIElement(child))];
20
+ };
5
21
  class MobileDevice {
6
22
  deviceId;
7
23
  mobilecli;
@@ -67,7 +83,7 @@ class MobileDevice {
67
83
  endX = x + swipeDistance;
68
84
  break;
69
85
  }
70
- this.runCommand(["io", "swipe", `${x},${y},${endX},${endY}`]);
86
+ this.runCommand(["io", "swipe", `${Math.round(x)},${Math.round(y)},${Math.round(endX)},${Math.round(endY)}`]);
71
87
  }
72
88
  async getScreenshot() {
73
89
  const fullArgs = ["screenshot", "--device", this.deviceId, "--format", "png", "--output", "-"];
@@ -106,7 +122,8 @@ class MobileDevice {
106
122
  this.runCommand(["io", "button", button]);
107
123
  }
108
124
  async tap(x, y) {
109
- this.runCommand(["io", "tap", `${x},${y}`]);
125
+ // mobilecli rejects fractional coordinates ("x and y must be integers")
126
+ this.runCommand(["io", "tap", `${Math.round(x)},${Math.round(y)}`]);
110
127
  }
111
128
  async doubleTap(x, y) {
112
129
  // TODO: should move into mobilecli itself as "io doubletap"
@@ -114,20 +131,11 @@ class MobileDevice {
114
131
  await this.tap(x, y);
115
132
  }
116
133
  async longPress(x, y, duration) {
117
- this.runCommand(["io", "longpress", `${x},${y}`, "--duration", `${duration}`]);
134
+ this.runCommand(["io", "longpress", `${Math.round(x)},${Math.round(y)}`, "--duration", `${duration}`]);
118
135
  }
119
136
  async getElementsOnScreen() {
120
137
  const response = JSON.parse(this.runCommand(["dump", "ui"]));
121
- return response.data.elements.map(element => ({
122
- type: element.type,
123
- label: element.label,
124
- text: element.text,
125
- name: element.name,
126
- value: element.value,
127
- identifier: element.identifier,
128
- rect: element.rect,
129
- focused: element.focused,
130
- }));
138
+ return response.data.elements.flatMap(element => flattenUIElement(element));
131
139
  }
132
140
  async setOrientation(orientation) {
133
141
  this.runCommand(["device", "orientation", "set", orientation]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mobilenext/mobile-mcp",
3
3
  "mcpName": "io.github.mobile-next/mobile-mcp",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "description": "Mobile MCP",
6
6
  "repository": {
7
7
  "type": "git",