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: mobile_take_screenshot on devices without 'cmd display get-displays' (#204)
Maxime Boulay-Cotee3e046d01854
diff --git a/src/android.ts b/src/android.tsindex 1439dd5..844f6d4 100644--- a/src/android.ts+++ b/src/android.ts@@ -214,25 +214,54 @@ export class AndroidRobot implements Robot {}private getFirstDisplayId(): string | null {- const displays = this.adb("shell", "cmd", "display", "get-displays")- .toString()- .split("\n")- .filter(s => s.startsWith("Display id "))- // filter for state ON even though get-displays only returns turned on displays- .filter(s => s.indexOf(", state ON,") >= 0)- // another paranoia check- .filter(s => s.indexOf(", uniqueId ") >= 0);-- if (displays.length > 0) {- const m = displays[0].match(/uniqueId \"([^\"]+)\"/);- if (m !== null) {- const displayId = m[1];- if (displayId.indexOf("local:") === 0) {- return displayId.split(":")[1];+ try {+ // Try using cmd display get-displays (Android 11+)+ const displays = this.adb("shell", "cmd", "display", "get-displays")+ .toString()+ .split("\n")+ .filter(s => s.startsWith("Display id "))+ // filter for state ON even though get-displays only returns turned on displays+ .filter(s => s.indexOf(", state ON,") >= 0)+ // another paranoia check+ .filter(s => s.indexOf(", uniqueId ") >= 0);++ if (displays.length > 0) {+ const m = displays[0].match(/uniqueId \"([^\"]+)\"/);+ if (m !== null) {+ const displayId = m[1];+ if (displayId.indexOf("local:") === 0) {+ return displayId.split(":")[1];+ }++ return displayId;}+ }+ } catch (error) {+ // cmd display get-displays not available on this device, try fallback+ }++ // Fallback: parse dumpsys display for display info (compatible with older Android versions)+ try {+ const dumpsys = this.adb("shell", "dumpsys", "display")+ .toString();++ // Look for DisplayViewport entries with isActive=true and type=INTERNAL+ const viewportMatch = dumpsys.match(/DisplayViewport\{type=INTERNAL[^}]*isActive=true[^}]*uniqueId='([^']+)'/);+ if (viewportMatch) {+ const uniqueId = viewportMatch[1];+ if (uniqueId.indexOf("local:") === 0) {+ return uniqueId.split(":")[1];+ }+ return uniqueId;+ }- return displayId;+ // Alternative: look for active display with state ON+ const displayStateMatch = dumpsys.match(/Display Id=(\d+)[\s\S]*?Display State=ON/);+ if (displayStateMatch) {+ return displayStateMatch[1];}+ } catch (error) {+ // dumpsys display also failed}return null;