@mobilenext/mobile-mcp 0.0.62 → 1.0.1

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/README.md CHANGED
@@ -467,6 +467,7 @@ Gmail to contacts "team@example.com".
467
467
  | `MOBILEMCP_AUTH` | Require a Bearer token on the SSE server — every request must then send `Authorization: Bearer <token>`. | `MOBILEMCP_AUTH=my-secret-token` |
468
468
  | `MOBILEMCP_DISABLE_TELEMETRY` | Disable anonymous usage telemetry. | `MOBILEMCP_DISABLE_TELEMETRY=1` |
469
469
  | `MOBILEMCP_ALLOW_UNSAFE_URLS` | Allow `mobile_open_url` to open non-standard URL schemes (blocked by default). | `MOBILEMCP_ALLOW_UNSAFE_URLS=1` |
470
+ | `MOBILEMCP_LEGACY_ROBOT` | Use the legacy platform-specific robots for Android devices and physical iOS devices. iOS simulators continue to use `mobilecli`. | `MOBILEMCP_LEGACY_ROBOT=1` |
470
471
 
471
472
  ### Simulators, Emulators, and Real Devices
472
473
 
package/lib/mobilecli.js CHANGED
@@ -6,6 +6,7 @@ const node_path_1 = require("node:path");
6
6
  const node_child_process_1 = require("node:child_process");
7
7
  const TIMEOUT = 30000;
8
8
  const MAX_BUFFER_SIZE = 1024 * 1024 * 8;
9
+ const DEFAULT_ALLOCATE_TIMEOUT_SECONDS = 900; // matches mobilecli's own "remote allocate --wait" default
9
10
  class Mobilecli {
10
11
  path = null;
11
12
  constructor() { }
@@ -15,9 +16,13 @@ class Mobilecli {
15
16
  }
16
17
  return this.path;
17
18
  }
18
- executeCommand(args) {
19
+ executeCommand(args, timeoutMs) {
19
20
  const path = this.getPath();
20
- return (0, node_child_process_1.execFileSync)(path, args, { encoding: "utf8" }).toString().trim();
21
+ const options = { encoding: "utf8" };
22
+ if (timeoutMs !== undefined) {
23
+ options.timeout = timeoutMs;
24
+ }
25
+ return (0, node_child_process_1.execFileSync)(path, args, options).toString().trim();
21
26
  }
22
27
  spawnCommand(args) {
23
28
  const binaryPath = this.getPath();
@@ -77,11 +82,37 @@ class Mobilecli {
77
82
  return "failed " + error.message;
78
83
  }
79
84
  }
85
+ spawnRemoteLogin() {
86
+ const binaryPath = this.getPath();
87
+ return (0, node_child_process_1.spawn)(binaryPath, ["auth", "login", "--provider", "mobilenext"], {
88
+ stdio: ["ignore", "pipe", "pipe"],
89
+ });
90
+ }
80
91
  remoteListDevices() {
81
92
  return this.executeCommand(["remote", "list-devices"]);
82
93
  }
83
- remoteAllocate(platform) {
84
- return this.executeCommand(["remote", "allocate", "--platform", platform]);
94
+ remoteAllocate(options) {
95
+ const args = ["remote", "allocate", "--platform", options.platform];
96
+ if (options.name) {
97
+ args.push("--name", options.name);
98
+ }
99
+ for (const version of options.version ?? []) {
100
+ args.push("--version", version);
101
+ }
102
+ if (options.type) {
103
+ args.push("--type", options.type);
104
+ }
105
+ if (options.wait) {
106
+ args.push("--wait");
107
+ }
108
+ if (options.timeoutSeconds !== undefined) {
109
+ args.push("--timeout", String(options.timeoutSeconds));
110
+ }
111
+ // only "--wait" makes this call block for as long as mobilecli's own allocation timeout
112
+ const execTimeoutMs = options.wait
113
+ ? (options.timeoutSeconds ?? DEFAULT_ALLOCATE_TIMEOUT_SECONDS) * 1000 + 5000
114
+ : undefined;
115
+ return this.executeCommand(args, execTimeoutMs);
85
116
  }
86
117
  remoteRelease(deviceId) {
87
118
  return this.executeCommand(["remote", "release", "--device", deviceId]);
package/lib/server.js CHANGED
@@ -21,6 +21,7 @@ const mobile_device_1 = require("./mobile-device");
21
21
  const utils_1 = require("./utils");
22
22
  const ALLOWED_SCREENSHOT_EXTENSIONS = [".png", ".jpg", ".jpeg"];
23
23
  const ALLOWED_RECORDING_EXTENSIONS = [".mp4"];
24
+ const LOGIN_PROMPT_TIMEOUT_MS = 15000;
24
25
  const getAgentVersion = () => {
25
26
  const json = require("../package.json");
26
27
  return json.version;
@@ -93,6 +94,7 @@ const createMcpServer = () => {
93
94
  Version: (0, exports.getAgentVersion)(),
94
95
  NodeVersion: process.version,
95
96
  CI: process.env.CI || "0",
97
+ RobotMode: process.env.MOBILEMCP_LEGACY_ROBOT === "1" ? "legacy" : "mobilecli",
96
98
  };
97
99
  const clientName = getClientName();
98
100
  if (clientName !== "unknown") {
@@ -121,6 +123,7 @@ const createMcpServer = () => {
121
123
  const mobilecli = new mobilecli_1.Mobilecli();
122
124
  const activeRecordings = new Map();
123
125
  const agentVerifiedSimulators = new Set();
126
+ const activeLoginProcesses = [];
124
127
  posthog("launch", {}).then();
125
128
  const ensureMobilecliAvailable = () => {
126
129
  try {
@@ -136,132 +139,218 @@ const createMcpServer = () => {
136
139
  const getRobotFromDevice = (deviceId) => {
137
140
  // from now on, we must have mobilecli working
138
141
  ensureMobilecliAvailable();
139
- // Check if it's an iOS device
140
- const iosManager = new ios_1.IosManager();
141
- const iosDevices = iosManager.listDevices();
142
- const iosDevice = iosDevices.find(d => d.deviceId === deviceId);
143
- if (iosDevice) {
144
- posthog("get_robot", { "DevicePlatform": "ios", "DeviceType": "real" }).then();
145
- return new ios_1.IosRobot(deviceId);
146
- }
147
- // Check if it's an Android device
148
- const androidManager = new android_1.AndroidDeviceManager();
149
- const androidDevices = androidManager.getConnectedDevices();
150
- const androidDevice = androidDevices.find(d => d.deviceId === deviceId);
151
- if (androidDevice) {
152
- posthog("get_robot", { "DevicePlatform": "android" }).then();
153
- return new android_1.AndroidRobot(deviceId);
142
+ const legacyRobot = process.env.MOBILEMCP_LEGACY_ROBOT === "1";
143
+ if (legacyRobot) {
144
+ // Check if it's an iOS device
145
+ const iosManager = new ios_1.IosManager();
146
+ const iosDevices = iosManager.listDevices();
147
+ const iosDevice = iosDevices.find(d => d.deviceId === deviceId);
148
+ if (iosDevice) {
149
+ posthog("get_robot", { "DevicePlatform": "ios", "DeviceType": "real" }).then();
150
+ return new ios_1.IosRobot(deviceId);
151
+ }
152
+ // Check if it's an Android device
153
+ const androidManager = new android_1.AndroidDeviceManager();
154
+ const androidDevices = androidManager.getConnectedDevices();
155
+ const androidDevice = androidDevices.find(d => d.deviceId === deviceId);
156
+ if (androidDevice) {
157
+ posthog("get_robot", { "DevicePlatform": "android", "DeviceType": androidDevice.deviceType }).then();
158
+ return new android_1.AndroidRobot(deviceId);
159
+ }
154
160
  }
155
- // Check if it's a simulator (will later replace all other device types as well)
156
- const response = mobilecli.getDevices({
161
+ const response = mobilecli.getDevices(legacyRobot ? {
157
162
  platform: "ios",
158
163
  type: "simulator",
159
164
  includeOffline: false,
165
+ } : {
166
+ includeOffline: false,
160
167
  });
161
168
  if (response.status === "ok" && response.data && response.data.devices) {
162
169
  for (const device of response.data.devices) {
163
170
  if (device.id === deviceId) {
164
- if (!agentVerifiedSimulators.has(deviceId)) {
171
+ if (device.platform === "ios" && device.type === "simulator" && !agentVerifiedSimulators.has(deviceId)) {
165
172
  const agentStatus = mobilecli.agentStatus(deviceId);
166
173
  if (agentStatus.status === "fail") {
167
174
  mobilecli.agentInstall(deviceId);
168
175
  }
169
176
  agentVerifiedSimulators.add(deviceId);
170
177
  }
171
- posthog("get_robot", { "DevicePlatform": "ios", "DeviceType": "simulator" }).then();
178
+ posthog("get_robot", { "DevicePlatform": device.platform, "DeviceType": device.type }).then();
172
179
  return new mobile_device_1.MobileDevice(deviceId);
173
180
  }
174
181
  }
175
182
  }
176
183
  throw new robot_1.ActionableError(`Device "${deviceId}" not found. Use the mobile_list_available_devices tool to see available devices.`);
177
184
  };
178
- tool("mobile_list_available_devices", "List Devices", "List all available devices. This includes both physical mobile devices and mobile simulators and emulators. It returns both Android and iOS devices.", {}, { readOnlyHint: true }, async ({}, telemetry) => {
185
+ tool("mobile_list_available_devices", "List Devices", "List all available devices. This includes both physical mobile devices and mobile simulators and emulators. It returns both Android and iOS devices. " +
186
+ "These are local devices already connected to this machine, ready to use immediately at no cost - for devices from the shared remote cloud fleet, use mobile_list_remote_devices instead.", {}, { readOnlyHint: true }, async ({}, telemetry) => {
179
187
  // from today onward, we must have mobilecli working
180
188
  ensureMobilecliAvailable();
181
- const iosManager = new ios_1.IosManager();
182
- const androidManager = new android_1.AndroidDeviceManager();
183
189
  const devices = [];
184
- // Get Android devices with details
185
- const androidDevices = androidManager.getConnectedDevicesWithDetails();
186
- telemetry.AndroidCount = androidDevices.length;
187
- for (const device of androidDevices) {
188
- devices.push({
189
- id: device.deviceId,
190
- name: device.name,
191
- platform: "android",
192
- type: "emulator",
193
- version: device.version,
194
- state: "online",
195
- });
196
- }
197
- // Get iOS physical devices with details
198
- telemetry.IosRealCount = 0;
199
- try {
200
- const iosDevices = iosManager.listDevicesWithDetails();
201
- telemetry.IosRealCount = iosDevices.length;
202
- for (const device of iosDevices) {
190
+ const legacyRobot = process.env.MOBILEMCP_LEGACY_ROBOT === "1";
191
+ if (legacyRobot) {
192
+ const iosManager = new ios_1.IosManager();
193
+ const androidManager = new android_1.AndroidDeviceManager();
194
+ // Get Android devices with details
195
+ const androidDevices = androidManager.getConnectedDevicesWithDetails();
196
+ telemetry.AndroidCount = androidDevices.length;
197
+ for (const device of androidDevices) {
203
198
  devices.push({
204
199
  id: device.deviceId,
205
- name: device.deviceName,
206
- platform: "ios",
207
- type: "real",
200
+ name: device.name,
201
+ platform: "android",
202
+ type: "emulator",
208
203
  version: device.version,
209
204
  state: "online",
210
205
  });
211
206
  }
207
+ // Get iOS physical devices with details
208
+ telemetry.IosRealCount = 0;
209
+ try {
210
+ const iosDevices = iosManager.listDevicesWithDetails();
211
+ telemetry.IosRealCount = iosDevices.length;
212
+ for (const device of iosDevices) {
213
+ devices.push({
214
+ id: device.deviceId,
215
+ name: device.deviceName,
216
+ platform: "ios",
217
+ type: "real",
218
+ version: device.version,
219
+ state: "online",
220
+ });
221
+ }
222
+ }
223
+ catch (error) {
224
+ // If go-ios is not available, silently skip
225
+ }
226
+ // Get iOS simulators from mobilecli, including offline ones so we can
227
+ // report how many are installed vs booted. only booted ones are returned.
228
+ const response = mobilecli.getDevices({
229
+ platform: "ios",
230
+ type: "simulator",
231
+ includeOffline: true,
232
+ });
233
+ telemetry.IosSimInstalledCount = 0;
234
+ telemetry.IosSimCount = 0;
235
+ if (response.status === "ok" && response.data && response.data.devices) {
236
+ const simulators = response.data.devices;
237
+ const booted = simulators.filter(device => device.state === "online");
238
+ telemetry.IosSimInstalledCount = simulators.length;
239
+ telemetry.IosSimCount = booted.length;
240
+ devices.push(...booted);
241
+ }
212
242
  }
213
- catch (error) {
214
- // If go-ios is not available, silently skip
215
- }
216
- // Get iOS simulators from mobilecli, including offline ones so we can
217
- // report how many are installed vs booted. only booted ones are returned.
218
- const response = mobilecli.getDevices({
219
- platform: "ios",
220
- type: "simulator",
221
- includeOffline: true,
222
- });
223
- telemetry.IosSimInstalledCount = 0;
224
- telemetry.IosSimCount = 0;
225
- if (response.status === "ok" && response.data && response.data.devices) {
226
- const simulators = response.data.devices;
227
- const booted = simulators.filter(device => device.state === "online");
228
- telemetry.IosSimInstalledCount = simulators.length;
229
- telemetry.IosSimCount = booted.length;
230
- for (const device of booted) {
231
- devices.push({
232
- id: device.id,
233
- name: device.name,
234
- platform: device.platform,
235
- type: device.type,
236
- version: device.version,
237
- state: "online",
238
- });
243
+ else {
244
+ const response = mobilecli.getDevices({ includeOffline: true });
245
+ telemetry.AndroidCount = 0;
246
+ telemetry.IosRealCount = 0;
247
+ telemetry.IosSimInstalledCount = 0;
248
+ telemetry.IosSimCount = 0;
249
+ if (response.status === "ok" && response.data && response.data.devices) {
250
+ const availableDevices = response.data.devices.filter(device => device.state === "online");
251
+ telemetry.AndroidCount = availableDevices.filter(device => device.platform === "android").length;
252
+ telemetry.IosRealCount = availableDevices.filter(device => device.platform === "ios" && device.type === "real").length;
253
+ telemetry.IosSimInstalledCount = response.data.devices.filter(device => device.platform === "ios" && device.type === "simulator").length;
254
+ telemetry.IosSimCount = availableDevices.filter(device => device.platform === "ios" && device.type === "simulator").length;
255
+ devices.push(...availableDevices);
239
256
  }
240
257
  }
241
258
  const out = { devices };
242
259
  return JSON.stringify(out);
243
260
  });
244
- if (process.env.MOBILEFLEET_ENABLE === "1") {
245
- tool("mobile_list_remote_devices", "List Remote Devices", "List devices available in the remote fleet", {}, { readOnlyHint: true }, async ({}) => {
246
- ensureMobilecliAvailable();
247
- const result = mobilecli.remoteListDevices();
248
- return result;
249
- });
250
- tool("mobile_allocate_remote_device", "Allocate Remote Device", "Reserve a device from the remote fleet", {
251
- platform: zod_1.z.enum(["ios", "android"]).describe("The platform to allocate a device for"),
252
- }, { destructiveHint: true }, async ({ platform }) => {
253
- ensureMobilecliAvailable();
254
- const result = mobilecli.remoteAllocate(platform);
255
- return result;
256
- });
257
- tool("mobile_release_remote_device", "Release Remote Device", "Release a device back to the remote fleet", {
258
- device: zod_1.z.string().describe("The device identifier to release back to the remote fleet"),
259
- }, { destructiveHint: true }, async ({ device }) => {
260
- ensureMobilecliAvailable();
261
- const result = mobilecli.remoteRelease(device);
262
- return result;
261
+ tool("mobile_login_to_cloud_provider", "Login to Cloud Provider", "Start authenticating this machine with the remote device cloud provider. This is required once before mobile_list_remote_devices or mobile_allocate_remote_device will work; if either of those fails with an authentication error, call this tool and then retry. " +
262
+ "This starts a browser-based device-code login and returns quickly with a URL and a one-time code - it does NOT wait for the login to complete. Show the URL and code to the user verbatim and ask them to open the URL and enter the code in their own browser. " +
263
+ "The login keeps running in the background after this tool returns; once the user confirms they've completed it, retry the remote devices tool that originally failed. " +
264
+ "Only call this after the user has explicitly asked to connect to, log into, or use remote/cloud devices - never call it speculatively, since it interrupts the user to act in their browser.", {}, {}, async ({}) => {
265
+ ensureMobilecliAvailable();
266
+ const child = mobilecli.spawnRemoteLogin();
267
+ activeLoginProcesses.push(child);
268
+ const forget = () => {
269
+ const index = activeLoginProcesses.indexOf(child);
270
+ if (index !== -1) {
271
+ activeLoginProcesses.splice(index, 1);
272
+ }
273
+ };
274
+ return new Promise((resolve, reject) => {
275
+ let output = "";
276
+ let settled = false;
277
+ const promptTimeout = setTimeout(() => {
278
+ if (!settled) {
279
+ settled = true;
280
+ forget();
281
+ child.kill();
282
+ reject(new robot_1.ActionableError(`Timed out waiting for the login prompt from mobilecli. Output so far: ${output.trim() || "(none)"}`));
283
+ }
284
+ }, LOGIN_PROMPT_TIMEOUT_MS);
285
+ child.stdout?.on("data", (chunk) => {
286
+ output += chunk.toString();
287
+ if (!settled && output.includes("Waiting for authorization")) {
288
+ settled = true;
289
+ clearTimeout(promptTimeout);
290
+ const urlMatch = output.match(/(https?:\/\/\S+)/);
291
+ const codeMatch = output.match(/enter the code:\s*(\S+)/i);
292
+ if (urlMatch && codeMatch) {
293
+ resolve(`Authentication to mobilenext.ai started, please open ${urlMatch[1]} and enter the code: ${codeMatch[1]}`);
294
+ }
295
+ else {
296
+ resolve(`Authentication started, please check the output: ${output.trim()}`);
297
+ }
298
+ }
299
+ });
300
+ child.stderr?.on("data", (chunk) => {
301
+ output += chunk.toString();
302
+ });
303
+ child.on("error", (err) => {
304
+ forget();
305
+ if (!settled) {
306
+ settled = true;
307
+ clearTimeout(promptTimeout);
308
+ reject(new robot_1.ActionableError(`Failed to start login: ${err.message}`));
309
+ }
310
+ });
311
+ child.on("exit", (code) => {
312
+ forget();
313
+ if (!settled) {
314
+ settled = true;
315
+ clearTimeout(promptTimeout);
316
+ reject(new robot_1.ActionableError(`mobilecli auth login exited early (code ${code}). Output: ${output.trim() || "(none)"}`));
317
+ }
318
+ });
263
319
  });
264
- }
320
+ });
321
+ tool("mobile_list_remote_devices", "List Remote Devices", "List the catalog of device models (make, platform, OS version) available to reserve from the remote cloud device fleet. " +
322
+ "This is different from mobile_list_available_devices, which lists real devices and simulators/emulators already connected to this local machine and ready to use immediately at no cost. " +
323
+ "Remote devices live in a shared cloud fleet: they are not usable until reserved with mobile_allocate_remote_device, and reserving one may be a limited/billed resource. " +
324
+ "Requires mobile_login_to_cloud_provider to have been called first; if this fails with an authentication error, call that tool then retry.", {}, { readOnlyHint: true }, async ({}) => {
325
+ ensureMobilecliAvailable();
326
+ const result = mobilecli.remoteListDevices();
327
+ return result;
328
+ });
329
+ tool("mobile_allocate_remote_device", "Allocate Remote Device", "Reserve a physical device from the remote cloud fleet for exclusive use, returning a device identifier usable with the other mobile_* tools. " +
330
+ "Unlike local devices, a remote device is a shared and billed resource borrowed for the session - only call this after the user has explicitly asked to use a remote/cloud device, never speculatively or as a fallback when a local device isn't found. " +
331
+ "Requires mobile_login_to_cloud_provider to have been called first; if this fails with an authentication error, call that tool then retry. " +
332
+ "Use mobile_list_remote_devices first to see which names and versions actually exist in the fleet before filtering by them. " +
333
+ "Release the device with mobile_release_remote_device once the whole task is finished - releasing wipes the device's state, so do not release and reallocate between steps of the same task just to be tidy.", {
334
+ platform: zod_1.z.enum(["ios", "android"]).describe("The platform to allocate a device for"),
335
+ name: zod_1.z.string().optional().describe("Filter by device name/model. Supports a trailing * for prefix match (e.g. \"iPhone*\"), or an exact name (e.g. \"iPhone 16\")."),
336
+ version: zod_1.z.array(zod_1.z.string()).optional().describe("Filter by OS version. Supports comparison prefixes >=, >, <=, < (e.g. \">=18\"), or an exact version (e.g. \"18.6.2\"). Multiple values are ANDed together."),
337
+ type: zod_1.z.enum(["real"]).optional().describe("Device type filter. Currently only \"real\" (physical devices) is supported by the fleet."),
338
+ wait: zod_1.z.boolean().optional().describe("If true, block until the device has finished allocating and is ready to use, up to timeoutSeconds. If false/omitted, this returns as soon as the reservation is made, but the device may not be immediately ready."),
339
+ timeoutSeconds: zod_1.z.coerce.number().int().positive().optional().describe("Seconds to wait for allocation when wait is true. Defaults to 900 (15 minutes). Only relevant when wait is true."),
340
+ }, { destructiveHint: true }, async ({ platform, name, version, type, wait, timeoutSeconds }) => {
341
+ ensureMobilecliAvailable();
342
+ const result = mobilecli.remoteAllocate({ platform, name, version, type, wait, timeoutSeconds });
343
+ return result;
344
+ });
345
+ tool("mobile_release_remote_device", "Release Remote Device", "Release a device previously reserved with mobile_allocate_remote_device back to the remote cloud fleet so it becomes available to others. " +
346
+ "Releasing is destructive to the device's state: apps installed, files pushed, and any other changes made during this session are lost, and a later mobile_allocate_remote_device call may take time and could return a different physical unit. " +
347
+ "Only release once the whole task is finished - if there is more work to do on the same device shortly, keep holding it rather than releasing and reallocating.", {
348
+ device: zod_1.z.string().describe("The device identifier to release back to the remote fleet"),
349
+ }, { destructiveHint: true }, async ({ device }) => {
350
+ ensureMobilecliAvailable();
351
+ const result = mobilecli.remoteRelease(device);
352
+ return result;
353
+ });
265
354
  tool("mobile_list_apps", "List Apps", "List all the installed apps on the device", {
266
355
  device: zod_1.z.string().describe("The device identifier to use. Use mobile_list_available_devices to find which devices are available to you.")
267
356
  }, { readOnlyHint: true }, async ({ device }) => {
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.62",
4
+ "version": "1.0.1",
5
5
  "description": "Mobile MCP",
6
6
  "repository": {
7
7
  "type": "git",
@@ -29,7 +29,7 @@
29
29
  "commander": "14.0.0",
30
30
  "express": "5.1.0",
31
31
  "fast-xml-parser": "5.8.0",
32
- "mobilewright": "0.0.48",
32
+ "mobilewright": "0.0.52",
33
33
  "qs": "^6.15.0",
34
34
  "zod": "^4.1.13",
35
35
  "zod-to-json-schema": "3.25.0"