preflight-ios-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +406 -0
- package/dist/helpers/applescript.d.ts +24 -0
- package/dist/helpers/applescript.js +116 -0
- package/dist/helpers/coordinate-mapper.d.ts +44 -0
- package/dist/helpers/coordinate-mapper.js +132 -0
- package/dist/helpers/idb.d.ts +30 -0
- package/dist/helpers/idb.js +169 -0
- package/dist/helpers/logger.d.ts +9 -0
- package/dist/helpers/logger.js +47 -0
- package/dist/helpers/simctl.d.ts +47 -0
- package/dist/helpers/simctl.js +174 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +139 -0
- package/dist/mouse-events +0 -0
- package/dist/tools/advanced.d.ts +203 -0
- package/dist/tools/advanced.js +275 -0
- package/dist/tools/app.d.ts +85 -0
- package/dist/tools/app.js +177 -0
- package/dist/tools/debug.d.ts +140 -0
- package/dist/tools/debug.js +511 -0
- package/dist/tools/device.d.ts +74 -0
- package/dist/tools/device.js +130 -0
- package/dist/tools/interaction.d.ts +101 -0
- package/dist/tools/interaction.js +159 -0
- package/dist/tools/playwright.d.ts +69 -0
- package/dist/tools/playwright.js +204 -0
- package/dist/tools/screenshot.d.ts +27 -0
- package/dist/tools/screenshot.js +97 -0
- package/dist/tools/system.d.ts +85 -0
- package/dist/tools/system.js +107 -0
- package/dist/tools/ui.d.ts +86 -0
- package/dist/tools/ui.js +245 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
# Preflight MCP
|
|
2
|
+
|
|
3
|
+
The most comprehensive MCP (Model Context Protocol) server for iOS Simulator automation. Gives AI agents like Claude, ChatGPT, Cursor, Windsurf, and any MCP-compatible tool full control over iOS Simulators — tap, swipe, type, read accessibility trees, inspect app data, capture screenshots, record video, manage devices, and debug apps in real time.
|
|
4
|
+
|
|
5
|
+
**57 tools** across 10 categories. Zero cursor interference — works silently in the background while you use your Mac.
|
|
6
|
+
|
|
7
|
+
Inspired by [Playwright MCP](https://github.com/anthropics/mcp-server-playwright) for web automation — Preflight brings the same structured accessibility-first approach to iOS.
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/preflight-ios-mcp)
|
|
10
|
+
[](https://opensource.org/licenses/MIT)
|
|
11
|
+
|
|
12
|
+
## Why Preflight?
|
|
13
|
+
|
|
14
|
+
- **No disk clutter** — Screenshots and video frames return directly in chat. No folders filling up.
|
|
15
|
+
- **AI-optimized** — Images compressed for minimal token usage. Video → key frames (most AI models can't view video files).
|
|
16
|
+
- **Accessibility-first** — Like Playwright's `browser_snapshot`, use `simulator_snapshot` to understand the screen without vision models.
|
|
17
|
+
- **Cursor-free** — Touch injection via idb (IndigoHID) — your Mac cursor stays put.
|
|
18
|
+
- **57 tools** — From basic tap/swipe to Dynamic Type testing, biometric enrollment, crash log analysis.
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### Prerequisites
|
|
23
|
+
|
|
24
|
+
- macOS with Xcode and iOS Simulator installed
|
|
25
|
+
- Node.js 18+
|
|
26
|
+
- [Facebook idb](https://fbidb.io/) (recommended for cursor-free operation)
|
|
27
|
+
|
|
28
|
+
### Install idb (recommended)
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
brew tap facebook/fb
|
|
32
|
+
brew install idb-companion
|
|
33
|
+
pip3 install fb-idb
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
> Without idb, the server falls back to CGEvent mouse injection (works but briefly moves your cursor).
|
|
37
|
+
|
|
38
|
+
### Install via npm (recommended)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install -g preflight-ios-mcp
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Build from Source
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
git clone https://github.com/EthanAckerman-git/Preflight.git
|
|
48
|
+
cd Preflight
|
|
49
|
+
npm install
|
|
50
|
+
npm run build
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Setup by IDE / AI Tool
|
|
54
|
+
|
|
55
|
+
> Add your Python bin directory to `PATH` if idb was installed via pip (e.g., `~/Library/Python/3.x/bin`).
|
|
56
|
+
|
|
57
|
+
### Claude Code
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
claude mcp add preflight -- npx preflight-ios-mcp
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Or add to **.mcp.json** in your project root:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"mcpServers": {
|
|
68
|
+
"preflight": {
|
|
69
|
+
"command": "npx",
|
|
70
|
+
"args": ["preflight-ios-mcp"],
|
|
71
|
+
"env": {
|
|
72
|
+
"PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Cursor
|
|
80
|
+
|
|
81
|
+
Add to **~/.cursor/mcp.json** (global) or **.cursor/mcp.json** (per-project):
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"mcpServers": {
|
|
86
|
+
"preflight": {
|
|
87
|
+
"command": "npx",
|
|
88
|
+
"args": ["preflight-ios-mcp"],
|
|
89
|
+
"env": {
|
|
90
|
+
"PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Then in Cursor: **Settings → MCP** — verify "preflight" shows as connected.
|
|
98
|
+
|
|
99
|
+
### Windsurf
|
|
100
|
+
|
|
101
|
+
Add to **~/.codeium/windsurf/mcp_config.json**:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"mcpServers": {
|
|
106
|
+
"preflight": {
|
|
107
|
+
"command": "npx",
|
|
108
|
+
"args": ["preflight-ios-mcp"],
|
|
109
|
+
"env": {
|
|
110
|
+
"PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Then in Windsurf: **Settings → Cascade → MCP** — verify "preflight" appears.
|
|
118
|
+
|
|
119
|
+
### VS Code (Copilot / Cline / Continue)
|
|
120
|
+
|
|
121
|
+
Add to **.vscode/mcp.json** in your project:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"servers": {
|
|
126
|
+
"preflight": {
|
|
127
|
+
"command": "npx",
|
|
128
|
+
"args": ["preflight-ios-mcp"],
|
|
129
|
+
"env": {
|
|
130
|
+
"PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
For **Cline** (VS Code extension), add to **~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json**:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"mcpServers": {
|
|
142
|
+
"preflight": {
|
|
143
|
+
"command": "npx",
|
|
144
|
+
"args": ["preflight-ios-mcp"],
|
|
145
|
+
"env": {
|
|
146
|
+
"PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Zed
|
|
154
|
+
|
|
155
|
+
Add to **~/.config/zed/settings.json**:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"context_servers": {
|
|
160
|
+
"preflight": {
|
|
161
|
+
"command": {
|
|
162
|
+
"path": "npx",
|
|
163
|
+
"args": ["preflight-ios-mcp"],
|
|
164
|
+
"env": {
|
|
165
|
+
"PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Any MCP-Compatible Client
|
|
174
|
+
|
|
175
|
+
Preflight uses the standard MCP stdio transport. Configure your client to run:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
npx preflight-ios-mcp
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Set the `PATH` environment variable to include idb's location for cursor-free touch injection.
|
|
182
|
+
|
|
183
|
+
## Tools Reference
|
|
184
|
+
|
|
185
|
+
### Observation (6 tools)
|
|
186
|
+
|
|
187
|
+
| Tool | Description |
|
|
188
|
+
|------|-------------|
|
|
189
|
+
| `simulator_screenshot` | Take a JPEG screenshot optimized for AI chat (~200-400KB). Returns image inline. |
|
|
190
|
+
| `simulator_list_devices` | List simulators with name, UDID, state, runtime. Filter: `booted`, `available`, `all`. |
|
|
191
|
+
| `simulator_list_apps` | List installed apps with bundle IDs. Toggle `includeSystem` for system apps. |
|
|
192
|
+
| `simulator_app_info` | Get app metadata: name, version, bundle path, data path, type. |
|
|
193
|
+
| `simulator_get_clipboard` | Read the simulator's clipboard text. |
|
|
194
|
+
| `simulator_get_screen_info` | Window geometry, coordinate mapping, scale factor. Debug tap accuracy. |
|
|
195
|
+
|
|
196
|
+
### User Interaction (6 tools)
|
|
197
|
+
|
|
198
|
+
| Tool | Description |
|
|
199
|
+
|------|-------------|
|
|
200
|
+
| `simulator_tap` | Tap at (x, y) in simulator screen points. Cursor-free via idb. |
|
|
201
|
+
| `simulator_swipe` | Swipe between two points. Supports edge-swipe-back from x=1. |
|
|
202
|
+
| `simulator_long_press` | Long press with configurable duration. Context menus, drag initiation. |
|
|
203
|
+
| `simulator_type_text` | Type text into the focused field. |
|
|
204
|
+
| `simulator_press_key` | Press special keys (return, escape, arrows, F-keys) with modifiers. |
|
|
205
|
+
| `simulator_navigate_back` | Navigate back via Cmd+[. Workaround for edge-swipe limitations. |
|
|
206
|
+
|
|
207
|
+
### Playwright-Inspired (3 tools)
|
|
208
|
+
|
|
209
|
+
| Tool | Description |
|
|
210
|
+
|------|-------------|
|
|
211
|
+
| `simulator_snapshot` | **Preferred over screenshots.** Structured accessibility tree — roles, labels, values, positions. No vision model needed. Like Playwright's `browser_snapshot`. |
|
|
212
|
+
| `simulator_wait_for_element` | Wait for an element to appear (by label, role, or text). Polls with configurable timeout. Like Playwright's `browser_wait_for`. |
|
|
213
|
+
| `simulator_element_exists` | Quick boolean check: does an element matching criteria exist on screen right now? |
|
|
214
|
+
|
|
215
|
+
### Device Management (6 tools)
|
|
216
|
+
|
|
217
|
+
| Tool | Description |
|
|
218
|
+
|------|-------------|
|
|
219
|
+
| `simulator_boot` | Boot a device by name or UDID. Optional `waitForBoot` polling. |
|
|
220
|
+
| `simulator_shutdown` | Shut down a running simulator. |
|
|
221
|
+
| `simulator_erase` | Factory reset — erases all content and settings. |
|
|
222
|
+
| `simulator_open_url` | Open URLs or deep links (e.g., `myapp://screen`). |
|
|
223
|
+
| `simulator_open_simulator` | Open the Simulator.app application. |
|
|
224
|
+
| `simulator_get_booted_sim_id` | Get the UDID of the currently booted simulator. |
|
|
225
|
+
|
|
226
|
+
### App Management (4 tools)
|
|
227
|
+
|
|
228
|
+
| Tool | Description |
|
|
229
|
+
|------|-------------|
|
|
230
|
+
| `simulator_launch_app` | Launch by bundle ID with optional args and env vars. |
|
|
231
|
+
| `simulator_terminate_app` | Force-terminate a running app. |
|
|
232
|
+
| `simulator_install_app` | Install a .app bundle or .ipa from a local path. |
|
|
233
|
+
| `simulator_uninstall_app` | Uninstall by bundle ID. |
|
|
234
|
+
|
|
235
|
+
### Debugging & Diagnostics (9 tools)
|
|
236
|
+
|
|
237
|
+
| Tool | Description |
|
|
238
|
+
|------|-------------|
|
|
239
|
+
| `simulator_get_logs` | Query device logs. Filter by process, subsystem, level, time range, message content. |
|
|
240
|
+
| `simulator_stream_logs` | Live log streaming with start/read/stop lifecycle. Configurable buffer. |
|
|
241
|
+
| `simulator_get_app_container` | Get filesystem path to app's bundle, data, or shared group container. |
|
|
242
|
+
| `simulator_list_app_files` | Browse an app's Documents/, Library/, Caches/, tmp/ directories. |
|
|
243
|
+
| `simulator_read_app_file` | Read plists (→JSON), SQLite (→schema), and text files from app data. |
|
|
244
|
+
| `simulator_get_crash_logs` | Retrieve crash reports with stack traces and thread states. |
|
|
245
|
+
| `simulator_diagnose` | Xcode version, disk usage, booted devices, system info. |
|
|
246
|
+
| `simulator_accessibility_audit` | Full iOS accessibility tree — real UIButton/UILabel elements with labels, frames, roles. |
|
|
247
|
+
| `simulator_describe_point` | Returns the accessibility element at given coordinates. |
|
|
248
|
+
|
|
249
|
+
### System Simulation (5 tools)
|
|
250
|
+
|
|
251
|
+
| Tool | Description |
|
|
252
|
+
|------|-------------|
|
|
253
|
+
| `simulator_set_location` | Set GPS coordinates (lat/lng). Test location-based features. |
|
|
254
|
+
| `simulator_send_push` | Send push notifications with full APNs payload JSON. |
|
|
255
|
+
| `simulator_set_clipboard` | Set the simulator clipboard text. |
|
|
256
|
+
| `simulator_add_media` | Add photos/videos to the camera roll from local files. |
|
|
257
|
+
| `simulator_grant_permission` | Grant, revoke, or reset permissions (camera, location, photos, contacts, microphone, etc.). |
|
|
258
|
+
|
|
259
|
+
### UI Configuration (4 tools)
|
|
260
|
+
|
|
261
|
+
| Tool | Description |
|
|
262
|
+
|------|-------------|
|
|
263
|
+
| `simulator_set_appearance` | Switch between light and dark mode. |
|
|
264
|
+
| `simulator_override_status_bar` | Set time, battery, signal, carrier, network type. |
|
|
265
|
+
| `simulator_record_video` | Start screen recording. On stop, key frames are extracted as images for AI chat. |
|
|
266
|
+
| `simulator_stop_recording` | Stop recording. Returns key frames inline (no disk clutter). Optional `savePath` to keep the video. |
|
|
267
|
+
|
|
268
|
+
### Advanced Debugging & Testing (14 tools)
|
|
269
|
+
|
|
270
|
+
| Tool | Description |
|
|
271
|
+
|------|-------------|
|
|
272
|
+
| `simulator_set_content_size` | Set Dynamic Type preferred size (13 categories from extra-small to accessibility-XXXL). |
|
|
273
|
+
| `simulator_set_increase_contrast` | Toggle Increase Contrast accessibility setting. |
|
|
274
|
+
| `simulator_location_scenario` | Run predefined GPS routes: Freeway Drive, City Run, City Bicycle Ride. |
|
|
275
|
+
| `simulator_location_route` | Simulate movement along custom waypoints with configurable speed. |
|
|
276
|
+
| `simulator_memory_warning` | Trigger simulated memory warning (didReceiveMemoryWarning). |
|
|
277
|
+
| `simulator_keychain` | Add root certificates, add certificates, or reset the device keychain. |
|
|
278
|
+
| `simulator_icloud_sync` | Trigger iCloud synchronization on the device. |
|
|
279
|
+
| `simulator_verbose_logging` | Enable/disable verbose device logging for deep debugging. |
|
|
280
|
+
| `simulator_install_app_data` | Install .xcappdata packages to restore test data snapshots. |
|
|
281
|
+
| `simulator_get_env` | Read environment variables from the running simulator. |
|
|
282
|
+
| `simulator_biometric` | Set Face ID / Touch ID enrollment state for auth testing. |
|
|
283
|
+
| `simulator_network_status` | Get network configuration — DNS, interfaces, connectivity status. |
|
|
284
|
+
| `simulator_defaults_read` | Read UserDefaults from inside the simulator (inspect app prefs, feature flags). |
|
|
285
|
+
| `simulator_defaults_write` | Write UserDefaults inside the simulator (set flags, inject test config). |
|
|
286
|
+
|
|
287
|
+
## Architecture
|
|
288
|
+
|
|
289
|
+
```
|
|
290
|
+
src/
|
|
291
|
+
├── index.ts # MCP server entry, 57 tool registrations
|
|
292
|
+
├── helpers/
|
|
293
|
+
│ ├── idb.ts # Facebook idb CLI wrapper (cursor-free touch)
|
|
294
|
+
│ ├── simctl.ts # xcrun simctl command wrapper
|
|
295
|
+
│ ├── applescript.ts # Keyboard input + CGEvent fallback
|
|
296
|
+
│ ├── coordinate-mapper.ts # Simulator points → macOS screen coords
|
|
297
|
+
│ ├── mouse-events.swift # Native Swift CGEvent binary (fallback)
|
|
298
|
+
│ └── logger.ts # Structured stderr logging
|
|
299
|
+
└── tools/
|
|
300
|
+
├── screenshot.ts # JPEG capture optimized for AI chat
|
|
301
|
+
├── interaction.ts # Tap, swipe, long press, type, key
|
|
302
|
+
├── device.ts # Boot, shutdown, erase, open URL
|
|
303
|
+
├── app.ts # Install, launch, terminate, list
|
|
304
|
+
├── system.ts # Location, push, clipboard, media, permissions
|
|
305
|
+
├── ui.ts # Appearance, status bar, video recording, navigate back
|
|
306
|
+
├── debug.ts # Logs, files, crash reports, accessibility
|
|
307
|
+
├── advanced.ts # Dynamic Type, keychain, iCloud, biometric, defaults
|
|
308
|
+
└── playwright.ts # Snapshot, wait_for_element, element_exists
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Design Philosophy
|
|
312
|
+
|
|
313
|
+
**Accessibility-first, like Playwright MCP:**
|
|
314
|
+
1. Use `simulator_snapshot` to understand the screen (structured text, no vision model)
|
|
315
|
+
2. Use coordinates from the snapshot to `simulator_tap`, `simulator_swipe`, etc.
|
|
316
|
+
3. Use `simulator_screenshot` when you need visual verification
|
|
317
|
+
4. Use `simulator_wait_for_element` before interacting with elements that appear after transitions
|
|
318
|
+
|
|
319
|
+
**No disk clutter:**
|
|
320
|
+
- Screenshots return as base64 in chat — no folders filling up your Desktop
|
|
321
|
+
- Video recordings extract key frames as inline images on stop
|
|
322
|
+
- Optional `savePath` parameter if you actually need files on disk
|
|
323
|
+
|
|
324
|
+
### Touch Injection Pipeline
|
|
325
|
+
|
|
326
|
+
```
|
|
327
|
+
simulator_tap(x=200, y=400)
|
|
328
|
+
│
|
|
329
|
+
├─ idb available? ──YES──► idb ui tap --udid <UDID> 200 400
|
|
330
|
+
│ (IndigoHID → real iOS touch event)
|
|
331
|
+
│ (zero cursor movement)
|
|
332
|
+
│
|
|
333
|
+
└─ idb unavailable? ──► coordinate mapper → macOS screen coords
|
|
334
|
+
→ Swift CGEvent binary → mouse down/up
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## Demo App
|
|
338
|
+
|
|
339
|
+
A SwiftUI demo app is included in `demo-app/` for testing all MCP features:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
cd demo-app
|
|
343
|
+
xcodebuild -project MCPDemo.xcodeproj -scheme MCPDemo \
|
|
344
|
+
-destination 'platform=iOS Simulator,name=iPhone 16 Pro' \
|
|
345
|
+
build
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
The demo app has 4 tabs exercising every tool category:
|
|
349
|
+
- **Interactions**: Buttons, text fields, long-press zones, navigation stack, scrollable lists
|
|
350
|
+
- **Location**: Live GPS display for testing `simulator_set_location`
|
|
351
|
+
- **Notifications**: Push notification display for testing `simulator_send_push`
|
|
352
|
+
- **Settings**: Clipboard, file I/O, accessibility toggles, UserDefaults
|
|
353
|
+
|
|
354
|
+
## Configuration
|
|
355
|
+
|
|
356
|
+
### Environment Variables
|
|
357
|
+
|
|
358
|
+
| Variable | Default | Description |
|
|
359
|
+
|----------|---------|-------------|
|
|
360
|
+
| `LOG_LEVEL` | `info` | Logging level: `debug`, `info`, `warn`, `error` |
|
|
361
|
+
| `PREFLIGHT_FILTERED_TOOLS` | (none) | Comma-separated list of tool names to disable |
|
|
362
|
+
| `PREFLIGHT_IDB_PATH` | (auto-detect) | Custom path to idb binary |
|
|
363
|
+
| `PATH` | System PATH | Must include idb binary location |
|
|
364
|
+
|
|
365
|
+
## Example Prompts
|
|
366
|
+
|
|
367
|
+
### QA Testing
|
|
368
|
+
> "Boot the iPhone 16 Pro simulator, install my app at ./build/MyApp.app, launch it, and take a screenshot of the home screen. Then tap the login button, type test@email.com in the email field, and verify the form validation works."
|
|
369
|
+
|
|
370
|
+
### Accessibility-First Workflow (Playwright-style)
|
|
371
|
+
> "Take a snapshot of the current screen to see what elements are available. Then tap the button labeled 'Sign In' and wait for the email text field to appear."
|
|
372
|
+
|
|
373
|
+
### Debugging
|
|
374
|
+
> "My app is crashing on launch. Check the crash logs for MyApp, then get the last 5 minutes of device logs filtered to the MyApp process."
|
|
375
|
+
|
|
376
|
+
### Dark Mode Testing
|
|
377
|
+
> "Switch to dark mode, take a screenshot, then switch to light mode and screenshot again."
|
|
378
|
+
|
|
379
|
+
## Troubleshooting
|
|
380
|
+
|
|
381
|
+
### idb not detected
|
|
382
|
+
If tools show `[CGEvent fallback]` instead of `[cursor-free]`:
|
|
383
|
+
|
|
384
|
+
1. Verify idb is installed: `which idb` or check `~/Library/Python/3.x/bin/idb`
|
|
385
|
+
2. Add the idb path to your MCP config's `PATH` env var
|
|
386
|
+
3. Or set `PREFLIGHT_IDB_PATH` directly
|
|
387
|
+
|
|
388
|
+
### Simulator not found
|
|
389
|
+
1. Open Simulator.app: `open -a Simulator`
|
|
390
|
+
2. Boot a device: use `simulator_boot` or `xcrun simctl boot "iPhone 16 Pro"`
|
|
391
|
+
|
|
392
|
+
### Accessibility permission errors
|
|
393
|
+
1. Go to System Settings → Privacy & Security → Accessibility
|
|
394
|
+
2. Add your terminal app (Terminal.app, iTerm, Claude Code, Cursor, Windsurf, etc.)
|
|
395
|
+
|
|
396
|
+
## Development
|
|
397
|
+
|
|
398
|
+
```bash
|
|
399
|
+
npm run dev # Watch mode (TypeScript only)
|
|
400
|
+
npm run build # Full rebuild (TypeScript + Swift binary)
|
|
401
|
+
node dist/index.js # Run directly
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
## License
|
|
405
|
+
|
|
406
|
+
MIT License — see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bring Simulator.app to the foreground.
|
|
3
|
+
*/
|
|
4
|
+
export declare function activateSimulator(): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Tap at absolute macOS screen coordinates using the compiled Swift mouse-events helper.
|
|
7
|
+
*/
|
|
8
|
+
export declare function tap(macX: number, macY: number): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Long press at absolute macOS screen coordinates.
|
|
11
|
+
*/
|
|
12
|
+
export declare function longPress(macX: number, macY: number, durationMs?: number): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Swipe from one point to another using the compiled Swift mouse-events helper.
|
|
15
|
+
*/
|
|
16
|
+
export declare function swipe(startMacX: number, startMacY: number, endMacX: number, endMacY: number, durationMs?: number, steps?: number): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Type text into the currently focused field in Simulator.
|
|
19
|
+
*/
|
|
20
|
+
export declare function typeText(text: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Press a special key with optional modifiers.
|
|
23
|
+
*/
|
|
24
|
+
export declare function pressKey(keyName: string, modifiers?: string[]): Promise<void>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { execCommand, runAppleScript } from './simctl.js';
|
|
2
|
+
import * as logger from './logger.js';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const MOUSE_HELPER = path.join(__dirname, '..', 'mouse-events');
|
|
7
|
+
/**
|
|
8
|
+
* Bring Simulator.app to the foreground.
|
|
9
|
+
*/
|
|
10
|
+
export async function activateSimulator() {
|
|
11
|
+
await runAppleScript('tell application "Simulator" to activate', 'applescript');
|
|
12
|
+
// Small delay for window to come to front
|
|
13
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Tap at absolute macOS screen coordinates using the compiled Swift mouse-events helper.
|
|
17
|
+
*/
|
|
18
|
+
export async function tap(macX, macY) {
|
|
19
|
+
const x = Math.round(macX);
|
|
20
|
+
const y = Math.round(macY);
|
|
21
|
+
logger.debug('applescript', `Tap at mac(${x},${y})`);
|
|
22
|
+
await activateSimulator();
|
|
23
|
+
await execCommand(MOUSE_HELPER, ['tap', String(x), String(y)], 'applescript:tap');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Long press at absolute macOS screen coordinates.
|
|
27
|
+
*/
|
|
28
|
+
export async function longPress(macX, macY, durationMs = 1000) {
|
|
29
|
+
const x = Math.round(macX);
|
|
30
|
+
const y = Math.round(macY);
|
|
31
|
+
logger.debug('applescript', `Long press at mac(${x},${y}) for ${durationMs}ms`);
|
|
32
|
+
await activateSimulator();
|
|
33
|
+
await execCommand(MOUSE_HELPER, ['longpress', String(x), String(y), String(durationMs)], 'applescript:longPress');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Swipe from one point to another using the compiled Swift mouse-events helper.
|
|
37
|
+
*/
|
|
38
|
+
export async function swipe(startMacX, startMacY, endMacX, endMacY, durationMs = 300, steps = 20) {
|
|
39
|
+
logger.debug('applescript', `Swipe from mac(${Math.round(startMacX)},${Math.round(startMacY)}) to mac(${Math.round(endMacX)},${Math.round(endMacY)}) in ${durationMs}ms`);
|
|
40
|
+
await activateSimulator();
|
|
41
|
+
await execCommand(MOUSE_HELPER, ['swipe', String(Math.round(startMacX)), String(Math.round(startMacY)), String(Math.round(endMacX)), String(Math.round(endMacY)), String(steps), String(durationMs)], 'applescript:swipe');
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Type text into the currently focused field in Simulator.
|
|
45
|
+
*/
|
|
46
|
+
export async function typeText(text) {
|
|
47
|
+
logger.debug('applescript', `Typing text: "${text.slice(0, 50)}${text.length > 50 ? '...' : ''}"`);
|
|
48
|
+
await activateSimulator();
|
|
49
|
+
// Escape for AppleScript string
|
|
50
|
+
const escaped = text.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
51
|
+
const script = `
|
|
52
|
+
tell application "System Events"
|
|
53
|
+
keystroke "${escaped}"
|
|
54
|
+
end tell
|
|
55
|
+
`;
|
|
56
|
+
await runAppleScript(script, 'applescript:type');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Press a special key with optional modifiers.
|
|
60
|
+
*/
|
|
61
|
+
export async function pressKey(keyName, modifiers = []) {
|
|
62
|
+
logger.debug('applescript', `Press key: ${keyName}`, { modifiers });
|
|
63
|
+
await activateSimulator();
|
|
64
|
+
const keyCodeMap = {
|
|
65
|
+
return: 36,
|
|
66
|
+
enter: 76,
|
|
67
|
+
escape: 53,
|
|
68
|
+
delete: 51,
|
|
69
|
+
forwarddelete: 117,
|
|
70
|
+
tab: 48,
|
|
71
|
+
space: 49,
|
|
72
|
+
up: 126,
|
|
73
|
+
down: 125,
|
|
74
|
+
left: 123,
|
|
75
|
+
right: 124,
|
|
76
|
+
home: 115,
|
|
77
|
+
end: 119,
|
|
78
|
+
pageup: 116,
|
|
79
|
+
pagedown: 121,
|
|
80
|
+
f1: 122, f2: 120, f3: 99, f4: 118, f5: 96,
|
|
81
|
+
f6: 97, f7: 98, f8: 100, f9: 101, f10: 109,
|
|
82
|
+
f11: 103, f12: 111,
|
|
83
|
+
volumeup: 72,
|
|
84
|
+
volumedown: 73,
|
|
85
|
+
mute: 74,
|
|
86
|
+
// Browser/editor navigation
|
|
87
|
+
'[': 33, ']': 30,
|
|
88
|
+
'-': 27, '=': 24,
|
|
89
|
+
',': 43, '.': 47, '/': 44,
|
|
90
|
+
';': 41, "'": 39, '`': 50,
|
|
91
|
+
'\\': 42,
|
|
92
|
+
};
|
|
93
|
+
const code = keyCodeMap[keyName.toLowerCase()];
|
|
94
|
+
if (code === undefined) {
|
|
95
|
+
throw new Error(`Unknown key: "${keyName}". Valid keys: ${Object.keys(keyCodeMap).join(', ')}`);
|
|
96
|
+
}
|
|
97
|
+
const modParts = modifiers.map(m => {
|
|
98
|
+
switch (m.toLowerCase()) {
|
|
99
|
+
case 'command':
|
|
100
|
+
case 'cmd': return 'command down';
|
|
101
|
+
case 'shift': return 'shift down';
|
|
102
|
+
case 'option':
|
|
103
|
+
case 'alt': return 'option down';
|
|
104
|
+
case 'control':
|
|
105
|
+
case 'ctrl': return 'control down';
|
|
106
|
+
default: throw new Error(`Unknown modifier: "${m}". Valid: command, shift, option, control`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
const modStr = modParts.length > 0 ? ` using {${modParts.join(', ')}}` : '';
|
|
110
|
+
const script = `
|
|
111
|
+
tell application "System Events"
|
|
112
|
+
key code ${code}${modStr}
|
|
113
|
+
end tell
|
|
114
|
+
`;
|
|
115
|
+
await runAppleScript(script, 'applescript:pressKey');
|
|
116
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface WindowGeometry {
|
|
2
|
+
windowX: number;
|
|
3
|
+
windowY: number;
|
|
4
|
+
windowWidth: number;
|
|
5
|
+
windowHeight: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ScreenMapping {
|
|
8
|
+
windowGeometry: WindowGeometry;
|
|
9
|
+
devicePointWidth: number;
|
|
10
|
+
devicePointHeight: number;
|
|
11
|
+
scaleFactor: number;
|
|
12
|
+
titleBarHeight: number;
|
|
13
|
+
contentWidth: number;
|
|
14
|
+
contentHeight: number;
|
|
15
|
+
scaleX: number;
|
|
16
|
+
scaleY: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the Simulator.app front window position and size using AppleScript.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getSimulatorWindowGeometry(): Promise<WindowGeometry>;
|
|
22
|
+
/**
|
|
23
|
+
* Get the device screen dimensions in points by taking a screenshot and reading its pixel dimensions.
|
|
24
|
+
* Returns { pointWidth, pointHeight, scaleFactor }.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getDeviceScreenDimensions(device: string): Promise<{
|
|
27
|
+
pointWidth: number;
|
|
28
|
+
pointHeight: number;
|
|
29
|
+
scaleFactor: number;
|
|
30
|
+
pixelWidth: number;
|
|
31
|
+
pixelHeight: number;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Compute the full screen mapping from simulator points to macOS screen coordinates.
|
|
35
|
+
* Cached for 10 seconds to improve performance during rapid interactions.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getScreenMapping(device: string): Promise<ScreenMapping>;
|
|
38
|
+
/**
|
|
39
|
+
* Convert simulator screen point coordinates to macOS absolute screen coordinates.
|
|
40
|
+
*/
|
|
41
|
+
export declare function simToMac(simX: number, simY: number, mapping: ScreenMapping): {
|
|
42
|
+
macX: number;
|
|
43
|
+
macY: number;
|
|
44
|
+
};
|