# ui_snapshot

The accessibility tree of a window as text, each element with an id that `ui_act` and the pointer tools accept. Prefer it to a screenshot where the app exposes one: it is cheaper and does not depend on pixels. Some apps expose little or nothing (then use `screen_capture`); the answer says when a limit cut the tree.

**In short:** Risk class [`screen`](https://docs.cmdop.ai/reference/tools.md#risk-classes). Over MCP call `ui_snapshot`; over HTTP send `"tool": "ui_snapshot"` to [`POST /api/v1/call`](https://docs.cmdop.ai/reference/http/post-call.md).

## Arguments

Over MCP every tool also takes `machine`: the machine's name or id, optional when only one machine is online.

| Name | Type | Required | Meaning |
| --- | --- | --- | --- |
| `depth` | `integer` | no | Tree depth (default 12). |
| `max_elements` | `integer` | no | At most this many elements (default 400, at most 3000). |
| `window` | `integer` | no | Window id from `window_list` (default: the frontmost window). |

## Result

| Name | Type | Required | Meaning |
| --- | --- | --- | --- |
| `elements` | `integer` | yes |  |
| `snapshot` | `string` | yes | Valid until the next snapshot; element ids belong to it. |
| `text` | `string` | yes | The tree as indented text, one element per line: `[id] role "name" value (state)`. |
| `truncated` | `string` | no | `depth`, `max_elements` or `time` when a limit cut the tree; absent when complete. |
| `window` | `integer` | no |  |

## Examples

**MCP**

```json
{
  "name": "ui_snapshot",
  "arguments": {
    "machine": "<machine>"
  }
}
```

**HTTP**

```bash
curl -sS -X POST "https://<contour>.cmdop.ai/api/v1/call" \
  -H "Authorization: Bearer $CMDOP_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"machine":"<machine>","tool":"ui_snapshot","args":{}}'
```

## Limits

The call times out after 30 s (`timed_out`). Available since version 0.0.2. A refused or failed call returns one of the [error codes](https://docs.cmdop.ai/reference/errors.md).
