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: start wda on ios simulator if possible
Gil Megidish47f5402e4ef9
diff --git a/src/iphone-simulator.ts b/src/iphone-simulator.tsindex 15d9e6c..41755f4 100644--- a/src/iphone-simulator.ts+++ b/src/iphone-simulator.ts@@ -1,5 +1,6 @@-import { execFileSync } from "child_process";+import { execFileSync } from "node:child_process";+import { trace } from "./logger";import { WebDriverAgent } from "./webdriver-agent";import { ActionableError, Button, InstalledApp, Robot, ScreenElement, ScreenSize, SwipeDirection, Orientation } from "./robot";@@ -40,11 +41,50 @@ export class Simctl implements Robot {constructor(private readonly simulatorUuid: string) {}+ private async isWdaInstalled(): Promise<boolean> {+ const apps = await this.listApps();+ return apps.map(app => app.packageName).includes("com.facebook.WebDriverAgentRunner.xctrunner");+ }++ private async startWda(): Promise<void> {+ if (!(await this.isWdaInstalled())) {+ // wda is not even installed, won't attempt to start it+ return;+ }++ trace("Starting WebDriverAgent");+ const webdriverPackageName = "com.facebook.WebDriverAgentRunner.xctrunner";+ this.simctl("launch", this.simulatorUuid, webdriverPackageName);++ // now we wait for wda to have a successful status+ const wda = new WebDriverAgent("localhost", WDA_PORT);++ // wait up to 10 seconds for wda to start+ const timeout = +new Date() + 10 * 1000;+ while (+new Date() < timeout) {+ // cross fingers and see if wda is already running+ if (await wda.isRunning()) {+ trace("WebDriverAgent is now running");+ return;+ }++ // wait 100ms before trying again+ await new Promise(resolve => setTimeout(resolve, 100));+ }++ trace("Could not start WebDriverAgent in time, giving up");+ }+private async wda(): Promise<WebDriverAgent> {const wda = new WebDriverAgent("localhost", WDA_PORT);if (!(await wda.isRunning())) {- throw new ActionableError("WebDriverAgent is not running on simulator, please see https://github.com/mobile-next/mobile-mcp/wiki/");+ await this.startWda();+ if (!(await wda.isRunning())) {+ throw new ActionableError("WebDriverAgent is not running on simulator, please see https://github.com/mobile-next/mobile-mcp/wiki/");+ }++ // was successfully started}return wda;