INNER CODE UNIT · Python
lifespan
CursorTouch/Android-MCP · src/android_mcp/__main__.py:202
async def lifespan(app: FastMCP):
"""Runs initialization code before the server starts and cleanup code after it shuts down."""
yield
mcp = FastMCP(name="Android-MCP", instructions=instructions, lifespan=lifespan)
mobile = Mobile()
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: