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(android): recurse into mobilecli children when listing UI elements (#406)
Gil Megidisha5c2d8fdbbd2
diff --git a/src/mobile-device.ts b/src/mobile-device.tsindex b0babaa..d171c8a 100644--- a/src/mobile-device.ts+++ b/src/mobile-device.ts@@ -43,6 +43,7 @@ interface UIElementResponse {height: number;};focused?: boolean;+ children?: UIElementResponse[];}interface DumpUIResponse {@@ -59,6 +60,25 @@ interface OrientationResponse {};}+const flattenUIElement = (element: UIElementResponse): ScreenElement[] => {+ const screenElement: ScreenElement = {+ type: element.type,+ label: element.label,+ text: element.text,+ name: element.name,+ value: element.value,+ identifier: element.identifier,+ rect: element.rect,+ focused: element.focused,+ };++ if (!element.children) {+ return [screenElement];+ }++ return [screenElement, ...element.children.flatMap(child => flattenUIElement(child))];+};+export class MobileDevice implements Robot {private mobilecli: Mobilecli;@@ -198,16 +218,7 @@ export class MobileDevice implements Robot {public async getElementsOnScreen(): Promise<ScreenElement[]> {const response = JSON.parse(this.runCommand(["dump", "ui"])) as DumpUIResponse;- return response.data.elements.map(element => ({- type: element.type,- label: element.label,- text: element.text,- name: element.name,- value: element.value,- identifier: element.identifier,- rect: element.rect,- focused: element.focused,- }));+ return response.data.elements.flatMap(element => flattenUIElement(element));}public async setOrientation(orientation: Orientation): Promise<void> {