Skip to content

MCP tools ​

Every device tool runs the toets core code its test API runs and answers with the matching test code, so what works in exploration pastes into a test. Elements are addressed with a target: { testId?, text?, exact?, nth? }, the same selectors tests use (app.getByTestId(id).getByText(text).nth(n)). Prefer test IDs.

ToolDoesIn a test
launchStarts or restarts the app on a target, optionally into a state with flags or from a deepLink.await app.launch({ state, flags, deepLink })
open_deep_linkDelivers a deep link (url) to the running app; reports the translation and where focus landed.await app.openDeepLink(url)
snapshotText snapshot of the screen (or a subtree), byte for byte what a test gets.await app.snapshot()
pressPresses remote keys in order (key overrides applied); reports where focus landed.app.remote.press / repeat / sequence
press_until_focusedPresses one D-pad direction until a target holds focus; reports the presses.await app.focus.pressUntilFocused(Key.RIGHT, locator)
navigate_toMoves focus to an on-screen target with real D-pad presses; reports the path.await app.focus.navigateTo(locator)
fillReplaces a field's text with its keyboard (declared app keyboard or system); no submit.await locator.fill(text, { mask })
typeTypes at the end of the field on the keyboard in use.await app.keyboard.type(text, { mask })
eraseDeletes characters with the keyboard's backspace.await app.keyboard.erase(count)
submitPresses the keyboard's submit key (or the system action key).await app.keyboard.submit()
queryLists current matches of a target with state and bounds.app.getByTestId(...)
assertAny toets matcher, retried until timeout; passes and fails exactly like expect.await expect(locator).toBeFocused()
screenshotPNG of the screen or of one element.await app.screenshot(), locator.screenshot()
capabilitiesPlatform, capabilities, keys, key overrides, keyboards, deep links, SDK and mocking status, targets.requires(...), app.platform.has()
docs_searchSearches the docs shipped in installed @toets/* packages.

Matchers ​

assert takes every toets matcher except the screenshot baseline: locator states (toBeVisible, toBeInViewport, toBeFocused, toHaveFocusWithin, toBeEnabled, toBeDisabled, toBeSelected, toBeBusy), toHaveText, toContainText, toHaveValue, toHaveCount, toMatchTextSnapshot (screen or target), media (toBePlaying, toBePaused, toHaveMediaState, toHavePosition), toHaveRequested and toBeOpen (on app.keyboard, no target). Any of them with not.

Text entry ​

fill, type, erase and submit pick the keyboard like tests do; see text input. App keyboards come from the keyboards option of the test config (or keyboards in toets.mcp.config.*, top level or per target); capabilities lists them. Pass mask: true for PINs and passwords: the text never shows in the output, and the code line carries a placeholder to replace. System password fields mask on their own.

launch with deepLink and open_deep_link take the canonical link a test uses (myapp://details/42) and answer with the step, translation included (openDeepLink myapp://details/42 → intent com.example.PLAY ...), and the focused element. The translation is the target's deepLink mapper from the test config; see deep links. capabilities says whether the target can launch from a link (deeplink.launch) and open one in the running app (deeplink.open).

Text snapshot ​

The core text snapshot format, so snapshot output pastes into toMatchTextSnapshot:

yaml
- rail_popular:
    - card_1 "Movie 1" [focused]
    - card_2 "Movie 2"

System text fields show their value, and a declared app keyboard collapses to one line (snapshot with its target shows the keys):

yaml
- email [editable] value="a@b.co"
- password [editable, secure] value="••••"
- 'osk [keyboard: search, layer: lower, focused: "m"]'

Errors ​

Failures come back as tool errors with a code, a hint and a docs link, like every toets error. Common ones:

CodeMeaning and fix
MCP_NOT_LAUNCHEDCall launch first.
MCP_NO_CONFIGNo test config with toets projects and no toets.mcp.config.*; see setup.
KEY_UNSUPPORTEDThe target lacks the key's capability; check capabilities. Nothing was pressed.
CAPABILITY_MISSINGstate, media or network checks need the SDK or mocking on.
ELEMENT_NOT_FOUNDNothing matches. Virtualized lists only render items near focus: press_until_focused toward it.
STRICT_MODE_VIOLATIONThe target matches several elements; use a test ID, exact or nth.
FOCUS_STUCKA press_until_focused press did not move focus: end of a row, a trap or a disabled target.
FOCUS_LOOPFocus came back to an element it left: the target is not in that direction.
NO_KEYBOARDNo declared keyboard lists the field and it is no system text field; add one to keyboards.
CHAR_NOT_ON_KEYBOARDNo key types the character on any layer reached; declare layers, keys or space.
DEEPLINK_UNHANDLEDNo activity, URL scheme or page of the app handles the translated link.
FOCUS_UNREACHABLED-pad presses can not get there (focus trap, disabled path). The message says where focus is.

assert failing is also a tool error: FAIL after 5000ms: <code>, then the message expect would print.