Skip to content

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.

fix: parse android raw ui hierarchy and default list format to text (#549)

Gil Megidish57efc27d9697
diff --git a/src/mobile-device.ts b/src/mobile-device.ts
index a58f543..885224c 100644
--- a/src/mobile-device.ts
+++ b/src/mobile-device.ts
@@ -323,6 +323,11 @@ export class MobileDevice implements Robot {
throw new ActionableError("No raw UI hierarchy was returned for this device. Its screen may be off or locked, or the installed mobilecli version may not support raw UI dumps");
}
+ // mobilecli returns android rawData as a json string, ios as an object
+ if (typeof rawData === "string") {
+ return JSON.parse(rawData);
+ }
+
return rawData;
}
diff --git a/src/server.ts b/src/server.ts
index 6e047c0..72b76d8 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -803,10 +803,10 @@ export const createMcpServer = (): McpServer => {
"List elements on screen with their ref, coordinates, and display text or accessibility label. Use the ref with mobile_click_on_screen_at_coordinates, mobile_double_tap_on_screen or mobile_long_press_on_screen_at_coordinates. Refs and coordinates stay valid as long as the screen does not change; re-list only after navigation or a layout change.",
{
device: z.string().describe("The device identifier to use. Use mobile_list_available_devices to find which devices are available to you."),
- format: z.enum(["text", "json", "raw"]).optional().describe("Output format. \"text\" (default) is one compact line per element, \"json\" is a json array, \"raw\" is the unfiltered platform-specific hierarchy as JSON (mobilecli only). Raw nodes may be offscreen and do not have element refs"),
+ format: z.enum(["text", "json", "raw"]).default("text").describe("Output format. \"text\" (default) is one compact line per element, \"json\" is a json array, \"raw\" is the unfiltered platform-specific hierarchy as JSON (mobilecli only). Raw nodes may be offscreen and do not have element refs"),
},
{ readOnlyHint: true, openWorldHint: true },
- async ({ device, format = "text" }) => {
+ async ({ device, format }) => {
const robot = getRobotFromDevice(device);
if (format === "raw") {
if (!robot.getRawUIHierarchy) {