Skip to content

Mobile MCP: let AI agents drive your iOS and Android apps. MCP server for simulators, emulators and real devices. Works with Claude Code, Codex, Cursor and any MCP client.

feat: silently introducing mobilecli as a one-binary for adb, go-ios and toolkits (#196)

Gil Megidishfe38e81654e3
diff --git a/package-lock.json b/package-lock.json
index e03c148..e742710 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -41,6 +41,9 @@
},
"engines": {
"node": ">=18"
+ },
+ "optionalDependencies": {
+ "@mobilenext/mobilecli": "0.0.27"
}
},
"node_modules/@babel/code-frame": {
@@ -712,6 +715,16 @@
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
+ "node_modules/@mobilenext/mobilecli": {
+ "version": "0.0.27",
+ "resolved": "https://registry.npmjs.org/@mobilenext/mobilecli/-/mobilecli-0.0.27.tgz",
+ "integrity": "sha512-RzYubvC9ikZl3UcfB2kVfKzHpItnFcfiwJzcp08IpLXtm7+rGe1/DYmIR0ddQRpEdyGMS1SWe+8QAksZZiZzKg==",
+ "license": "MIT",
+ "optional": true,
+ "bin": {
+ "mobilecli": "index.js"
+ }
+ },
"node_modules/@modelcontextprotocol/sdk": {
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.13.2.tgz",
diff --git a/package.json b/package.json
index 29becea..5b029ee 100644
--- a/package.json
+++ b/package.json
@@ -30,6 +30,9 @@
"fast-xml-parser": "5.2.5",
"zod-to-json-schema": "3.24.6"
},
+ "optionalDependencies": {
+ "@mobilenext/mobilecli": "0.0.27"
+ },
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.19.0",
diff --git a/src/mobilecli.ts b/src/mobilecli.ts
new file mode 100644
index 0000000..804f66d
--- /dev/null
+++ b/src/mobilecli.ts
@@ -0,0 +1,57 @@
+import { existsSync } from "node:fs";
+import { dirname, join, sep } from "node:path";
+
+export const getMobilecliPath = (): string => {
+ if (process.env.MOBILECLI_PATH) {
+ return process.env.MOBILECLI_PATH;
+ }
+
+ const platform = process.platform;
+ let binaryName = "mobilecli";
+
+ switch (platform) {
+ case "darwin":
+ binaryName += "-darwin";
+ break;
+ case "linux":
+ const arch = process.arch;
+ if (arch === "arm64") {
+ binaryName += "-linux-arm64";
+ } else {
+ binaryName += "-linux-amd64";
+ }
+ break;
+ case "win32":
+ binaryName += "-windows-amd64.exe";
+ break;
+ default:
+ throw new Error(`Unsupported platform: ${platform}`);
+ }
+
+ // Check if mobile-mcp is installed as a package
+ const currentPath = __filename;
+ const pathParts = currentPath.split(sep);
+ const lastNodeModulesIndex = pathParts.lastIndexOf("node_modules");
+
+ if (lastNodeModulesIndex !== -1) {
+ // We're inside node_modules, go to the last node_modules in the path
+ const nodeModulesParts = pathParts.slice(0, lastNodeModulesIndex + 1);
+ const lastNodeModulesPath = nodeModulesParts.join(sep);
+ const mobilecliPath = join(lastNodeModulesPath, "@mobilenext", "mobilecli", "bin", binaryName);
+
+ if (existsSync(mobilecliPath)) {
+ return mobilecliPath;
+ }
+ }
+
+ // Not in node_modules, look one directory up from current script
+ const scriptDir = dirname(__filename);
+ const parentDir = dirname(scriptDir);
+ const mobilecliPath = join(parentDir, "node_modules", "@mobilenext", "mobilecli", "bin", binaryName);
+
+ if (existsSync(mobilecliPath)) {
+ return mobilecliPath;
+ }
+
+ throw new Error(`Could not find mobilecli binary for platform: ${platform}`);
+};
diff --git a/src/server.ts b/src/server.ts
index 94351ac..da2b1c8 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -4,6 +4,7 @@ import { z, ZodRawShape, ZodTypeAny } from "zod";
import fs from "node:fs";
import os from "node:os";
import crypto from "node:crypto";
+import { execFileSync } from "node:child_process";
import { error, trace } from "./logger";
import { AndroidRobot, AndroidDeviceManager } from "./android";
@@ -12,30 +13,13 @@ import { SimctlManager } from "./iphone-simulator";
import { IosManager, IosRobot } from "./ios";
import { PNG } from "./png";
import { isScalingAvailable, Image } from "./image-utils";
+import { getMobilecliPath } from "./mobilecli";
export const getAgentVersion = (): string => {
const json = require("../package.json");
return json.version;
};
-const getLatestAgentVersion = async (): Promise<string> => {
- const response = await fetch("https://api.github.com/repos/mobile-next/mobile-mcp/tags?per_page=1");
- const json = await response.json();
- return json[0].name;
-};
-
-const checkForLatestAgentVersion = async (): Promise<void> => {
- try {
- const latestVersion = await getLatestAgentVersion();
- const currentVersion = getAgentVersion();
- if (latestVersion !== currentVersion) {
- trace(`You are running an older version of the agent. Please update to the latest version: ${latestVersion}.`);
- }
- } catch (error: any) {
- // ignore
- }
-};
-
export const createMcpServer = (): McpServer => {
const server = new McpServer({
@@ -112,7 +96,22 @@ export const createMcpServer = (): McpServer => {
}
};
- posthog("launch", {}).then();
+ const getMobilecliVersion = (): string => {
+ try {
+ const path = getMobilecliPath();
+ const output = execFileSync(path, ["--version"], { encoding: "utf8" }).toString().trim();
+ if (output.startsWith("mobilecli version ")) {
+ return output.substring("mobilecli version ".length);
+ }
+
+ return "failed";
+ } catch (error: any) {
+ return "failed " + error.message;
+ }
+ };
+
+ const mobilecliVersion = getMobilecliVersion();
+ posthog("launch", { "MobilecliVersion": mobilecliVersion }).then();
const simulatorManager = new SimctlManager();
@@ -472,8 +471,5 @@ export const createMcpServer = (): McpServer => {
}
);
- // async check for latest agent version
- checkForLatestAgentVersion().then();
-
return server;
};