react-native-ai-debugger 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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +303 -0
  3. package/build/core/android.d.ts +108 -0
  4. package/build/core/android.d.ts.map +1 -0
  5. package/build/core/android.js +686 -0
  6. package/build/core/android.js.map +1 -0
  7. package/build/core/connection.d.ts +12 -0
  8. package/build/core/connection.d.ts.map +1 -0
  9. package/build/core/connection.js +242 -0
  10. package/build/core/connection.js.map +1 -0
  11. package/build/core/executor.d.ts +6 -0
  12. package/build/core/executor.d.ts.map +1 -0
  13. package/build/core/executor.js +112 -0
  14. package/build/core/executor.js.map +1 -0
  15. package/build/core/index.d.ts +10 -0
  16. package/build/core/index.d.ts.map +1 -0
  17. package/build/core/index.js +21 -0
  18. package/build/core/index.js.map +1 -0
  19. package/build/core/ios.d.ts +54 -0
  20. package/build/core/ios.d.ts.map +1 -0
  21. package/build/core/ios.js +393 -0
  22. package/build/core/ios.js.map +1 -0
  23. package/build/core/logs.d.ts +27 -0
  24. package/build/core/logs.d.ts.map +1 -0
  25. package/build/core/logs.js +102 -0
  26. package/build/core/logs.js.map +1 -0
  27. package/build/core/metro.d.ts +8 -0
  28. package/build/core/metro.d.ts.map +1 -0
  29. package/build/core/metro.js +79 -0
  30. package/build/core/metro.js.map +1 -0
  31. package/build/core/network.d.ts +37 -0
  32. package/build/core/network.d.ts.map +1 -0
  33. package/build/core/network.js +210 -0
  34. package/build/core/network.js.map +1 -0
  35. package/build/core/state.d.ts +9 -0
  36. package/build/core/state.d.ts.map +1 -0
  37. package/build/core/state.js +16 -0
  38. package/build/core/state.js.map +1 -0
  39. package/build/core/types.d.ts +68 -0
  40. package/build/core/types.d.ts.map +1 -0
  41. package/build/core/types.js +2 -0
  42. package/build/core/types.js.map +1 -0
  43. package/build/index.d.ts +3 -0
  44. package/build/index.d.ts.map +1 -0
  45. package/build/index.js +951 -0
  46. package/build/index.js.map +1 -0
  47. package/package.json +50 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2025 Ihor Zheludkov
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,303 @@
1
+ # React Native AI Debugger
2
+
3
+ An MCP (Model Context Protocol) server for AI-powered React Native debugging. Enables AI assistants like Claude to capture logs, execute code, inspect state, and control navigation in your React Native app.
4
+
5
+ ## Features
6
+
7
+ - Captures `console.log`, `console.warn`, `console.error` from React Native apps
8
+ - **Network request tracking** - capture HTTP requests/responses with headers, timing, and status
9
+ - Supports both **Expo SDK 54+** (React Native Bridgeless) and **RN 0.70+** (Hermes)
10
+ - Auto-discovers running Metro servers on common ports
11
+ - Filters logs by level (log, warn, error, info, debug)
12
+ - Circular buffer stores last 1000 log entries and 500 network requests
13
+ - **Execute JavaScript** directly in the running app (REPL-style)
14
+ - **Inspect global objects** like Apollo Client, Redux store, Expo Router
15
+ - **Discover debug globals** available in the app
16
+
17
+ ## Requirements
18
+
19
+ - Node.js 18+
20
+ - React Native app running with Metro bundler
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install -g react-native-ai-debugger
26
+ ```
27
+
28
+ Or install locally in your project:
29
+
30
+ ```bash
31
+ npm install --save-dev react-native-ai-debugger
32
+ ```
33
+
34
+ ## Claude Code Setup
35
+
36
+ ### Global (all projects)
37
+
38
+ ```bash
39
+ claude mcp add rn-debugger -- npx react-native-ai-debugger --scope user
40
+ ```
41
+
42
+ ### Project-specific
43
+
44
+ ```bash
45
+ claude mcp add rn-debugger -- npx react-native-ai-debugger --scope project
46
+ ```
47
+
48
+ ### Manual Configuration
49
+
50
+ Add to `~/.claude.json` (user scope) or `.mcp.json` (project scope):
51
+
52
+ ```json
53
+ {
54
+ "mcpServers": {
55
+ "rn-debugger": {
56
+ "type": "stdio",
57
+ "command": "npx",
58
+ "args": ["react-native-ai-debugger"]
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ Restart Claude Code after adding the configuration.
65
+
66
+ ## Available Tools
67
+
68
+ ### Connection & Logs
69
+
70
+ | Tool | Description |
71
+ |------|-------------|
72
+ | `scan_metro` | Scan for running Metro servers and auto-connect |
73
+ | `connect_metro` | Connect to a specific Metro port |
74
+ | `get_apps` | List connected React Native apps |
75
+ | `get_logs` | Retrieve console logs (with optional filtering and start position) |
76
+ | `search_logs` | Search logs for specific text (case-insensitive) |
77
+ | `clear_logs` | Clear the log buffer |
78
+
79
+ ### Network Tracking
80
+
81
+ | Tool | Description |
82
+ |------|-------------|
83
+ | `get_network_requests` | Retrieve captured network requests with optional filtering |
84
+ | `search_network` | Search requests by URL pattern (case-insensitive) |
85
+ | `get_request_details` | Get full details of a request (headers, body, timing) |
86
+ | `get_network_stats` | Get statistics: counts by method, status code, domain |
87
+ | `clear_network` | Clear the network request buffer |
88
+
89
+ ### App Inspection & Execution
90
+
91
+ | Tool | Description |
92
+ |------|-------------|
93
+ | `execute_in_app` | Execute JavaScript code in the connected app and return the result |
94
+ | `list_debug_globals` | Discover available debug objects (Apollo, Redux, Expo Router, etc.) |
95
+ | `inspect_global` | Inspect a global object to see its properties and callable methods |
96
+ | `reload_app` | Reload the app (like pressing 'r' in Metro or shaking the device) |
97
+
98
+ ## Usage
99
+
100
+ 1. Start your React Native app:
101
+ ```bash
102
+ npm start
103
+ # or
104
+ expo start
105
+ ```
106
+
107
+ 2. In Claude Code, scan for Metro:
108
+ ```
109
+ Use scan_metro to find and connect to Metro
110
+ ```
111
+
112
+ 3. Get logs:
113
+ ```
114
+ Use get_logs to see recent console output
115
+ ```
116
+
117
+ ### Filtering Logs
118
+
119
+ ```
120
+ get_logs with maxLogs=20 and level="error"
121
+ ```
122
+
123
+ Available levels: `all`, `log`, `warn`, `error`, `info`, `debug`
124
+
125
+ ### Start from Specific Line
126
+
127
+ ```
128
+ get_logs with startFromText="iOS Bundled" and maxLogs=100
129
+ ```
130
+
131
+ This finds the **last** (most recent) line containing the text and returns logs from that point forward. Useful for getting logs since the last app reload.
132
+
133
+ ### Search Logs
134
+
135
+ ```
136
+ search_logs with text="error" and maxResults=20
137
+ ```
138
+
139
+ Case-insensitive search across all log messages.
140
+
141
+ ## Network Tracking
142
+
143
+ ### View Recent Requests
144
+
145
+ ```
146
+ get_network_requests with maxRequests=20
147
+ ```
148
+
149
+ ### Filter by Method
150
+
151
+ ```
152
+ get_network_requests with method="POST"
153
+ ```
154
+
155
+ ### Filter by Status Code
156
+
157
+ Useful for debugging auth issues:
158
+
159
+ ```
160
+ get_network_requests with status=401
161
+ ```
162
+
163
+ ### Search by URL
164
+
165
+ ```
166
+ search_network with urlPattern="api/auth"
167
+ ```
168
+
169
+ ### Get Full Request Details
170
+
171
+ After finding a request ID from `get_network_requests`:
172
+
173
+ ```
174
+ get_request_details with requestId="123.45"
175
+ ```
176
+
177
+ Shows full headers, request body, response headers, and timing.
178
+
179
+ ### View Statistics
180
+
181
+ ```
182
+ get_network_stats
183
+ ```
184
+
185
+ Example output:
186
+ ```
187
+ Total requests: 47
188
+ Completed: 45
189
+ Errors: 2
190
+ Avg duration: 234ms
191
+
192
+ By Method:
193
+ GET: 32
194
+ POST: 15
195
+
196
+ By Status:
197
+ 2xx: 43
198
+ 4xx: 2
199
+
200
+ By Domain:
201
+ api.example.com: 40
202
+ cdn.example.com: 7
203
+ ```
204
+
205
+ ## App Inspection
206
+
207
+ ### Discover Debug Globals
208
+
209
+ Find what debugging objects are available in your app:
210
+
211
+ ```
212
+ list_debug_globals
213
+ ```
214
+
215
+ Example output:
216
+ ```json
217
+ {
218
+ "Apollo Client": ["__APOLLO_CLIENT__"],
219
+ "Redux": ["__REDUX_STORE__"],
220
+ "Expo": ["__EXPO_ROUTER__"],
221
+ "Reanimated": ["__reanimatedModuleProxy"]
222
+ }
223
+ ```
224
+
225
+ ### Inspect an Object
226
+
227
+ Before calling methods on an unfamiliar object, inspect it to see what's callable:
228
+
229
+ ```
230
+ inspect_global with objectName="__EXPO_ROUTER__"
231
+ ```
232
+
233
+ Example output:
234
+ ```json
235
+ {
236
+ "navigate": { "type": "function", "callable": true },
237
+ "push": { "type": "function", "callable": true },
238
+ "currentPath": { "type": "string", "callable": false, "value": "/" },
239
+ "routes": { "type": "array", "callable": false }
240
+ }
241
+ ```
242
+
243
+ ### Execute Code in App
244
+
245
+ Run JavaScript directly in the connected app:
246
+
247
+ ```
248
+ execute_in_app with expression="__DEV__"
249
+ // Returns: true
250
+
251
+ execute_in_app with expression="__APOLLO_CLIENT__.cache.extract()"
252
+ // Returns: Full Apollo cache contents
253
+
254
+ execute_in_app with expression="__EXPO_ROUTER__.navigate('/settings')"
255
+ // Navigates the app to /settings
256
+ ```
257
+
258
+ ### Async Code
259
+
260
+ For async operations, promises are awaited by default:
261
+
262
+ ```
263
+ execute_in_app with expression="AsyncStorage.getItem('userToken')"
264
+ ```
265
+
266
+ Set `awaitPromise=false` for synchronous execution only.
267
+
268
+ ## Supported React Native Versions
269
+
270
+ | Version | Runtime | Status |
271
+ |---------|---------|--------|
272
+ | Expo SDK 54+ | React Native Bridgeless | ✓ |
273
+ | RN 0.70 - 0.76 | Hermes React Native | ✓ |
274
+ | RN < 0.70 | JSC | Not tested |
275
+
276
+ ## How It Works
277
+
278
+ 1. Fetches device list from Metro's `/json` endpoint
279
+ 2. Connects to the main JS runtime via CDP (Chrome DevTools Protocol) WebSocket
280
+ 3. Enables `Runtime.enable` to receive `Runtime.consoleAPICalled` events
281
+ 4. Enables `Network.enable` to receive network request/response events
282
+ 5. Stores logs and network requests in circular buffers for retrieval
283
+
284
+ ## Troubleshooting
285
+
286
+ ### No devices found
287
+ - Make sure the app is running on a simulator/device
288
+ - Check that Metro bundler is running (`npm start`)
289
+
290
+ ### Wrong device connected
291
+ The server prioritizes devices in this order:
292
+ 1. React Native Bridgeless (SDK 54+)
293
+ 2. Hermes React Native
294
+ 3. Any React Native (excluding Reanimated/Experimental)
295
+
296
+ ### Logs not appearing
297
+ - Ensure the app is actively running (not just Metro)
298
+ - Try `clear_logs` then trigger some actions in the app
299
+ - Check `get_apps` to verify connection status
300
+
301
+ ## License
302
+
303
+ MIT
@@ -0,0 +1,108 @@
1
+ export interface AndroidDevice {
2
+ id: string;
3
+ status: "device" | "offline" | "unauthorized" | "no permissions" | string;
4
+ product?: string;
5
+ model?: string;
6
+ device?: string;
7
+ transportId?: string;
8
+ }
9
+ export interface AdbResult {
10
+ success: boolean;
11
+ result?: string;
12
+ error?: string;
13
+ data?: Buffer;
14
+ scaleFactor?: number;
15
+ originalWidth?: number;
16
+ originalHeight?: number;
17
+ }
18
+ /**
19
+ * Check if ADB is available in PATH
20
+ */
21
+ export declare function isAdbAvailable(): Promise<boolean>;
22
+ /**
23
+ * List connected Android devices
24
+ */
25
+ export declare function listAndroidDevices(): Promise<AdbResult>;
26
+ /**
27
+ * Get the first connected Android device ID
28
+ */
29
+ export declare function getDefaultAndroidDevice(): Promise<string | null>;
30
+ /**
31
+ * Take a screenshot from an Android device
32
+ */
33
+ export declare function androidScreenshot(outputPath?: string, deviceId?: string): Promise<AdbResult>;
34
+ /**
35
+ * Install an APK on an Android device
36
+ */
37
+ export declare function androidInstallApp(apkPath: string, deviceId?: string, options?: {
38
+ replace?: boolean;
39
+ grantPermissions?: boolean;
40
+ }): Promise<AdbResult>;
41
+ /**
42
+ * Launch an app on an Android device
43
+ */
44
+ export declare function androidLaunchApp(packageName: string, activityName?: string, deviceId?: string): Promise<AdbResult>;
45
+ /**
46
+ * Get list of installed packages on the device
47
+ */
48
+ export declare function androidListPackages(deviceId?: string, filter?: string): Promise<AdbResult>;
49
+ /**
50
+ * Common key event codes for Android
51
+ */
52
+ export declare const ANDROID_KEY_EVENTS: {
53
+ readonly HOME: 3;
54
+ readonly BACK: 4;
55
+ readonly CALL: 5;
56
+ readonly END_CALL: 6;
57
+ readonly VOLUME_UP: 24;
58
+ readonly VOLUME_DOWN: 25;
59
+ readonly POWER: 26;
60
+ readonly CAMERA: 27;
61
+ readonly CLEAR: 28;
62
+ readonly TAB: 61;
63
+ readonly ENTER: 66;
64
+ readonly DEL: 67;
65
+ readonly MENU: 82;
66
+ readonly SEARCH: 84;
67
+ readonly MEDIA_PLAY_PAUSE: 85;
68
+ readonly MEDIA_STOP: 86;
69
+ readonly MEDIA_NEXT: 87;
70
+ readonly MEDIA_PREVIOUS: 88;
71
+ readonly MOVE_HOME: 122;
72
+ readonly MOVE_END: 123;
73
+ readonly APP_SWITCH: 187;
74
+ readonly ESCAPE: 111;
75
+ };
76
+ /**
77
+ * Tap at coordinates on an Android device
78
+ */
79
+ export declare function androidTap(x: number, y: number, deviceId?: string): Promise<AdbResult>;
80
+ /**
81
+ * Long press at coordinates on an Android device
82
+ */
83
+ export declare function androidLongPress(x: number, y: number, durationMs?: number, deviceId?: string): Promise<AdbResult>;
84
+ /**
85
+ * Swipe on an Android device
86
+ */
87
+ export declare function androidSwipe(startX: number, startY: number, endX: number, endY: number, durationMs?: number, deviceId?: string): Promise<AdbResult>;
88
+ /**
89
+ * Input text on an Android device
90
+ *
91
+ * ADB input text has limitations with special characters.
92
+ * This function handles escaping properly for URLs, emails, and special strings.
93
+ */
94
+ export declare function androidInputText(text: string, deviceId?: string): Promise<AdbResult>;
95
+ /**
96
+ * Send a key event to an Android device
97
+ */
98
+ export declare function androidKeyEvent(keyCode: number | keyof typeof ANDROID_KEY_EVENTS, deviceId?: string): Promise<AdbResult>;
99
+ /**
100
+ * Get device screen size
101
+ */
102
+ export declare function androidGetScreenSize(deviceId?: string): Promise<{
103
+ success: boolean;
104
+ width?: number;
105
+ height?: number;
106
+ error?: string;
107
+ }>;
108
+ //# sourceMappingURL=android.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../src/core/android.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,cAAc,GAAG,gBAAgB,GAAG,MAAM,CAAC;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAGD,MAAM,WAAW,SAAS;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAOvD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,SAAS,CAAC,CA6D7D;AAED;;GAE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