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: get bundle display name of apps from physical iOS and simulators
gmegidish4884ff9e2898
diff --git a/src/android.ts b/src/android.tsindex 28beedf..48c008b 100644--- a/src/android.ts+++ b/src/android.ts@@ -3,7 +3,7 @@ import { execFileSync } from "child_process";import * as xml from "fast-xml-parser";-import { Bounds, Button, Dimensions, ElementCoordinates, Robot, SwipeDirection } from "./robot";+import { Bounds, Button, Dimensions, ElementCoordinates, InstalledApp, Robot, SwipeDirection } from "./robot";interface UiAutomatorXmlNode {node: UiAutomatorXmlNode[];@@ -64,16 +64,18 @@ export class AndroidRobot implements Robot {return { width, height };}- public async listApps(): Promise<string[]> {- const result = this.adb("shell", "cmd", "package", "query-activities", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER")+ public async listApps(): Promise<InstalledApp[]> {+ return this.adb("shell", "cmd", "package", "query-activities", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER").toString().split("\n").map(line => line.trim()).filter(line => line.startsWith("packageName=")).map(line => line.substring("packageName=".length))- .filter((value, index, self) => self.indexOf(value) === index);-- return result;+ .filter((value, index, self) => self.indexOf(value) === index)+ .map(packageName => ({+ packageName,+ appName: packageName,+ }));}public async launchApp(packageName: string): Promise<void> {diff --git a/src/ios.ts b/src/ios.tsindex 648933f..a04cbd6 100644--- a/src/ios.ts+++ b/src/ios.ts@@ -3,9 +3,13 @@ import { join } from "path";import { randomBytes } from "crypto";import { readFileSync, unlinkSync } from "fs";import { execFileSync } from "child_process";+import { Socket } from "net";import { WebDriverAgent } from "./webdriver-agent";-import { Button, Dimensions, Robot, SwipeDirection } from "./robot";+import { Button, Dimensions, InstalledApp, Robot, SwipeDirection } from "./robot";++const WDA_PORT = 8100;+const IOS_TUNNEL_PORT = 60105;interface ListCommandOutput {deviceList: string[];@@ -17,10 +21,42 @@ const getGoIosPath = (): string => {export class IosRobot implements Robot {- private readonly wda: WebDriverAgent;-public constructor(private deviceId: string) {- this.wda = new WebDriverAgent("localhost", 8100);+ }++ private isListeningOnPort(port: number): Promise<boolean> {+ return new Promise((resolve, reject) => {+ const client = new Socket();+ client.connect(port, "localhost", () => {+ client.destroy();+ resolve(true);+ });++ client.on("error", (err: any) => {+ resolve(false);+ });+ });+ }++ private async isTunnelRunning(): Promise<boolean> {+ return await this.isListeningOnPort(IOS_TUNNEL_PORT);+ }++ private async isWdaForwardRunning(): Promise<boolean> {+ return await this.isListeningOnPort(WDA_PORT);+ }++ private async wda(): Promise<WebDriverAgent> {+ if (!(await this.isTunnelRunning())) {+ throw new Error("iOS tunnel is not running, please see https://github.com/mobile-next/mobile-mcp/wiki/Getting-Started-with-iOS");+ }++ if (!(await this.isWdaForwardRunning())) {+ throw new Error("Port forwarding to WebDriverAgent is not running, please see https://github.com/mobile-next/mobile-mcp/wiki/Getting-Started-with-iOS");+ }++ const wda = new WebDriverAgent("localhost", WDA_PORT);+ return wda;}private async ios(...args: string[]): Promise<string> {@@ -28,18 +64,26 @@ export class IosRobot implements Robot {}public async getScreenSize(): Promise<Dimensions> {- return await this.wda.getScreenSize();+ const wda = await this.wda();+ return await wda.getScreenSize();}public async swipe(direction: SwipeDirection): Promise<void> {- await this.wda.swipe(direction);+ const wda = await this.wda();+ await wda.swipe(direction);}- public async listApps(): Promise<string[]> {+ public async listApps(): Promise<InstalledApp[]> {const output = await this.ios("apps", "--all", "--list");return output.split("\n")- .map(line => line.split(" ")[0]);+ .map(line => {+ const [packageName, appName] = line.split(" ");+ return {+ packageName,+ appName,+ };+ });}public async launchApp(packageName: string): Promise<void> {@@ -51,23 +95,28 @@ export class IosRobot implements Robot {}public async openUrl(url: string): Promise<void> {- await this.wda.openUrl(url);+ const wda = await this.wda();+ await wda.openUrl(url);}public async sendKeys(text: string): Promise<void> {- await this.wda.sendKeys(text);+ const wda = await this.wda();+ await wda.sendKeys(text);}public async pressButton(button: Button): Promise<void> {- await this.wda.pressButton(button);+ const wda = await this.wda();+ await wda.pressButton(button);}public async tap(x: number, y: number): Promise<void> {- await this.wda.tap(x, y);+ const wda = await this.wda();+ await wda.tap(x, y);}public async getElementsOnScreen(): Promise<any[]> {- return await this.wda.getElementsOnScreen();+ const wda = await this.wda();+ return await wda.getElementsOnScreen();}public async getScreenshot(): Promise<Buffer> {diff --git a/src/iphone-simulator.ts b/src/iphone-simulator.tsindex b43f195..7f6fa9f 100644--- a/src/iphone-simulator.ts+++ b/src/iphone-simulator.ts@@ -1,7 +1,7 @@import { execFileSync, execSync } from "child_process";import { WebDriverAgent } from "./webdriver-agent";-import { Button, Dimensions, Robot, SwipeDirection } from "./robot";+import { Button, Dimensions, InstalledApp, Robot, SwipeDirection } from "./robot";export interface Simulator {name: string;@@ -101,10 +101,13 @@ export class Simctl implements Robot {return result;}- public async listApps(): Promise<string[]> {+ public async listApps(): Promise<InstalledApp[]> {const text = this.simctl("listapps", this.simulatorUuid).toString();const apps = this.parseIOSAppData(text);- return apps.map(app => app.CFBundleIdentifier);+ return apps.map(app => ({+ packageName: app.CFBundleIdentifier,+ appName: app.CFBundleDisplayName,+ }));}public async getScreenSize(): Promise<Dimensions> {diff --git a/src/robot.ts b/src/robot.tsindex 1301ba1..76f3528 100644--- a/src/robot.ts+++ b/src/robot.ts@@ -15,6 +15,11 @@ export interface Dimensions {height: number;}+export interface InstalledApp {+ packageName: string;+ appName: string;+}+export type SwipeDirection = "up" | "down" | "left" | "right";export type Button = "HOME" | "BACK" | "VOLUME_UP" | "VOLUME_DOWN" | "ENTER";@@ -40,7 +45,7 @@ export interface Robot {* List all installed apps on the device. Returns an array of package names (or* bundle identifiers in iOS) for all installed apps.*/- listApps(): Promise<string[]>;+ listApps(): Promise<InstalledApp[]>;/*** Launch an app.diff --git a/test/android.ts b/test/android.tsindex a94f54b..8a38446 100644--- a/test/android.ts+++ b/test/android.ts@@ -37,7 +37,8 @@ hasOneAndroidDevice && describe("android", () => {it("should be able to list apps", async () => {const apps = await android.listApps();- assert.ok(apps.includes("com.android.settings"));+ const packages = apps.map(app => app.packageName);+ assert.ok(packages.includes("com.android.settings"));});it("should be able to open a url", async () => {diff --git a/test/iphone-simulator.ts b/test/iphone-simulator.tsindex 7f6c00d..1544127 100644--- a/test/iphone-simulator.ts+++ b/test/iphone-simulator.ts@@ -42,9 +42,10 @@ describe("ios", () => {it("should be able to list apps", async () => {const apps = await simctl.listApps();- assert.ok(apps.includes("com.apple.mobilesafari"));- assert.ok(apps.includes("com.apple.reminders"));- assert.ok(apps.includes("com.apple.Preferences"));+ const packages = apps.map(app => app.packageName);+ assert.ok(packages.includes("com.apple.mobilesafari"));+ assert.ok(packages.includes("com.apple.reminders"));+ assert.ok(packages.includes("com.apple.Preferences"));});it("should be able to get elements on screen", async () => {