mirror of
https://github.com/mobile-next/mobile-mcp.git
synced 2026-10-02 01:05:27 +08:00
`mobile_list_elements_on_screen` called `response.data.elements.flatMap(...)`
directly. When the device screen is off or locked, `mobilecli dump ui` answers
with `{"status": "ok", "data": {}}`, so `.elements` is `undefined` and the call
died with a raw "Cannot read properties of undefined (reading 'flatMap')"
TypeError and a stack trace.
An agent driving the device got an unactionable internal error instead of
something it could recover from, and the correct next step (wake the device)
was not discoverable from the message, so it typically retried the same failing
call.
Guard both levels of the payload and raise an `ActionableError`, which the tool
wrapper already renders as "<message>. Please fix the issue and try again."
without a stack trace. `DumpUIResponse` now models `data` and `data.elements`
as optional so the guard is type-honest rather than a cast.
An empty `elements` array still resolves to an empty list, so a genuinely empty
screen keeps its previous behaviour.
Closes #455
Co-authored-by: Yi-111-a <42726078+Yi-111-a@users.noreply.github.com>