INNER CODE UNIT · Python
require_device
CursorTouch/Android-MCP · src/android_mcp/__main__.py:211
def require_device():
_connect_preferred_device()
return mobile.get_device()
def _resolve_resource_id(device, resource_id: str) -> str:
"""Auto-expand short resourceId (e.g. 'btn_login') to full form (e.g. 'com.example.app:id/btn_login') using the current foreground app package."""
if not resource_id or '/' in resource_id or ':' in resource_id:
return resource_id
try:
pkg = device.app_current().get('package', '')
except Exception:
pkg = ''
if pkg:
return f'{pkg}:id/{resource_id}'
return resource_id
@mcp.tool(name='ListDevices',description='List available ADB devices',annotations=ToolAnnotations(title="List Devices",readOnlyHint=True))
def list_devices_tool():