@metamask/device-mcp 0.1.0 → 0.3.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 (156) hide show
  1. package/CHANGELOG.md +29 -14
  2. package/LICENSE +6 -0
  3. package/LICENSE.APACHE2 +201 -0
  4. package/LICENSE.MIT +21 -0
  5. package/README.md +114 -33
  6. package/dist/backends/adb-backend.cjs +21 -5
  7. package/dist/backends/adb-backend.cjs.map +1 -1
  8. package/dist/backends/adb-backend.d.cts +9 -2
  9. package/dist/backends/adb-backend.d.cts.map +1 -1
  10. package/dist/backends/adb-backend.d.mts +9 -2
  11. package/dist/backends/adb-backend.d.mts.map +1 -1
  12. package/dist/backends/adb-backend.mjs +21 -5
  13. package/dist/backends/adb-backend.mjs.map +1 -1
  14. package/dist/backends/appium-backend.cjs +25 -7
  15. package/dist/backends/appium-backend.cjs.map +1 -1
  16. package/dist/backends/appium-backend.d.cts +9 -2
  17. package/dist/backends/appium-backend.d.cts.map +1 -1
  18. package/dist/backends/appium-backend.d.mts +9 -2
  19. package/dist/backends/appium-backend.d.mts.map +1 -1
  20. package/dist/backends/appium-backend.mjs +25 -7
  21. package/dist/backends/appium-backend.mjs.map +1 -1
  22. package/dist/backends/idb-backend.cjs +96 -38
  23. package/dist/backends/idb-backend.cjs.map +1 -1
  24. package/dist/backends/idb-backend.d.cts +9 -2
  25. package/dist/backends/idb-backend.d.cts.map +1 -1
  26. package/dist/backends/idb-backend.d.mts +9 -2
  27. package/dist/backends/idb-backend.d.mts.map +1 -1
  28. package/dist/backends/idb-backend.mjs +97 -39
  29. package/dist/backends/idb-backend.mjs.map +1 -1
  30. package/dist/backends/index.cjs +37 -15
  31. package/dist/backends/index.cjs.map +1 -1
  32. package/dist/backends/index.d.cts +8 -11
  33. package/dist/backends/index.d.cts.map +1 -1
  34. package/dist/backends/index.d.mts +8 -11
  35. package/dist/backends/index.d.mts.map +1 -1
  36. package/dist/backends/index.mjs +38 -16
  37. package/dist/backends/index.mjs.map +1 -1
  38. package/dist/backends/types.cjs.map +1 -1
  39. package/dist/backends/types.d.cts +20 -1
  40. package/dist/backends/types.d.cts.map +1 -1
  41. package/dist/backends/types.d.mts +20 -1
  42. package/dist/backends/types.d.mts.map +1 -1
  43. package/dist/backends/types.mjs.map +1 -1
  44. package/dist/cli/device-mcp.cjs +11 -2
  45. package/dist/cli/device-mcp.cjs.map +1 -1
  46. package/dist/cli/device-mcp.mjs +11 -2
  47. package/dist/cli/device-mcp.mjs.map +1 -1
  48. package/dist/hermes/hermes-cdp.cjs +674 -0
  49. package/dist/hermes/hermes-cdp.cjs.map +1 -0
  50. package/dist/hermes/hermes-cdp.d.cts +248 -0
  51. package/dist/hermes/hermes-cdp.d.cts.map +1 -0
  52. package/dist/hermes/hermes-cdp.d.mts +248 -0
  53. package/dist/hermes/hermes-cdp.d.mts.map +1 -0
  54. package/dist/hermes/hermes-cdp.mjs +665 -0
  55. package/dist/hermes/hermes-cdp.mjs.map +1 -0
  56. package/dist/hermes/session.cjs +196 -0
  57. package/dist/hermes/session.cjs.map +1 -0
  58. package/dist/hermes/session.d.cts +163 -0
  59. package/dist/hermes/session.d.cts.map +1 -0
  60. package/dist/hermes/session.d.mts +163 -0
  61. package/dist/hermes/session.d.mts.map +1 -0
  62. package/dist/hermes/session.mjs +189 -0
  63. package/dist/hermes/session.mjs.map +1 -0
  64. package/dist/index.cjs +19 -1
  65. package/dist/index.cjs.map +1 -1
  66. package/dist/index.d.cts +8 -1
  67. package/dist/index.d.cts.map +1 -1
  68. package/dist/index.d.mts +8 -1
  69. package/dist/index.d.mts.map +1 -1
  70. package/dist/index.mjs +3 -0
  71. package/dist/index.mjs.map +1 -1
  72. package/dist/server.cjs +8 -0
  73. package/dist/server.cjs.map +1 -1
  74. package/dist/server.d.cts +2 -2
  75. package/dist/server.d.cts.map +1 -1
  76. package/dist/server.d.mts +2 -2
  77. package/dist/server.d.mts.map +1 -1
  78. package/dist/server.mjs +9 -1
  79. package/dist/server.mjs.map +1 -1
  80. package/dist/tools/get-element-text.cjs +46 -0
  81. package/dist/tools/get-element-text.cjs.map +1 -0
  82. package/dist/tools/get-element-text.d.cts +4 -0
  83. package/dist/tools/get-element-text.d.cts.map +1 -0
  84. package/dist/tools/get-element-text.d.mts +4 -0
  85. package/dist/tools/get-element-text.d.mts.map +1 -0
  86. package/dist/tools/get-element-text.mjs +43 -0
  87. package/dist/tools/get-element-text.mjs.map +1 -0
  88. package/dist/tools/hermes-cdp.cjs +102 -0
  89. package/dist/tools/hermes-cdp.cjs.map +1 -0
  90. package/dist/tools/hermes-cdp.d.cts +18 -0
  91. package/dist/tools/hermes-cdp.d.cts.map +1 -0
  92. package/dist/tools/hermes-cdp.d.mts +18 -0
  93. package/dist/tools/hermes-cdp.d.mts.map +1 -0
  94. package/dist/tools/hermes-cdp.mjs +99 -0
  95. package/dist/tools/hermes-cdp.mjs.map +1 -0
  96. package/dist/tools/hermes-targets.cjs +127 -0
  97. package/dist/tools/hermes-targets.cjs.map +1 -0
  98. package/dist/tools/hermes-targets.d.cts +20 -0
  99. package/dist/tools/hermes-targets.d.cts.map +1 -0
  100. package/dist/tools/hermes-targets.d.mts +20 -0
  101. package/dist/tools/hermes-targets.d.mts.map +1 -0
  102. package/dist/tools/hermes-targets.mjs +124 -0
  103. package/dist/tools/hermes-targets.mjs.map +1 -0
  104. package/dist/tools/index.cjs +11 -1
  105. package/dist/tools/index.cjs.map +1 -1
  106. package/dist/tools/index.d.cts +5 -0
  107. package/dist/tools/index.d.cts.map +1 -1
  108. package/dist/tools/index.d.mts +5 -0
  109. package/dist/tools/index.d.mts.map +1 -1
  110. package/dist/tools/index.mjs +5 -0
  111. package/dist/tools/index.mjs.map +1 -1
  112. package/dist/tools/list-devices.cjs +36 -0
  113. package/dist/tools/list-devices.cjs.map +1 -0
  114. package/dist/tools/list-devices.d.cts +4 -0
  115. package/dist/tools/list-devices.d.cts.map +1 -0
  116. package/dist/tools/list-devices.d.mts +4 -0
  117. package/dist/tools/list-devices.d.mts.map +1 -0
  118. package/dist/tools/list-devices.mjs +33 -0
  119. package/dist/tools/list-devices.mjs.map +1 -0
  120. package/dist/tools/screenshot.cjs +8 -3
  121. package/dist/tools/screenshot.cjs.map +1 -1
  122. package/dist/tools/screenshot.d.cts.map +1 -1
  123. package/dist/tools/screenshot.d.mts.map +1 -1
  124. package/dist/tools/screenshot.mjs +8 -3
  125. package/dist/tools/screenshot.mjs.map +1 -1
  126. package/dist/tools/select-device.cjs +38 -0
  127. package/dist/tools/select-device.cjs.map +1 -0
  128. package/dist/tools/select-device.d.cts +4 -0
  129. package/dist/tools/select-device.d.cts.map +1 -0
  130. package/dist/tools/select-device.d.mts +4 -0
  131. package/dist/tools/select-device.d.mts.map +1 -0
  132. package/dist/tools/select-device.mjs +35 -0
  133. package/dist/tools/select-device.mjs.map +1 -0
  134. package/dist/utils/exec.cjs +11 -9
  135. package/dist/utils/exec.cjs.map +1 -1
  136. package/dist/utils/exec.d.cts.map +1 -1
  137. package/dist/utils/exec.d.mts.map +1 -1
  138. package/dist/utils/exec.mjs +11 -9
  139. package/dist/utils/exec.mjs.map +1 -1
  140. package/dist/utils/output-path.cjs +128 -0
  141. package/dist/utils/output-path.cjs.map +1 -0
  142. package/dist/utils/output-path.d.cts +41 -0
  143. package/dist/utils/output-path.d.cts.map +1 -0
  144. package/dist/utils/output-path.d.mts +41 -0
  145. package/dist/utils/output-path.d.mts.map +1 -0
  146. package/dist/utils/output-path.mjs +123 -0
  147. package/dist/utils/output-path.mjs.map +1 -0
  148. package/dist/utils/platform.cjs +121 -36
  149. package/dist/utils/platform.cjs.map +1 -1
  150. package/dist/utils/platform.d.cts +14 -3
  151. package/dist/utils/platform.d.cts.map +1 -1
  152. package/dist/utils/platform.d.mts +14 -3
  153. package/dist/utils/platform.d.mts.map +1 -1
  154. package/dist/utils/platform.mjs +117 -36
  155. package/dist/utils/platform.mjs.map +1 -1
  156. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0]
11
+
12
+ ### Added
13
+
14
+ - Add Hermes CDP tools (`hermes_cdp`, `hermes_targets`) for inspecting the React Native Hermes JS runtime via Metro ([#14](https://github.com/MetaMask/device-mcp/pull/14))
15
+
16
+ ### Changed
17
+
18
+ - Make screenshot base64 encoding optional — `DeviceBackend.screenshot(outputPath, { encode })` accepts `{ encode: false }` to return only the file `path` and skip base64 encoding. `ScreenshotResult.data` is now optional; the default (`encode: true`) preserves existing behavior ([#15](https://github.com/MetaMask/device-mcp/pull/15))
19
+ - The Appium backend now saves the screenshot to `outputPath` when one is provided (previously the argument was ignored) ([#15](https://github.com/MetaMask/device-mcp/pull/15))
20
+
21
+ ### Fixed
22
+
23
+ - Fix `device_screenshot` failing on macOS — the captured PNG is now read in-process via `fs.readFile(path, 'base64')` instead of shelling out to the `base64` CLI, which is not portable (BSD `base64` on macOS rejects the GNU positional-file syntax that was used previously) ([#15](https://github.com/MetaMask/device-mcp/pull/15))
24
+
25
+ ### Security
26
+
27
+ - Harden screenshot and screen-recording file writes across the ADB, IDB, and Appium backends — default captures now use a private per-process temporary directory (`0700`) with unpredictable names instead of the predictable `/tmp/device-mcp-*-<timestamp>` paths, files are written owner-only (`0600`), and a symlink at the destination is never followed. Caller-supplied output paths can be confined to a single directory via the new `DEVICE_MCP_OUTPUT_DIR` environment variable
28
+
29
+ ## [0.2.0]
30
+
31
+ ### Added
32
+
33
+ - Add get element text and mapping to all backends ([#9](https://github.com/MetaMask/device-mcp/pull/9))
34
+ - Add device selection tools ([#7](https://github.com/MetaMask/device-mcp/pull/7))
35
+
10
36
  ## [0.1.0]
11
37
 
12
38
  ### Added
@@ -16,19 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16
42
  - Three backends: iOS (IDB), Android (ADB), Appium/BrowserStack (W3C WebDriver)
17
43
  - `.device-session` file for attaching to existing Appium sessions or creating new ones
18
44
  - 16 MCP tools: `device_snapshot`, `device_screenshot`, `device_info`, `device_tap_element`, `device_tap_coordinates`, `device_type`, `device_swipe`, `device_long_press`, `device_wait_for`, `device_app_state`, `device_open_app`, `device_close_app`, `device_press_button`, `device_dismiss_keyboard`, `device_dismiss_alert`, `device_logs`
19
- - Fuzzy element matching (case-insensitive, partial text)
20
- - Android tree-structured UI hierarchy parser (nested, not flat)
21
- - iOS `snapshotMaxDepth` and `mobile: source` fallback for deep hierarchies
22
- - Auto-detection of platform from `.device-session`, `DEVICE_ID`, or booted simulator/emulator
23
- - Runtime health check with actionable error messages for missing IDB/ADB
24
- - SKILL.md agent reference with core loop, common patterns, and platform differences
25
- - MetaMask module template compliance (ts-bridge, dual CJS/ESM, yarn constraints, CI workflows)
26
-
27
- ### Fixed
28
-
29
- - fix: GH workflow release creation
30
- - chore: add additional tools
31
- - chore: add MetaMask Security Code Scanner workflow
32
45
 
33
- [Unreleased]: https://github.com/MetaMask/device-mcp/compare/v0.1.0...HEAD
46
+ [Unreleased]: https://github.com/MetaMask/device-mcp/compare/v0.3.0...HEAD
47
+ [0.3.0]: https://github.com/MetaMask/device-mcp/compare/v0.2.0...v0.3.0
48
+ [0.2.0]: https://github.com/MetaMask/device-mcp/compare/v0.1.0...v0.2.0
34
49
  [0.1.0]: https://github.com/MetaMask/device-mcp/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,6 @@
1
+ This project is licensed under either of
2
+
3
+ - MIT license ([LICENSE.MIT](LICENSE.MIT))
4
+ - Apache License, Version 2.0 ([LICENSE.APACHE2](LICENSE.APACHE2))
5
+
6
+ at your option.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 MetaMask
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/LICENSE.MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MetaMask
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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @metamask/device-mcp
2
2
 
3
- MCP server for mobile device interaction — iOS (IDB), Android (ADB), and remote devices (Appium/BrowserStack).
3
+ MCP server for mobile device interaction — iOS (simctl + IDB), Android (ADB), and remote devices (Appium/BrowserStack).
4
4
 
5
5
  Provides device interaction tools for LLM agents to inspect UI state, interact with elements, capture evidence, and control app lifecycle. Works standalone for debugging or as part of the [self-healing test infrastructure](https://github.com/MetaMask/metamask-mobile) for MetaMask Mobile.
6
6
 
@@ -15,9 +15,10 @@ Provides device interaction tools for LLM agents to inspect UI state, interact w
15
15
  ## Requirements
16
16
 
17
17
  - **Node.js** `^20 || ^22 || >=24`
18
- - **iOS local**: [IDB](https://fbidb.io/) (`brew tap facebook/fb && brew install idb-companion && pip3 install fb-idb`)
19
- - **Android local**: ADB (Android SDK platform-tools)
18
+ - **iOS local**: Xcode Command Line Tools (for `xcrun simctl`) + [IDB](https://fbidb.io/) for UI interaction (`brew tap facebook/fb && brew install idb-companion && pip3 install fb-idb`)
19
+ - **Android local**: ADB (Android SDK platform-tools) — auto-discovered from `$ANDROID_HOME`, `$ANDROID_SDK_ROOT`, or `~/Library/Android/sdk`
20
20
  - **Remote/BrowserStack**: No local tools needed — connects via Appium W3C WebDriver HTTP
21
+ - **Hermes CDP** (debugging the React Native JS runtime): uses the global `WebSocket` API. Node 22+ works out of the box; **Node 20 requires launching with `NODE_OPTIONS="--experimental-websocket"`**.
21
22
 
22
23
  ## Installation
23
24
 
@@ -41,6 +42,10 @@ device-mcp
41
42
 
42
43
  # Target a specific device
43
44
  DEVICE_ID=<udid-or-serial> device-mcp
45
+
46
+ # Target a specific platform (useful in CI with one device per platform)
47
+ DEVICE_PLATFORM=ios device-mcp
48
+ DEVICE_PLATFORM=android device-mcp
44
49
  ```
45
50
 
46
51
  ### Backend Selection
@@ -48,8 +53,21 @@ DEVICE_ID=<udid-or-serial> device-mcp
48
53
  The server selects a backend in this order:
49
54
 
50
55
  1. **`.device-session` file** — if present in the working directory, connects via Appium (local or BrowserStack)
51
- 2. **`DEVICE_ID` env var**format determines platform (UUID = iOS, serial = Android)
52
- 3. **Auto-detect**checks for booted iOS simulator (IDB), then connected Android device (ADB)
56
+ 2. **`DEVICE_ID` + `DEVICE_PLATFORM`**direct connect, no auto-detection
57
+ 3. **`DEVICE_ID` only** — platform inferred from format (UUID = iOS, serial/emulator-\* = Android)
58
+ 4. **`DEVICE_PLATFORM` only** — auto-detect first device of that platform
59
+ 5. **Nothing set, 1 device** — auto-connect
60
+ 6. **Nothing set, multiple devices** — returns device list, agent asks user to pick via `device_select_device`
61
+
62
+ ### Multi-Device Selection
63
+
64
+ When multiple devices are connected and no `DEVICE_ID` is set, the server enters an "awaiting selection" state. Any tool call returns the list of available devices. Use `device_list_devices` to enumerate them and `device_select_device` to choose one.
65
+
66
+ ### Device Discovery
67
+
68
+ - **iOS simulators** are discovered via `xcrun simctl list devices booted --json` — no IDB needed for discovery
69
+ - **Android devices** are discovered via `adb devices` — the server probes `$ANDROID_HOME/platform-tools/adb`, `$ANDROID_SDK_ROOT/platform-tools/adb`, and `~/Library/Android/sdk/platform-tools/adb` when `adb` is not on `$PATH`
70
+ - **IDB** is resolved from `$PATH`, `/usr/local/bin`, `/opt/homebrew/bin`, and `~/Library/Python/*/bin` (pip user installs)
53
71
 
54
72
  ### BrowserStack / Appium
55
73
 
@@ -102,6 +120,13 @@ The `.device-session` file is typically written by the test runner when it creat
102
120
 
103
121
  ## Tools
104
122
 
123
+ ### Device Management
124
+
125
+ | Tool | Description |
126
+ | ---------------------- | ------------------------------------------------------------------ |
127
+ | `device_list_devices` | List all connected devices and simulators/emulators. |
128
+ | `device_select_device` | Select a device for this session. Use after `device_list_devices`. |
129
+
105
130
  ### Inspection
106
131
 
107
132
  | Tool | Description |
@@ -133,6 +158,13 @@ The `.device-session` file is typically written by the test runner when it creat
133
158
  | `device_dismiss_keyboard` | Hide the on-screen keyboard after typing. |
134
159
  | `device_dismiss_alert` | Accept or dismiss a system alert or permission dialog. |
135
160
 
161
+ ### Hermes CDP
162
+
163
+ | Tool | Description |
164
+ | ---------------- | ------------------------------------------------------------------------- |
165
+ | `hermes_cdp` | Speak raw Chrome DevTools Protocol to the React Native Hermes JS runtime. |
166
+ | `hermes_targets` | List and diagnose the debuggable Hermes targets exposed by Metro. |
167
+
136
168
  ### Element Identification
137
169
 
138
170
  Elements are identified by accessibility attributes — not internal refs. Matching is **fuzzy**: partial text and case-insensitive matches work. For example, querying `{ label: "Confirm" }` matches an element with label `"Confirm Transaction"`.
@@ -142,24 +174,71 @@ Elements are identified by accessibility attributes — not internal refs. Match
142
174
 
143
175
  ### Backend Implementation
144
176
 
145
- | Tool | iOS (IDB) | Android (ADB) | Appium (W3C WebDriver) |
146
- | ------------------------- | ----------------------- | -------------------- | ----------------------------- |
147
- | `device_snapshot` | `idb ui describe-all` | `uiautomator dump` | `mobile: source` |
148
- | `device_screenshot` | `idb screenshot` | `screencap` + `pull` | `mobile: getScreenshot` |
149
- | `device_info` | `idb describe` | `getprop` | session capabilities |
150
- | `device_tap_element` | find + `idb ui tap` | find + `input tap` | find + W3C Actions |
151
- | `device_tap_coordinates` | `idb ui tap x y` | `input tap x y` | W3C Actions |
152
- | `device_type` | `idb ui text` | `input text` | `findElement` + `sendKeys` |
153
- | `device_swipe` | `idb ui swipe` | `input swipe` | W3C Actions |
154
- | `device_long_press` | `idb ui tap --duration` | `input swipe` (hold) | W3C Actions (pause) |
155
- | `device_wait_for` | poll snapshot | poll snapshot | poll snapshot |
156
- | `device_app_state` | `idb list-apps` | `dumpsys activity` | `mobile: queryAppState` |
157
- | `device_open_app` | `idb launch` | `monkey -p` | `mobile: activateApp` |
158
- | `device_close_app` | `idb terminate` | `am force-stop` | `mobile: terminateApp` |
159
- | `device_press_button` | `idb ui key` | `input keyevent` | `mobile: pressButton/Key` |
160
- | `device_dismiss_keyboard` | `idb ui key RETURN` | `input keyevent 111` | `mobile: hideKeyboard` |
161
- | `device_dismiss_alert` | find button + tap | find button + tap | `mobile: accept/dismissAlert` |
162
- | `device_logs` | `idb log` | `logcat` | `mobile: getLog` |
177
+ | Tool | iOS (IDB) | Android (ADB) | Appium (W3C WebDriver) |
178
+ | ------------------------- | ------------------------------------ | -------------------- | ----------------------------- |
179
+ | `device_snapshot` | `idb ui describe-all` | `uiautomator dump` | `mobile: source` |
180
+ | `device_screenshot` | `idb screenshot` | `screencap` + `pull` | `mobile: getScreenshot` |
181
+ | `device_info` | `idb describe` | `getprop` | session capabilities |
182
+ | `device_tap_element` | find + `idb ui tap` | find + `input tap` | find + W3C Actions |
183
+ | `device_tap_coordinates` | `idb ui tap x y` | `input tap x y` | W3C Actions |
184
+ | `device_type` | `idb ui text` | `input text` | `findElement` + `sendKeys` |
185
+ | `device_swipe` | `idb ui swipe` | `input swipe` | W3C Actions |
186
+ | `device_long_press` | `idb ui tap --duration` | `input swipe` (hold) | W3C Actions (pause) |
187
+ | `device_wait_for` | poll snapshot | poll snapshot | poll snapshot |
188
+ | `device_list_devices` | `xcrun simctl list` | `adb devices` | N/A |
189
+ | `device_select_device` | select by UDID | select by serial | N/A |
190
+ | `device_app_state` | `idb list-apps` / `simctl listapps` | `dumpsys activity` | `mobile: queryAppState` |
191
+ | `device_open_app` | `idb launch` / `simctl launch` | `monkey -p` | `mobile: activateApp` |
192
+ | `device_close_app` | `idb terminate` / `simctl terminate` | `am force-stop` | `mobile: terminateApp` |
193
+ | `device_press_button` | `idb ui key` | `input keyevent` | `mobile: pressButton/Key` |
194
+ | `device_dismiss_keyboard` | `idb ui key RETURN` | `input keyevent 111` | `mobile: hideKeyboard` |
195
+ | `device_dismiss_alert` | find button + tap | find button + tap | `mobile: accept/dismissAlert` |
196
+ | `device_logs` | `idb log` | `logcat` | `mobile: getLog` |
197
+
198
+ ## Hermes CDP
199
+
200
+ Beyond native UI automation (idb/adb), the server can speak [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) (CDP) directly to the **React Native Hermes** JS runtime of a running app via Metro's inspector proxy. This lets an agent evaluate JavaScript, inspect runtime state, and diagnose the app's JS layer — complementing the native tools. Works on **both iOS and Android** (the transport is identical HTTP/WebSocket to Metro; only the default `appId` differs).
201
+
202
+ This is _React Native Hermes CDP via Metro's inspector proxy_ — not WebView/browser CDP, and not the iOS WebKit Inspector Protocol. The app's Hermes runtime connects out to Metro; Metro exposes debuggable targets over `http://localhost:<metroPort>/json` and a per-target `webSocketDebuggerUrl`, and the server speaks real CDP over that WebSocket.
203
+
204
+ ### Prerequisites
205
+
206
+ - A **DEBUG build with Metro running** on the inspector port. Release builds expose no inspector (`/json` returns `[]`).
207
+ - The global `WebSocket` API: **Node 22+ works out of the box**; **Node 20 requires launching with `NODE_OPTIONS="--experimental-websocket"`** (see [Requirements](#requirements)).
208
+
209
+ ### Tools
210
+
211
+ | Tool | Description |
212
+ | ---------------- | ------------------------------------------------------------------------- |
213
+ | `hermes_cdp` | Speak raw Chrome DevTools Protocol to the React Native Hermes JS runtime. |
214
+ | `hermes_targets` | List and diagnose the debuggable Hermes targets exposed by Metro. |
215
+
216
+ Example `hermes_cdp` call: method `Runtime.evaluate` with params `{"expression":"1+1","returnByValue":true}` — the raw response nests the value at `result.result.value`.
217
+
218
+ ### Safety model
219
+
220
+ A single Metro can have multiple apps/simulators registered, so executing CDP against the wrong target could run code in the wrong workspace. The server applies five fail-closed checks before executing:
221
+
222
+ 1. **Strict `appId` match** — only targets whose `appId` equals the expected id (no substring, no `targets[0]` fallback).
223
+ 2. **`HermesInternal` identity probe** — evaluates `HermesInternal.getRuntimeProperties()` before the user's method; non-Hermes targets fail closed.
224
+ 3. **Device pin** — pins `reactNative.logicalDeviceId` on first success; later calls are filtered to the pin.
225
+ 4. **Multi-device fail-closed** — multiple distinct logical devices (or any missing the field) fail closed rather than guess.
226
+ 5. **WebSocket URL validation** — protocol must be `ws:`, hostname must be loopback, and port must equal the resolved Metro port.
227
+
228
+ The synthetic legacy page (`React Native Experimental (Improved Chrome Reloads)`) is filtered out, and destructive methods `Runtime.terminateExecution` and `Inspector.detached` are blocked.
229
+
230
+ ### Configuration
231
+
232
+ - **appId** defaults to `io.metamask.MetaMask` (iOS) / `io.metamask` (Android). Override globally via the `HERMES_APP_ID` env var or per-call via the tool's `appId` param. Android users not on the default must pass `appId` or set `HERMES_APP_ID`; `hermes_targets` with `all: true` aids discovery of the real appId.
233
+ - **Metro port** defaults to `8081`. Override via the `HERMES_METRO_PORT` env var or per-call via the tool's `metroPort` param.
234
+
235
+ ## File Output & Safety
236
+
237
+ `device_screenshot` and `device_screen_recording` write image/video files to disk. These artifacts can contain sensitive on-screen content (seed phrases, private keys, balances), so writes are hardened:
238
+
239
+ - **No `outputPath`** — the file is written into a private, per-process temporary directory (`0700`) with an unpredictable name, rather than a predictable `/tmp/device-mcp-*-<timestamp>` path (which is exposed to symlink and information-disclosure attacks on shared hosts).
240
+ - **With `outputPath`** — the path is resolved to an absolute path and written owner-only (`0600`); a symlink already present at the destination is never followed.
241
+ - **`DEVICE_MCP_OUTPUT_DIR`** — set this to confine every caller-supplied `outputPath` to a single directory. Any path resolving outside it is rejected. Leave it unset to allow writing to any path the server process can access.
163
242
 
164
243
  ## MCP Client Configuration
165
244
 
@@ -172,15 +251,14 @@ Add to `~/.config/opencode/opencode.json`:
172
251
  "mcp": {
173
252
  "device": {
174
253
  "type": "local",
175
- "command": ["node", "/path/to/metamask-device-mcp/dist/index.js"],
176
- "environment": {
177
- "PATH": "/path/to/idb/bin:/usr/local/bin:/usr/bin:/bin"
178
- }
254
+ "command": ["npx", "-y", "@metamask/device-mcp"]
179
255
  }
180
256
  }
181
257
  }
182
258
  ```
183
259
 
260
+ IDB and ADB are auto-discovered from standard install locations. No `PATH` override needed unless tools are installed in custom directories.
261
+
184
262
  ### Cursor
185
263
 
186
264
  Add to `.cursor/mcp.json` in your project root:
@@ -235,19 +313,22 @@ Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
235
313
  @metamask/device-mcp
236
314
  ├── src/
237
315
  │ ├── index.ts # Entry point — lazy backend, stdio MCP server
238
- │ ├── server.ts # MCP server — registers 16 tools
316
+ │ ├── server.ts # MCP server — registers 28 tools
239
317
  │ ├── backends/
240
- │ │ ├── types.ts # DeviceBackend interface (16 operations)
241
- │ │ ├── idb-backend.ts # iOS local — IDB commands + JSON parser
318
+ │ │ ├── types.ts # DeviceBackend interface
319
+ │ │ ├── idb-backend.ts # iOS local — IDB commands + simctl fallback
242
320
  │ │ ├── adb-backend.ts # Android local — ADB commands + XML parser
243
321
  │ │ ├── appium-backend.ts # Remote — Appium/BrowserStack via W3C WebDriver
244
322
  │ │ ├── webdriver-client.ts # Minimal W3C WebDriver HTTP client (fetch)
245
323
  │ │ ├── session-file.ts # .device-session file reader
246
324
  │ │ └── index.ts # createBackend() + createLazyBackend() factory
247
- │ ├── tools/ # One file per MCP tool (16 tools)
325
+ │ ├── tools/ # One file per MCP tool (28 tools)
326
+ │ │ ├── list-devices.ts # device_list_devices — enumerate connected devices
327
+ │ │ ├── select-device.ts # device_select_device — choose device for session
328
+ │ │ └── ... # snapshot, tap, type, swipe, etc.
248
329
  │ └── utils/
249
330
  │ ├── exec.ts # Shell execution wrapper
250
- │ ├── platform.ts # Platform auto-detection
331
+ │ ├── platform.ts # Device discovery (simctl, adb), path resolution
251
332
  │ └── element.ts # Element search, matching, formatting
252
333
  ```
253
334
 
@@ -255,7 +336,7 @@ Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
255
336
 
256
337
  ```bash
257
338
  yarn build # Compile TypeScript
258
- yarn test # Run tests (69 tests)
339
+ yarn test # Run tests
259
340
  yarn lint # Lint everything (ESLint + Prettier + changelog)
260
341
  yarn lint:fix # Auto-fix lint issues
261
342
  yarn dev # Watch mode compilation
@@ -16,9 +16,11 @@ exports.AdbBackend = void 0;
16
16
  exports.parseAndroidHierarchy = parseAndroidHierarchy;
17
17
  exports.parseNodeAttributes = parseNodeAttributes;
18
18
  const node_child_process_1 = require("node:child_process");
19
+ const promises_1 = require("node:fs/promises");
19
20
  const alert_labels_js_1 = require("../utils/alert-labels.cjs");
20
21
  const element_js_1 = require("../utils/element.cjs");
21
22
  const exec_js_1 = require("../utils/exec.cjs");
23
+ const output_path_js_1 = require("../utils/output-path.cjs");
22
24
  class AdbBackend {
23
25
  constructor(serial) {
24
26
  _AdbBackend_instances.add(this);
@@ -79,6 +81,15 @@ class AdbBackend {
79
81
  targetDescription: (0, element_js_1.describeElement)(element),
80
82
  };
81
83
  }
84
+ async getElementText(query) {
85
+ const snapshot = await this.snapshot();
86
+ const element = (0, element_js_1.findElement)(snapshot.hierarchy, query);
87
+ if (!element) {
88
+ throw new Error(`Element not found: ${JSON.stringify(query)}\n` +
89
+ 'Use device_snapshot to inspect the current UI hierarchy.');
90
+ }
91
+ return element.label ?? element.value ?? '';
92
+ }
82
93
  async tapCoordinates(x, y) {
83
94
  await __classPrivateFieldGet(this, _AdbBackend_instances, "m", _AdbBackend_adb).call(this, ['shell', 'input', 'tap', String(x), String(y)]);
84
95
  }
@@ -149,8 +160,8 @@ class AdbBackend {
149
160
  }
150
161
  return { bundleId, state: 'Not Installed' };
151
162
  }
152
- async screenshot(outputPath) {
153
- const localPath = outputPath ?? `/tmp/device-mcp-screenshot-${Date.now()}.png`;
163
+ async screenshot(outputPath, options) {
164
+ const localPath = (0, output_path_js_1.resolveArtifactPath)(outputPath, 'screenshot');
154
165
  await __classPrivateFieldGet(this, _AdbBackend_instances, "m", _AdbBackend_adb).call(this, ['shell', 'screencap', '-p', '/sdcard/screenshot.png']);
155
166
  await (0, exec_js_1.execStrict)('adb', [
156
167
  '-s',
@@ -160,8 +171,12 @@ class AdbBackend {
160
171
  localPath,
161
172
  ]);
162
173
  await __classPrivateFieldGet(this, _AdbBackend_instances, "m", _AdbBackend_adb).call(this, ['shell', 'rm', '-f', '/sdcard/screenshot.png']);
163
- const data = await (0, exec_js_1.execStrict)('base64', [localPath]);
164
- return { data: data.trim(), format: 'png', path: localPath };
174
+ (0, output_path_js_1.hardenArtifactFile)(localPath);
175
+ if (options?.encode === false) {
176
+ return { data: undefined, format: 'png', path: localPath };
177
+ }
178
+ const data = await (0, promises_1.readFile)(localPath, 'base64');
179
+ return { data, format: 'png', path: localPath };
165
180
  }
166
181
  async openApp(bundleId) {
167
182
  await __classPrivateFieldGet(this, _AdbBackend_instances, "m", _AdbBackend_adb).call(this, [
@@ -311,7 +326,7 @@ class AdbBackend {
311
326
  if (__classPrivateFieldGet(this, _AdbBackend_recordingProcess, "f")) {
312
327
  throw new Error('Screen recording is already in progress');
313
328
  }
314
- __classPrivateFieldSet(this, _AdbBackend_recordingPath, outputPath ?? `/tmp/device-mcp-recording-${Date.now()}.mp4`, "f");
329
+ __classPrivateFieldSet(this, _AdbBackend_recordingPath, (0, output_path_js_1.resolveArtifactPath)(outputPath, 'recording'), "f");
315
330
  __classPrivateFieldSet(this, _AdbBackend_recordingProcess, (0, node_child_process_1.spawn)('adb', [
316
331
  '-s',
317
332
  __classPrivateFieldGet(this, _AdbBackend_serial, "f"),
@@ -341,6 +356,7 @@ class AdbBackend {
341
356
  localPath,
342
357
  ]);
343
358
  await __classPrivateFieldGet(this, _AdbBackend_instances, "m", _AdbBackend_adb).call(this, ['shell', 'rm', '-f', __classPrivateFieldGet(this, _AdbBackend_recordingRemotePath, "f")]);
359
+ (0, output_path_js_1.hardenArtifactFile)(localPath);
344
360
  return localPath;
345
361
  }
346
362
  }