rn-mcp CLI (Snapshot + Refs)
A shell-first interface for AI agents to control React Native apps. Uses the Snapshot + Refs pattern inspired by agent-browser for token-efficient interaction.
Why CLI?
Installation
The CLI is included in the same package:
Prerequisites
- MCP server must be running (started by your editor or
npx react-native-mcp-server) - App must be running on a simulator/emulator and connected via WebSocket (port 12300)
- iOS: idb installed
- Android: adb installed
Workflow
Snapshot output example
Each element gets a short ref (@e1, @e2, ...) assigned in depth-first order.
Commands
Connection
Snapshot
Interaction
Available keys: back, home, enter, tab, delete, up, down, left, right
Assertions
Query
Screenshot
Agent Guide Setup
Global Options
Refs System
How refs work
rn-mcp snapshot -iassigns@e1,@e2, ... to each element (depth-first order)- Refs are saved to
~/.rn-mcp/session.json - Subsequent commands use refs:
rn-mcp tap @e3 - Running snapshot again invalidates all previous refs
When to re-snapshot
- After screen transitions (navigation, modal open/close)
- When
@ref not founderror occurs - After actions that change the UI structure
Selectors (alternative to refs)
You can also use selectors directly without snapshot:
Important Notes
- iOS orientation is handled automatically — no manual action needed
- Android dp→px conversion is automatic
- Coordinates are in points (dp), not pixels
- Use
--jsonflag for programmatic output parsing