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
fix(ios): auto-install agent on simulator when mobilecli exits non-zero (#498)
Gil Megidish4d14ee004b0d
diff --git a/src/mobilecli.ts b/src/mobilecli.tsindex 047a25a..077b397 100644--- a/src/mobilecli.ts+++ b/src/mobilecli.ts@@ -224,8 +224,17 @@ export class Mobilecli {}agentStatus(deviceId: string): MobilecliAgentStatusResponse {- const output = this.executeCommand(["agent", "status", "--device", deviceId]);- return JSON.parse(output) as MobilecliAgentStatusResponse;+ try {+ const output = this.executeCommand(["agent", "status", "--device", deviceId]);+ return JSON.parse(output) as MobilecliAgentStatusResponse;+ } catch (error: any) {+ // mobilecli exits 1 when the agent is missing, but still prints the json status+ if (!error.stdout) {+ throw error;+ }++ return JSON.parse(error.stdout.toString()) as MobilecliAgentStatusResponse;+ }}agentInstall(deviceId: string): void {diff --git a/test/mobilecli.test.ts b/test/mobilecli.test.tsindex 453c22f..b867fe9 100644--- a/test/mobilecli.test.ts+++ b/test/mobilecli.test.ts@@ -116,4 +116,18 @@ test.describe("mobilecli", () => {expect(calls[0].args).toEqual(["devices", "--include-offline", "--platform", "android", "--type", "emulator"]);});});++ test.describe("agentStatus", () => {+ test("should return fail status when agent is not installed and mobilecli exits non-zero", () => {+ const mobilecli = new Mobilecli();+ const notInstalledResponse = JSON.stringify({ status: "fail", data: { message: "Agent is not installed on the device" } });+ mobilecli.executeCommand = function(): string {+ throw Object.assign(new Error("Command failed"), { status: 1, stdout: notInstalledResponse });+ };++ const status = mobilecli.agentStatus("SIM-ID");++ expect(status.status).toBe("fail");+ });+ });});