@mobilenext/mobile-mcp 0.0.33 → 0.0.34
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 +25 -4
- package/lib/mobilecli.js +7 -2
- package/lib/server.js +35 -0
- package/package.json +2 -2
package/lib/android.js
CHANGED
|
@@ -46,10 +46,19 @@ const getAdbPath = () => {
|
|
|
46
46
|
if (process.env.ANDROID_HOME) {
|
|
47
47
|
return node_path_1.default.join(process.env.ANDROID_HOME, "platform-tools", "adb");
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (process.platform === "win32" && process.env.LOCALAPPDATA) {
|
|
50
|
+
const windowsAdbPath = node_path_1.default.join(process.env.LOCALAPPDATA, "Android", "Sdk", "platform-tools", "adb.exe");
|
|
51
|
+
if ((0, node_fs_1.existsSync)(windowsAdbPath)) {
|
|
52
|
+
return windowsAdbPath;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (process.env.HOME) {
|
|
56
|
+
const defaultAndroidSdk = node_path_1.default.join(process.env.HOME, "Library", "Android", "sdk", "platform-tools", "adb");
|
|
57
|
+
if ((0, node_fs_1.existsSync)(defaultAndroidSdk)) {
|
|
58
|
+
return defaultAndroidSdk;
|
|
59
|
+
}
|
|
52
60
|
}
|
|
61
|
+
// fallthrough, hope for the best
|
|
53
62
|
return "adb";
|
|
54
63
|
};
|
|
55
64
|
const BUTTON_MAP = {
|
|
@@ -77,6 +86,13 @@ class AndroidRobot {
|
|
|
77
86
|
timeout: TIMEOUT,
|
|
78
87
|
});
|
|
79
88
|
}
|
|
89
|
+
silentAdb(...args) {
|
|
90
|
+
return (0, node_child_process_1.execFileSync)(getAdbPath(), ["-s", this.deviceId, ...args], {
|
|
91
|
+
maxBuffer: MAX_BUFFER_SIZE,
|
|
92
|
+
timeout: TIMEOUT,
|
|
93
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
94
|
+
});
|
|
95
|
+
}
|
|
80
96
|
getSystemFeatures() {
|
|
81
97
|
return this.adb("shell", "pm", "list", "features")
|
|
82
98
|
.toString()
|
|
@@ -120,7 +136,12 @@ class AndroidRobot {
|
|
|
120
136
|
.map(line => line.substring("package:".length));
|
|
121
137
|
}
|
|
122
138
|
async launchApp(packageName) {
|
|
123
|
-
|
|
139
|
+
try {
|
|
140
|
+
this.silentAdb("shell", "monkey", "-p", packageName, "-c", "android.intent.category.LAUNCHER", "1");
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
throw new robot_1.ActionableError(`Failed launching app with package name "${packageName}", please make sure it exists`);
|
|
144
|
+
}
|
|
124
145
|
}
|
|
125
146
|
async listRunningProcesses() {
|
|
126
147
|
return this.adb("shell", "ps", "-e")
|
package/lib/mobilecli.js
CHANGED
|
@@ -7,14 +7,19 @@ const getMobilecliPath = () => {
|
|
|
7
7
|
if (process.env.MOBILECLI_PATH) {
|
|
8
8
|
return process.env.MOBILECLI_PATH;
|
|
9
9
|
}
|
|
10
|
+
const arch = process.arch;
|
|
10
11
|
const platform = process.platform;
|
|
11
12
|
let binaryName = "mobilecli";
|
|
12
13
|
switch (platform) {
|
|
13
14
|
case "darwin":
|
|
14
|
-
|
|
15
|
+
if (arch === "arm64") {
|
|
16
|
+
binaryName += "-darwin-arm64";
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
binaryName += "-darwin-amd64";
|
|
20
|
+
}
|
|
15
21
|
break;
|
|
16
22
|
case "linux":
|
|
17
|
-
const arch = process.arch;
|
|
18
23
|
if (arch === "arm64") {
|
|
19
24
|
binaryName += "-linux-arm64";
|
|
20
25
|
}
|
package/lib/server.js
CHANGED
|
@@ -56,6 +56,7 @@ const createMcpServer = () => {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
catch (error) {
|
|
59
|
+
posthog("tool_failed", { "ToolName": name }).then();
|
|
59
60
|
if (error instanceof robot_1.ActionableError) {
|
|
60
61
|
return {
|
|
61
62
|
content: [{ type: "text", text: `${error.message}. Please fix the issue and try again.` }],
|
|
@@ -122,6 +123,11 @@ const createMcpServer = () => {
|
|
|
122
123
|
return "failed " + error.message;
|
|
123
124
|
}
|
|
124
125
|
};
|
|
126
|
+
const getMobilecliDevices = () => {
|
|
127
|
+
const mobilecliPath = (0, mobilecli_1.getMobilecliPath)();
|
|
128
|
+
const mobilecliOutput = (0, node_child_process_1.execFileSync)(mobilecliPath, ["devices"], { encoding: "utf8" }).toString().trim();
|
|
129
|
+
return JSON.parse(mobilecliOutput);
|
|
130
|
+
};
|
|
125
131
|
const mobilecliVersion = getMobilecliVersion();
|
|
126
132
|
posthog("launch", { "MobilecliVersion": mobilecliVersion }).then();
|
|
127
133
|
const simulatorManager = new iphone_simulator_1.SimctlManager();
|
|
@@ -160,6 +166,35 @@ const createMcpServer = () => {
|
|
|
160
166
|
const iosDeviceNames = iosDevices.map(d => d.deviceId);
|
|
161
167
|
const androidTvDevices = androidDevices.filter(d => d.deviceType === "tv").map(d => d.deviceId);
|
|
162
168
|
const androidMobileDevices = androidDevices.filter(d => d.deviceType === "mobile").map(d => d.deviceId);
|
|
169
|
+
if (true) {
|
|
170
|
+
// gilm: this is new code to verify first that mobilecli detects more or equal number of devices.
|
|
171
|
+
// in an attempt to make the smoothest transition from go-ios+xcrun+adb+iproxy+sips+imagemagick+wda to
|
|
172
|
+
// a single cli tool.
|
|
173
|
+
const deviceCount = simulators.length + iosDevices.length + androidDevices.length;
|
|
174
|
+
let mobilecliDeviceCount = 0;
|
|
175
|
+
try {
|
|
176
|
+
const response = getMobilecliDevices();
|
|
177
|
+
if (response.status === "ok" && response.data && response.data.devices) {
|
|
178
|
+
mobilecliDeviceCount = response.data.devices.length;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
// if mobilecli fails, we'll just set count to 0
|
|
183
|
+
}
|
|
184
|
+
if (deviceCount === mobilecliDeviceCount) {
|
|
185
|
+
posthog("debug_mobilecli_same_number_of_devices", {
|
|
186
|
+
"DeviceCount": deviceCount,
|
|
187
|
+
"MobilecliDeviceCount": mobilecliDeviceCount,
|
|
188
|
+
}).then();
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
posthog("debug_mobilecli_different_number_of_devices", {
|
|
192
|
+
"DeviceCount": deviceCount,
|
|
193
|
+
"MobilecliDeviceCount": mobilecliDeviceCount,
|
|
194
|
+
"DeviceCountDifference": deviceCount - mobilecliDeviceCount,
|
|
195
|
+
}).then();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
163
198
|
const resp = ["Found these devices:"];
|
|
164
199
|
if (simulatorNames.length > 0) {
|
|
165
200
|
resp.push(`iOS simulators: [${simulatorNames.join(",")}]`);
|
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": "0.0.
|
|
4
|
+
"version": "0.0.34",
|
|
5
5
|
"description": "Mobile MCP",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"zod-to-json-schema": "3.24.6"
|
|
32
32
|
},
|
|
33
33
|
"optionalDependencies": {
|
|
34
|
-
"@mobilenext/mobilecli": "0.0.
|
|
34
|
+
"@mobilenext/mobilecli": "0.0.33"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@eslint/eslintrc": "^3.2.0",
|