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.
TypeScript agentandroidandroid-automationappium-alternativeclaude-codecodexcursoremulatoriosios-automationmcpmcp-servermobilemobile-automationmobile-testingreal-devicesimulatorskills
feat: adding install and uninstall app tools (#202)
Gil Megidish7ff448f8c5f8
diff --git a/src/android.ts b/src/android.tsindex eaa6fd5..055727c 100644--- a/src/android.ts+++ b/src/android.ts@@ -299,6 +299,28 @@ export class AndroidRobot implements Robot {this.adb("shell", "am", "force-stop", packageName);}+ public async installApp(path: string): Promise<void> {+ try {+ this.adb("install", "-r", path);+ } catch (error: any) {+ const stdout = error.stdout ? error.stdout.toString() : "";+ const stderr = error.stderr ? error.stderr.toString() : "";+ const output = (stdout + stderr).trim();+ throw new ActionableError(output || error.message);+ }+ }++ public async uninstallApp(bundleId: string): Promise<void> {+ try {+ this.adb("uninstall", bundleId);+ } catch (error: any) {+ const stdout = error.stdout ? error.stdout.toString() : "";+ const stderr = error.stderr ? error.stderr.toString() : "";+ const output = (stdout + stderr).trim();+ throw new ActionableError(output || error.message);+ }+ }+public async openUrl(url: string): Promise<void> {this.adb("shell", "am", "start", "-a", "android.intent.action.VIEW", "-d", url);}diff --git a/src/ios.ts b/src/ios.tsindex ca0d10b..ccd4a8a 100644--- a/src/ios.ts+++ b/src/ios.ts@@ -147,6 +147,30 @@ export class IosRobot implements Robot {await this.ios("kill", packageName);}+ public async installApp(path: string): Promise<void> {+ await this.assertTunnelRunning();+ try {+ await this.ios("install", "--path", path);+ } catch (error: any) {+ const stdout = error.stdout ? error.stdout.toString() : "";+ const stderr = error.stderr ? error.stderr.toString() : "";+ const output = (stdout + stderr).trim();+ throw new ActionableError(output || error.message);+ }+ }++ public async uninstallApp(bundleId: string): Promise<void> {+ await this.assertTunnelRunning();+ try {+ await this.ios("uninstall", "--bundleid", bundleId);+ } catch (error: any) {+ const stdout = error.stdout ? error.stdout.toString() : "";+ const stderr = error.stderr ? error.stderr.toString() : "";+ const output = (stdout + stderr).trim();+ throw new ActionableError(output || error.message);+ }+ }+public async openUrl(url: string): Promise<void> {const wda = await this.wda();await wda.openUrl(url);diff --git a/src/iphone-simulator.ts b/src/iphone-simulator.tsindex 430f080..6b3b1b2 100644--- a/src/iphone-simulator.ts+++ b/src/iphone-simulator.ts@@ -1,4 +1,7 @@import { execFileSync } from "node:child_process";+import { mkdtempSync, readdirSync, rmSync } from "node:fs";+import { tmpdir } from "node:os";+import { join, basename, extname } from "node:path";import { trace } from "./logger";import { WebDriverAgent } from "./webdriver-agent";@@ -117,6 +120,99 @@ export class Simctl implements Robot {this.simctl("terminate", this.simulatorUuid, packageName);}+ private findAppBundle(dir: string): string | null {+ const entries = readdirSync(dir, { withFileTypes: true });++ for (const entry of entries) {+ if (entry.isDirectory() && entry.name.endsWith(".app")) {+ return join(dir, entry.name);+ }+ }++ return null;+ }++ private validateZipPaths(zipPath: string): void {+ const output = execFileSync("/usr/bin/zipinfo", ["-1", zipPath], {+ timeout: TIMEOUT,+ maxBuffer: MAX_BUFFER_SIZE,+ }).toString();++ const invalidPath = output+ .split("\n")+ .map(s => s.trim())+ .filter(s => s)+ .find(s => s.startsWith("/") || s.includes(".."));++ if (invalidPath) {+ throw new ActionableError(`Security violation: File path '${invalidPath}' contains invalid characters`);+ }+ }++ public async installApp(path: string): Promise<void> {+ let tempDir: string | null = null;+ let installPath = path;++ try {+ // zip files need to be extracted prior to installation+ if (extname(path).toLowerCase() === ".zip") {+ trace(`Detected .zip file, validating contents`);++ // before extracting, let's make sure there's no zip-slip bombs here+ this.validateZipPaths(path);++ tempDir = mkdtempSync(join(tmpdir(), "ios-app-"));++ try {+ execFileSync("unzip", ["-q", path, "-d", tempDir], {+ timeout: TIMEOUT,+ });+ } catch (error: any) {+ throw new ActionableError(`Failed to unzip file: ${error.message}`);+ }++ const appBundle = this.findAppBundle(tempDir);+ if (!appBundle) {+ throw new ActionableError("No .app bundle found in the .zip file, please visit wiki at https://github.com/mobile-next/mobile-mcp/wiki for assistance.");+ }++ installPath = appBundle;+ trace(`Found .app bundle at: ${basename(appBundle)}`);+ }++ // continue with installation+ this.simctl("install", this.simulatorUuid, installPath);++ } catch (error: any) {+ const stdout = error.stdout ? error.stdout.toString() : "";+ const stderr = error.stderr ? error.stderr.toString() : "";+ const output = (stdout + stderr).trim();+ throw new ActionableError(output || error.message);++ } finally {+ // Clean up temporary directory if it was created+ if (tempDir) {+ try {+ trace(`Cleaning up temporary directory`);+ rmSync(tempDir, { recursive: true, force: true });+ } catch (cleanupError) {+ trace(`Warning: Failed to cleanup temporary directory: ${cleanupError}`);+ }+ }+ }+ }++ public async uninstallApp(bundleId: string): Promise<void> {+ try {+ this.simctl("uninstall", this.simulatorUuid, bundleId);+ } catch (error: any) {+ const stdout = error.stdout ? error.stdout.toString() : "";+ const stderr = error.stderr ? error.stderr.toString() : "";+ const output = (stdout + stderr).trim();+ throw new ActionableError(output || error.message);+ }+ }+public async listApps(): Promise<InstalledApp[]> {const text = this.simctl("listapps", this.simulatorUuid).toString();const result = execFileSync("plutil", ["-convert", "json", "-o", "-", "-r", "-"], {diff --git a/src/robot.ts b/src/robot.tsindex a7c3446..becea03 100644--- a/src/robot.ts+++ b/src/robot.ts@@ -83,6 +83,16 @@ export interface Robot {*/terminateApp(packageName: string): Promise<void>;+ /**+ * Install an app on the device from a file path.+ */+ installApp(path: string): Promise<void>;++ /**+ * Uninstall an app from the device.+ */+ uninstallApp(bundleId: string): Promise<void>;+/*** Open a URL in the device's web browser. Can be an https:// url, or a* custom scheme (e.g. "myapp://").diff --git a/src/server.ts b/src/server.tsindex da2b1c8..a9d40a8 100644--- a/src/server.ts+++ b/src/server.ts@@ -223,6 +223,34 @@ export const createMcpServer = (): McpServer => {});+ tool(+ "mobile_install_app",+ "Install an app on mobile device",+ {+ device: z.string().describe("The device identifier to use. Use mobile_list_available_devices to find which devices are available to you."),+ path: z.string().describe("The path to the app file to install. For iOS simulators, provide a .zip file or a .app directory. For Android provide an .apk file. For iOS real devices provide an .ipa file"),+ },+ async ({ device, path }) => {+ const robot = getRobotFromDevice(device);+ await robot.installApp(path);+ return `Installed app from ${path}`;+ }+ );++ tool(+ "mobile_uninstall_app",+ "Uninstall an app from mobile device",+ {+ device: z.string().describe("The device identifier to use. Use mobile_list_available_devices to find which devices are available to you."),+ bundle_id: z.string().describe("Bundle identifier (iOS) or package name (Android) of the app to be uninstalled"),+ },+ async ({ device, bundle_id }) => {+ const robot = getRobotFromDevice(device);+ await robot.uninstallApp(bundle_id);+ return `Uninstalled app ${bundle_id}`;+ }+ );+tool("mobile_get_screen_size","Get the screen size of the mobile device in pixels",