@creatoria/miniapp-mcp 0.1.3 → 0.2.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 (246) hide show
  1. package/README.md +14 -3
  2. package/dist/app/cli/index.d.ts +6 -0
  3. package/dist/app/cli/index.d.ts.map +1 -0
  4. package/dist/app/cli/index.js +6 -0
  5. package/dist/app/cli/index.js.map +1 -0
  6. package/dist/app/index.d.ts +6 -0
  7. package/dist/app/index.d.ts.map +1 -0
  8. package/dist/app/index.js +6 -0
  9. package/dist/app/index.js.map +1 -0
  10. package/dist/app/server/index.d.ts +7 -0
  11. package/dist/app/server/index.d.ts.map +1 -0
  12. package/dist/app/server/index.js +6 -0
  13. package/dist/app/server/index.js.map +1 -0
  14. package/dist/capabilities/assert/index.d.ts +5 -0
  15. package/dist/capabilities/assert/index.d.ts.map +1 -0
  16. package/dist/capabilities/assert/index.js +5 -0
  17. package/dist/capabilities/assert/index.js.map +1 -0
  18. package/dist/capabilities/automator/index.d.ts +6 -0
  19. package/dist/capabilities/automator/index.d.ts.map +1 -0
  20. package/dist/capabilities/automator/index.js +6 -0
  21. package/dist/capabilities/automator/index.js.map +1 -0
  22. package/dist/capabilities/automator/schemas/close.d.ts +5 -0
  23. package/dist/capabilities/automator/schemas/close.d.ts.map +1 -0
  24. package/dist/capabilities/automator/schemas/close.js +11 -0
  25. package/dist/capabilities/automator/schemas/close.js.map +1 -0
  26. package/dist/capabilities/automator/schemas/connect.d.ts +11 -0
  27. package/dist/capabilities/automator/schemas/connect.d.ts.map +1 -0
  28. package/dist/capabilities/automator/schemas/connect.js +19 -0
  29. package/dist/capabilities/automator/schemas/connect.js.map +1 -0
  30. package/dist/capabilities/automator/schemas/disconnect.d.ts +5 -0
  31. package/dist/capabilities/automator/schemas/disconnect.d.ts.map +1 -0
  32. package/dist/capabilities/automator/schemas/disconnect.js +11 -0
  33. package/dist/capabilities/automator/schemas/disconnect.js.map +1 -0
  34. package/dist/capabilities/automator/schemas/index.d.ts +4 -0
  35. package/dist/capabilities/automator/schemas/index.d.ts.map +1 -0
  36. package/dist/capabilities/automator/schemas/index.js +12 -0
  37. package/dist/capabilities/automator/schemas/index.js.map +1 -0
  38. package/dist/capabilities/automator/schemas/launch.d.ts +17 -0
  39. package/dist/capabilities/automator/schemas/launch.d.ts.map +1 -0
  40. package/dist/capabilities/automator/schemas/launch.js +26 -0
  41. package/dist/capabilities/automator/schemas/launch.js.map +1 -0
  42. package/dist/capabilities/element/index.d.ts +5 -0
  43. package/dist/capabilities/element/index.d.ts.map +1 -0
  44. package/dist/capabilities/element/index.js +5 -0
  45. package/dist/capabilities/element/index.js.map +1 -0
  46. package/dist/capabilities/index.d.ts +15 -0
  47. package/dist/capabilities/index.d.ts.map +1 -0
  48. package/dist/capabilities/index.js +14 -0
  49. package/dist/capabilities/index.js.map +1 -0
  50. package/dist/capabilities/miniprogram/index.d.ts +5 -0
  51. package/dist/capabilities/miniprogram/index.d.ts.map +1 -0
  52. package/dist/capabilities/miniprogram/index.js +5 -0
  53. package/dist/capabilities/miniprogram/index.js.map +1 -0
  54. package/dist/capabilities/network/index.d.ts +5 -0
  55. package/dist/capabilities/network/index.d.ts.map +1 -0
  56. package/dist/capabilities/network/index.js +5 -0
  57. package/dist/capabilities/network/index.js.map +1 -0
  58. package/dist/capabilities/page/index.d.ts +5 -0
  59. package/dist/capabilities/page/index.d.ts.map +1 -0
  60. package/dist/capabilities/page/index.js +5 -0
  61. package/dist/capabilities/page/index.js.map +1 -0
  62. package/dist/capabilities/record/index.d.ts +5 -0
  63. package/dist/capabilities/record/index.d.ts.map +1 -0
  64. package/dist/capabilities/record/index.js +5 -0
  65. package/dist/capabilities/record/index.js.map +1 -0
  66. package/dist/capabilities/schema-registry.d.ts +4 -0
  67. package/dist/capabilities/schema-registry.d.ts.map +1 -0
  68. package/dist/capabilities/schema-registry.js +18 -0
  69. package/dist/capabilities/schema-registry.js.map +1 -0
  70. package/dist/capabilities/schema-types.d.ts +22 -0
  71. package/dist/capabilities/schema-types.d.ts.map +1 -0
  72. package/dist/capabilities/schema-types.js +2 -0
  73. package/dist/capabilities/schema-types.js.map +1 -0
  74. package/dist/capabilities/snapshot/index.d.ts +5 -0
  75. package/dist/capabilities/snapshot/index.d.ts.map +1 -0
  76. package/dist/capabilities/snapshot/index.js +5 -0
  77. package/dist/capabilities/snapshot/index.js.map +1 -0
  78. package/dist/config/loader.js +1 -1
  79. package/dist/config/loader.js.map +1 -1
  80. package/dist/core/element-ref.d.ts +1 -43
  81. package/dist/core/element-ref.d.ts.map +1 -1
  82. package/dist/core/element-ref.js +1 -212
  83. package/dist/core/element-ref.js.map +1 -1
  84. package/dist/core/logger.d.ts +1 -54
  85. package/dist/core/logger.d.ts.map +1 -1
  86. package/dist/core/logger.js +1 -377
  87. package/dist/core/logger.js.map +1 -1
  88. package/dist/core/output.d.ts +1 -20
  89. package/dist/core/output.d.ts.map +1 -1
  90. package/dist/core/output.js +1 -55
  91. package/dist/core/output.js.map +1 -1
  92. package/dist/core/report-generator.d.ts +1 -23
  93. package/dist/core/report-generator.d.ts.map +1 -1
  94. package/dist/core/report-generator.js +1 -211
  95. package/dist/core/report-generator.js.map +1 -1
  96. package/dist/core/session.d.ts +2 -82
  97. package/dist/core/session.d.ts.map +1 -1
  98. package/dist/core/session.js +2 -305
  99. package/dist/core/session.js.map +1 -1
  100. package/dist/core/timeout.d.ts +1 -48
  101. package/dist/core/timeout.d.ts.map +1 -1
  102. package/dist/core/timeout.js +1 -66
  103. package/dist/core/timeout.js.map +1 -1
  104. package/dist/core/tool-logger.d.ts +1 -82
  105. package/dist/core/tool-logger.d.ts.map +1 -1
  106. package/dist/core/tool-logger.js +1 -452
  107. package/dist/core/tool-logger.js.map +1 -1
  108. package/dist/core/validation.d.ts +1 -38
  109. package/dist/core/validation.d.ts.map +1 -1
  110. package/dist/core/validation.js +1 -92
  111. package/dist/core/validation.js.map +1 -1
  112. package/dist/runtime/element/element-ref.d.ts +44 -0
  113. package/dist/runtime/element/element-ref.d.ts.map +1 -0
  114. package/dist/runtime/element/element-ref.js +214 -0
  115. package/dist/runtime/element/element-ref.js.map +1 -0
  116. package/dist/runtime/element/index.d.ts +2 -0
  117. package/dist/runtime/element/index.d.ts.map +1 -0
  118. package/dist/runtime/element/index.js +2 -0
  119. package/dist/runtime/element/index.js.map +1 -0
  120. package/dist/runtime/index.d.ts +10 -0
  121. package/dist/runtime/index.d.ts.map +1 -0
  122. package/dist/runtime/index.js +10 -0
  123. package/dist/runtime/index.js.map +1 -0
  124. package/dist/runtime/logging/index.d.ts +3 -0
  125. package/dist/runtime/logging/index.d.ts.map +1 -0
  126. package/dist/runtime/logging/index.js +3 -0
  127. package/dist/runtime/logging/index.js.map +1 -0
  128. package/dist/runtime/logging/logger.d.ts +55 -0
  129. package/dist/runtime/logging/logger.d.ts.map +1 -0
  130. package/dist/runtime/logging/logger.js +379 -0
  131. package/dist/runtime/logging/logger.js.map +1 -0
  132. package/dist/runtime/logging/tool-logger.d.ts +83 -0
  133. package/dist/runtime/logging/tool-logger.d.ts.map +1 -0
  134. package/dist/runtime/logging/tool-logger.js +454 -0
  135. package/dist/runtime/logging/tool-logger.js.map +1 -0
  136. package/dist/runtime/outputs/index.d.ts +3 -0
  137. package/dist/runtime/outputs/index.d.ts.map +1 -0
  138. package/dist/runtime/outputs/index.js +3 -0
  139. package/dist/runtime/outputs/index.js.map +1 -0
  140. package/dist/runtime/outputs/output-manager.d.ts +12 -0
  141. package/dist/runtime/outputs/output-manager.d.ts.map +1 -0
  142. package/dist/runtime/outputs/output-manager.js +39 -0
  143. package/dist/runtime/outputs/output-manager.js.map +1 -0
  144. package/dist/runtime/outputs/report-generator.d.ts +5 -0
  145. package/dist/runtime/outputs/report-generator.d.ts.map +1 -0
  146. package/dist/runtime/outputs/report-generator.js +175 -0
  147. package/dist/runtime/outputs/report-generator.js.map +1 -0
  148. package/dist/runtime/session/index.d.ts +3 -0
  149. package/dist/runtime/session/index.d.ts.map +1 -0
  150. package/dist/runtime/session/index.js +3 -0
  151. package/dist/runtime/session/index.js.map +1 -0
  152. package/dist/runtime/session/store.d.ts +28 -0
  153. package/dist/runtime/session/store.d.ts.map +1 -0
  154. package/dist/runtime/session/store.js +154 -0
  155. package/dist/runtime/session/store.js.map +1 -0
  156. package/dist/runtime/session/utils/cleanup.d.ts +3 -0
  157. package/dist/runtime/session/utils/cleanup.d.ts.map +1 -0
  158. package/dist/runtime/session/utils/cleanup.js +78 -0
  159. package/dist/runtime/session/utils/cleanup.js.map +1 -0
  160. package/dist/runtime/timeout/index.d.ts +2 -0
  161. package/dist/runtime/timeout/index.d.ts.map +1 -0
  162. package/dist/runtime/timeout/index.js +2 -0
  163. package/dist/runtime/timeout/index.js.map +1 -0
  164. package/dist/runtime/timeout/timeout.d.ts +49 -0
  165. package/dist/runtime/timeout/timeout.d.ts.map +1 -0
  166. package/dist/runtime/timeout/timeout.js +67 -0
  167. package/dist/runtime/timeout/timeout.js.map +1 -0
  168. package/dist/runtime/validation/index.d.ts +2 -0
  169. package/dist/runtime/validation/index.d.ts.map +1 -0
  170. package/dist/runtime/validation/index.js +2 -0
  171. package/dist/runtime/validation/index.js.map +1 -0
  172. package/dist/runtime/validation/validation.d.ts +39 -0
  173. package/dist/runtime/validation/validation.d.ts.map +1 -0
  174. package/dist/runtime/validation/validation.js +93 -0
  175. package/dist/runtime/validation/validation.js.map +1 -0
  176. package/dist/schemas/automator/miniprogram_close.json +12 -0
  177. package/dist/schemas/automator/miniprogram_connect.json +19 -0
  178. package/dist/schemas/automator/miniprogram_disconnect.json +12 -0
  179. package/dist/schemas/automator/miniprogram_launch.json +30 -0
  180. package/dist/server.js +1 -1
  181. package/dist/server.js.map +1 -1
  182. package/dist/tools/index.js +1 -1
  183. package/dist/tools/index.js.map +1 -1
  184. package/dist/tools/miniprogram.d.ts +0 -1
  185. package/dist/tools/miniprogram.d.ts.map +1 -1
  186. package/dist/tools/miniprogram.js +17 -29
  187. package/dist/tools/miniprogram.js.map +1 -1
  188. package/dist/tools/page.js +2 -2
  189. package/dist/tools/page.js.map +1 -1
  190. package/docs/directory-structure-and-code-style-best-practices.md +91 -0
  191. package/docs/migration/README.md +34 -0
  192. package/docs/migration/TC-ALIGN-01-notes.md +35 -0
  193. package/docs/migration/runtime-skeleton.md +50 -0
  194. package/docs/migration/tool-schema-strategy.md +75 -0
  195. package/docs//345/256/214/346/225/264/345/256/236/347/216/260/346/226/271/346/241/210.md +14 -14
  196. package/docs//347/254/254/344/270/200/347/211/210/346/234/254/346/226/271/346/241/210.md +7 -7
  197. package/package.json +4 -2
  198. package/docs/SIMPLE_USAGE.md +0 -210
  199. package/docs/architecture.E-Docs.md +0 -1359
  200. package/docs/architecture.F1.md +0 -720
  201. package/docs/architecture.F2.md +0 -871
  202. package/docs/architecture.F3.md +0 -905
  203. package/docs/architecture.md +0 -90
  204. package/docs/charter.A1.align.yaml +0 -170
  205. package/docs/charter.A2.align.yaml +0 -199
  206. package/docs/charter.A3.align.yaml +0 -242
  207. package/docs/charter.A4.align.yaml +0 -227
  208. package/docs/charter.B1.align.yaml +0 -179
  209. package/docs/charter.B2.align.yaml +0 -200
  210. package/docs/charter.B3.align.yaml +0 -200
  211. package/docs/charter.B4.align.yaml +0 -188
  212. package/docs/charter.C1.align.yaml +0 -190
  213. package/docs/charter.C2.align.yaml +0 -202
  214. package/docs/charter.C3.align.yaml +0 -211
  215. package/docs/charter.C4.align.yaml +0 -263
  216. package/docs/charter.C5.align.yaml +0 -220
  217. package/docs/charter.D1.align.yaml +0 -190
  218. package/docs/charter.D2.align.yaml +0 -234
  219. package/docs/charter.D3.align.yaml +0 -206
  220. package/docs/charter.E-Docs.align.yaml +0 -294
  221. package/docs/charter.F1.align.yaml +0 -193
  222. package/docs/charter.F2.align.yaml +0 -248
  223. package/docs/charter.F3.align.yaml +0 -287
  224. package/docs/charter.G.align.yaml +0 -174
  225. package/docs/charter.align.yaml +0 -111
  226. package/docs/maintenance.md +0 -682
  227. package/docs/playwright-mcp/350/260/203/347/240/224.md +0 -53
  228. package/docs/setup-guide.md +0 -775
  229. package/docs/tasks.A1.atomize.md +0 -296
  230. package/docs/tasks.A2.atomize.md +0 -408
  231. package/docs/tasks.A3.atomize.md +0 -564
  232. package/docs/tasks.A4.atomize.md +0 -496
  233. package/docs/tasks.B1.atomize.md +0 -352
  234. package/docs/tasks.B2.atomize.md +0 -561
  235. package/docs/tasks.B3.atomize.md +0 -508
  236. package/docs/tasks.B4.atomize.md +0 -504
  237. package/docs/tasks.C1.atomize.md +0 -540
  238. package/docs/tasks.C2.atomize.md +0 -665
  239. package/docs/tasks.C3.atomize.md +0 -745
  240. package/docs/tasks.C4.atomize.md +0 -908
  241. package/docs/tasks.C5.atomize.md +0 -755
  242. package/docs/tasks.D1.atomize.md +0 -547
  243. package/docs/tasks.D2.atomize.md +0 -619
  244. package/docs/tasks.D3.atomize.md +0 -790
  245. package/docs/tasks.E-Docs.atomize.md +0 -1204
  246. package/docs/tasks.atomize.md +0 -189
@@ -1,1359 +0,0 @@
1
- # E1: Documentation Enhancement - Architecture Design
2
-
3
- ## Metadata
4
- - **Task**: E1 - Documentation Enhancement
5
- - **Stage**: E - Documentation & Examples
6
- - **Status**: PLANNED
7
- - **Created**: 2025-10-02
8
- - **Author**: Claude Code
9
-
10
- ---
11
-
12
- ## 1. Overview
13
-
14
- This document defines the architecture and organization of the project documentation system. The goal is to create a comprehensive, navigable, and maintainable documentation structure that serves multiple user personas (new users, integration developers, test engineers, troubleshooters, contributors).
15
-
16
- ### Key Design Principles
17
- 1. **Progressive Disclosure**: Start simple (README quickstart), go deep (API docs)
18
- 2. **Consistent Formatting**: Unified structure for all API docs and examples
19
- 3. **Cross-Referencing**: Internal links between related documentation
20
- 4. **Maintainability**: Clear update protocols, templates for new content
21
- 5. **Searchability**: Descriptive headings, keywords, categorization
22
- 6. **Bilingual Support**: Critical sections in English + Chinese for accessibility
23
-
24
- ---
25
-
26
- ## 2. Documentation Structure
27
-
28
- ```
29
- creatoria-miniapp-mcp/
30
- ├── README.md # Entry point: quickstart + navigation
31
- ├── CONTRIBUTING.md # Enhanced: 6A workflow + development guide
32
- ├── LICENSE # MIT license (existing)
33
-
34
- ├── docs/
35
- │ ├── architecture.md # System architecture (NEW)
36
- │ ├── setup-guide.md # Detailed environment setup (ENHANCE)
37
- │ ├── troubleshooting.md # FAQ + error reference + debugging (ENHANCE)
38
- │ │
39
- │ └── api/ # API reference documentation
40
- │ ├── README.md # Tool catalog + basic workflows (NEW)
41
- │ ├── automator.md # 4 tools: launch, connect, disconnect, close (NEW)
42
- │ ├── miniprogram.md # 6 tools: navigate, evaluate, screenshot, etc. (NEW)
43
- │ ├── page.md # 8 tools: query, data, wait, scroll, etc. (NEW)
44
- │ ├── element.md # 23 tools: attributes, interactions, components (NEW)
45
- │ ├── assert.md # 9 tools: exists, text, attribute, data, etc. (NEW)
46
- │ ├── snapshot.md # 3 tools: capture, restore, compare (NEW)
47
- │ └── record.md # 6 tools: start, stop, save, replay, etc. (NEW)
48
-
49
- └── examples/ # Usage scenarios and patterns
50
- ├── README.md # Example index (NEW)
51
- ├── 01-basic-navigation.md # Basic: page navigation (EXISTING - enhance)
52
- ├── 02-element-interaction.md # Basic: tap, input, swiper, picker (NEW)
53
- ├── 03-assertion-testing.md # Advanced: automated testing workflow (NEW)
54
- ├── 04-snapshot-debugging.md # Advanced: state capture and restore (NEW)
55
- ├── 05-record-replay.md # Advanced: record flows, replay (NEW)
56
- └── (optional) 06-e2e-shopping.md # Comprehensive: shopping cart flow (NEW)
57
- ```
58
-
59
- **Design Rationale**:
60
- - **Separation of Concerns**: `/docs` for reference, `/examples` for learning
61
- - **Logical Grouping**: API docs categorized by tool level (Automator → Element)
62
- - **Discoverability**: Each directory has README.md index
63
- - **Version Control**: All docs in git, track changes alongside code
64
-
65
- ---
66
-
67
- ## 3. Component Specifications
68
-
69
- ### 3.1 README.md (Entry Point)
70
-
71
- **Purpose**: 5-minute path to first successful automation command
72
-
73
- **Target Audience**: New users, evaluators, quick reference
74
-
75
- **Structure**:
76
- ```markdown
77
- # WeChat Mini Program Automation MCP Server
78
-
79
- [Badges: Tests Status, License, Version, MCP Protocol]
80
-
81
- ## What is this?
82
-
83
- Brief value proposition (2-3 sentences):
84
- - Expose WeChat Mini Program automation via MCP protocol
85
- - 59 tools across 7 categories
86
- - Seamless integration with Claude Desktop, Cline, and custom MCP clients
87
-
88
- ## Features
89
-
90
- - 🚀 **59 Automation Tools**: Comprehensive coverage (Automator/MiniProgram/Page/Element/Assert/Snapshot/Record)
91
- - 🎯 **ElementRef Protocol**: Reliable element resolution (refId/selector/xpath)
92
- - 📦 **Session Management**: Isolated state per MCP session
93
- - 🔄 **Snapshot & Replay**: Debug with state capture, automate with recording
94
- - 🧪 **Built-in Assertions**: 9 assertion tools for testing workflows
95
- - 🔌 **MCP Native**: First-class support for Claude Desktop and MCP ecosystem
96
-
97
- ## Quick Start
98
-
99
- ### Prerequisites
100
- - Node.js 18+ (LTS recommended)
101
- - WeChat DevTools with automation enabled
102
- - MCP-compatible client (Claude Desktop, Cline, etc.)
103
-
104
- ### Installation
105
-
106
- ```bash
107
- # Step 1: Clone and install
108
- git clone git@github.com:rn1024/creatoria-miniapp-mcp.git
109
- cd creatoria-miniapp-mcp
110
- pnpm install
111
-
112
- # Step 2: Build
113
- pnpm build
114
-
115
- # Step 3: Configure MCP client (e.g., Claude Desktop)
116
- # Edit ~/Library/Application Support/Claude/claude_desktop_config.json
117
- {
118
- "mcpServers": {
119
- "wechat-automation": {
120
- "command": "node",
121
- "args": ["/absolute/path/to/creatoria-miniapp-mcp/dist/cli.js"]
122
- }
123
- }
124
- }
125
- ```
126
-
127
- ### First Automation
128
-
129
- ```javascript
130
- // 1. Launch WeChat DevTools
131
- await automator_launch({
132
- projectPath: "/path/to/mini-program"
133
- });
134
-
135
- // 2. Navigate to a page
136
- await miniprogram_navigateTo({
137
- url: "/pages/index/index"
138
- });
139
-
140
- // 3. Query and interact with element
141
- const result = await element_tap({
142
- elementRef: { selector: ".btn-submit" }
143
- });
144
- ```
145
-
146
- ## Documentation
147
-
148
- - 📚 [Complete API Reference](docs/api/README.md) - All 59 tools documented
149
- - 💡 [Usage Examples](examples/README.md) - 5+ real-world scenarios
150
- - ⚙️ [Setup Guide](docs/setup-guide.md) - Detailed environment configuration
151
- - 🔧 [Troubleshooting](docs/troubleshooting.md) - Common issues and debugging
152
- - 🏗️ [System Architecture](docs/architecture.md) - Design decisions and structure
153
- - 🤝 [Contributing Guide](CONTRIBUTING.md) - 6A workflow and development standards
154
-
155
- ## Usage Examples
156
-
157
- ### Navigate and Interact
158
- ```javascript
159
- // Launch and navigate
160
- await automator_launch({ projectPath: "/path/to/project" });
161
- await miniprogram_navigateTo({ url: "/pages/list/list" });
162
-
163
- // Query and tap element
164
- await element_tap({
165
- elementRef: { selector: ".item-card", index: 0 }
166
- });
167
- ```
168
-
169
- ### Run Assertions
170
- ```javascript
171
- // Assert element exists
172
- await assert_elementExists({
173
- elementRef: { selector: ".success-message" }
174
- });
175
-
176
- // Assert text content
177
- await assert_elementText({
178
- elementRef: { selector: ".title" },
179
- expected: "Product Name"
180
- });
181
- ```
182
-
183
- ### Capture Snapshots
184
- ```javascript
185
- // Capture state before action
186
- const before = await snapshot_capture({
187
- snapshotId: "before-submit"
188
- });
189
-
190
- // Perform action
191
- await element_tap({ elementRef: { selector: ".btn-submit" } });
192
-
193
- // Compare state changes
194
- await snapshot_compare({
195
- snapshotId1: "before-submit",
196
- snapshotId2: "after-submit"
197
- });
198
- ```
199
-
200
- ## Tool Categories (59 Total)
201
-
202
- ### Automator (4 tools)
203
- Launch, connect, disconnect, close automation sessions
204
-
205
- ### MiniProgram (6 tools)
206
- Navigate, evaluate, screenshot, mock, app-level operations
207
-
208
- ### Page (8 tools)
209
- Query elements, manipulate data, wait for conditions, scroll
210
-
211
- ### Element (23 tools)
212
- Get attributes, interact (tap/input/swipe), component-specific methods
213
-
214
- ### Assert (9 tools)
215
- Validate existence, text, attributes, data, visibility
216
-
217
- ### Snapshot (3 tools)
218
- Capture, restore, compare application state
219
-
220
- ### Record (6 tools)
221
- Record user flows, save, replay, manage recordings
222
-
223
- ## Project Structure
224
-
225
- ```
226
- src/
227
- ├── tools/ # 59 MCP tool implementations
228
- ├── core/ # SessionStore, ElementRef, OutputManager
229
- ├── config/ # Configuration resolution
230
- ├── server.ts # MCP Server with stdio transport
231
- └── cli.ts # CLI entry point
232
-
233
- tests/
234
- └── unit/ # 290+ tests validating all tools
235
-
236
- docs/
237
- ├── api/ # Complete API reference
238
- └── architecture.md # System design
239
-
240
- examples/
241
- └── *.md # Usage scenarios
242
- ```
243
-
244
- ## Contributing
245
-
246
- We welcome contributions! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for:
247
- - 6A Workflow (Align → Architect → Atomize → Approve → Automate → Assess)
248
- - Development environment setup
249
- - Code standards and testing conventions
250
- - How to add new tools
251
- - Pull request process
252
-
253
- ## License
254
-
255
- MIT License - see [LICENSE](LICENSE) for details
256
-
257
- ## Links
258
-
259
- - **GitHub**: [rn1024/creatoria-miniapp-mcp](https://github.com/rn1024/creatoria-miniapp-mcp)
260
- - **MCP Protocol**: [modelcontextprotocol.io](https://modelcontextprotocol.io/)
261
- - **WeChat DevTools**: [developers.weixin.qq.com](https://developers.weixin.qq.com/miniprogram/dev/devtools/)
262
- ```
263
-
264
- **Update Protocol**:
265
- - Update "Features" when tool categories added
266
- - Update quickstart if MCP configuration changes
267
- - Keep inline examples synchronized with examples/ directory
268
- - Review quarterly for accuracy
269
-
270
- ---
271
-
272
- ### 3.2 API Documentation (docs/api/)
273
-
274
- #### 3.2.1 docs/api/README.md (Tool Catalog)
275
-
276
- **Purpose**: Comprehensive index of all 59 tools with navigation and basic workflows
277
-
278
- **Structure**:
279
- ```markdown
280
- # API Reference
281
-
282
- ## Overview
283
-
284
- This MCP server provides **59 tools** across **7 categories** for WeChat Mini Program automation.
285
-
286
- ## Tool Categories
287
-
288
- ### Automator Level (4 tools)
289
- Session lifecycle management for WeChat DevTools automation.
290
-
291
- | Tool | Description |
292
- |------|-------------|
293
- | [automator_launch](automator.md#automator_launch) | Launch WeChat DevTools with a Mini Program project |
294
- | [automator_connect](automator.md#automator_connect) | Connect to an already-running DevTools instance |
295
- | [automator_disconnect](automator.md#automator_disconnect) | Disconnect from the current instance |
296
- | [automator_close](automator.md#automator_close) | Close the DevTools instance |
297
-
298
- ### MiniProgram Level (6 tools)
299
- Application-wide operations (navigation, evaluation, screenshots).
300
-
301
- | Tool | Description |
302
- |------|-------------|
303
- | [miniprogram_navigateTo](miniprogram.md#miniprogram_navigateto) | Navigate to a new page |
304
- | [miniprogram_navigateBack](miniprogram.md#miniprogram_navigateback) | Go back to previous page |
305
- | [miniprogram_redirectTo](miniprogram.md#miniprogram_redirectto) | Redirect to page (replace current) |
306
- | [miniprogram_evaluate](miniprogram.md#miniprogram_evaluate) | Execute JavaScript in Mini Program context |
307
- | [miniprogram_screenshot](miniprogram.md#miniprogram_screenshot) | Capture screenshot of entire app |
308
- | [miniprogram_currentPage](miniprogram.md#miniprogram_currentpage) | Get current page information |
309
-
310
- ### Page Level (8 tools)
311
- Current page operations (query, data, wait, scroll).
312
-
313
- | Tool | Description |
314
- |------|-------------|
315
- | [page_querySelector](page.md#page_queryselector) | Query single element by selector |
316
- | [page_querySelectorAll](page.md#page_queryselectorall) | Query multiple elements by selector |
317
- | [page_data](page.md#page_data) | Get or set page data |
318
- | [page_setData](page.md#page_setdata) | Update page data |
319
- | [page_waitFor](page.md#page_waitfor) | Wait for condition (selector, timeout, custom) |
320
- | [page_scrollTo](page.md#page_scrollto) | Scroll to position |
321
- | [page_callMethod](page.md#page_callmethod) | Call page instance method |
322
- | [page_size](page.md#page_size) | Get page dimensions |
323
-
324
- ### Element Level (23 tools)
325
- Element-specific interactions and attribute access.
326
-
327
- **General Attributes (8 tools)**:
328
- - [element_attribute](element.md#element_attribute), [element_boundingClientRect](element.md#element_boundingclientrect)
329
- - [element_text](element.md#element_text), [element_value](element.md#element_value)
330
- - [element_property](element.md#element_property), [element_style](element.md#element_style)
331
- - [element_wxml](element.md#element_wxml), [element_outerWxml](element.md#element_outerwxml)
332
-
333
- **Interactions (3 tools)**:
334
- - [element_tap](element.md#element_tap), [element_longpress](element.md#element_longpress)
335
- - [element_touchstart_touchend](element.md#element_touchstart_touchend)
336
-
337
- **Input (1 tool)**:
338
- - [element_input](element.md#element_input)
339
-
340
- **Component-Specific Methods (11 tools)**:
341
- - Swiper: [element_swipeTo](element.md#element_swipeto)
342
- - Scroll View: [element_scrollIntoView](element.md#element_scrollintoview), [element_scrollTo_element](element.md#element_scrollto_element)
343
- - Movable View: [element_moveTo](element.md#element_moveto)
344
- - Picker: [element_callMethod](element.md#element_callmethod), [element_setPickerValue](element.md#element_setpickervalue)
345
- - Video: [element_play](element.md#element_play), [element_pause](element.md#element_pause), [element_seek](element.md#element_seek)
346
- - Textarea/Input: [element_trigger](element.md#element_trigger), [element_callMethod](element.md#element_callmethod)
347
-
348
- ### Assert Tools (9 tools)
349
- Testing and validation assertions.
350
-
351
- | Tool | Description |
352
- |------|-------------|
353
- | [assert_elementExists](assert.md#assert_elementexists) | Assert element exists in DOM |
354
- | [assert_elementNotExists](assert.md#assert_elementnotexists) | Assert element does not exist |
355
- | [assert_elementText](assert.md#assert_elementtext) | Assert element text content |
356
- | [assert_elementAttribute](assert.md#assert_elementattribute) | Assert element attribute value |
357
- | [assert_elementData](assert.md#assert_elementdata) | Assert page data value |
358
- | [assert_elementVisible](assert.md#assert_elementvisible) | Assert element is visible |
359
- | [assert_elementEnabled](assert.md#assert_elementenabled) | Assert element is enabled |
360
- | [assert_pageUrl](assert.md#assert_pageurl) | Assert current page URL |
361
- | [assert_screenshot](assert.md#assert_screenshot) | Visual regression testing |
362
-
363
- ### Snapshot Tools (3 tools)
364
- State management for debugging and testing.
365
-
366
- | Tool | Description |
367
- |------|-------------|
368
- | [snapshot_capture](snapshot.md#snapshot_capture) | Capture current page state |
369
- | [snapshot_restore](snapshot.md#snapshot_restore) | Restore previously captured state |
370
- | [snapshot_compare](snapshot.md#snapshot_compare) | Compare two snapshots |
371
-
372
- ### Record Tools (6 tools)
373
- Record and replay user flows for automation.
374
-
375
- | Tool | Description |
376
- |------|-------------|
377
- | [record_start](record.md#record_start) | Start recording user actions |
378
- | [record_stop](record.md#record_stop) | Stop current recording |
379
- | [record_save](record.md#record_save) | Save recording to file |
380
- | [record_replay](record.md#record_replay) | Replay saved recording |
381
- | [record_list](record.md#record_list) | List all saved recordings |
382
- | [record_delete](record.md#record_delete) | Delete saved recording |
383
-
384
- ## Common Workflows
385
-
386
- ### Basic Navigation Flow
387
- ```javascript
388
- // Launch → Navigate → Query → Interact → Screenshot
389
- await automator_launch({ projectPath: "/path/to/project" });
390
- await miniprogram_navigateTo({ url: "/pages/index/index" });
391
- const element = await page_querySelector({ selector: ".btn" });
392
- await element_tap({ elementRef: { refId: element.data.refId } });
393
- await miniprogram_screenshot({ path: "./result.png" });
394
- await automator_close();
395
- ```
396
-
397
- ### Testing Flow
398
- ```javascript
399
- // Launch → Navigate → Assert → Close
400
- await automator_launch({ projectPath: "/path/to/project" });
401
- await miniprogram_navigateTo({ url: "/pages/detail/detail" });
402
- await assert_elementExists({ elementRef: { selector: ".title" } });
403
- await assert_elementText({
404
- elementRef: { selector: ".title" },
405
- expected: "Product Details"
406
- });
407
- await automator_close();
408
- ```
409
-
410
- ### Debugging Flow
411
- ```javascript
412
- // Snapshot → Action → Compare
413
- await snapshot_capture({ snapshotId: "before" });
414
- await miniprogram_navigateTo({ url: "/pages/form/form" });
415
- await element_tap({ elementRef: { selector: ".submit" } });
416
- await snapshot_capture({ snapshotId: "after" });
417
- const diff = await snapshot_compare({
418
- snapshotId1: "before",
419
- snapshotId2: "after"
420
- });
421
- ```
422
-
423
- ### Record/Replay Flow
424
- ```javascript
425
- // Record → Save → Replay
426
- await record_start({ recordId: "checkout-flow" });
427
- // ... perform actions manually in DevTools or via tools
428
- await record_stop();
429
- await record_save({ recordId: "checkout-flow", path: "./recordings/checkout.json" });
430
-
431
- // Later: replay
432
- await record_replay({ recordId: "checkout-flow" });
433
- ```
434
-
435
- ## ElementRef Protocol
436
-
437
- All element-related tools accept an `elementRef` parameter for element resolution:
438
-
439
- ```typescript
440
- type ElementRef = {
441
- refId?: string; // Cached element handle (from previous save)
442
- selector?: string; // CSS/WXML selector
443
- xpath?: string; // XPath selector
444
- index?: number; // Index for multi-element results (0-based)
445
- pagePath?: string; // Target page path (optional)
446
- save?: boolean; // Save handle for future reference
447
- };
448
- ```
449
-
450
- **Resolution Priority**: `refId` → `selector` → `xpath`
451
-
452
- **Cache Invalidation**: Element handles (`refId`) are automatically invalidated on page navigation.
453
-
454
- **Example**:
455
- ```javascript
456
- // Method 1: Use selector (resolved every time)
457
- await element_tap({ elementRef: { selector: ".btn-submit" } });
458
-
459
- // Method 2: Save handle for reuse
460
- const result = await element_tap({
461
- elementRef: { selector: ".btn-submit", save: true }
462
- });
463
- const refId = result.data.refId;
464
-
465
- // Reuse handle (faster, no re-query)
466
- await element_attribute({ elementRef: { refId }, name: "class" });
467
-
468
- // Method 3: Query specific index
469
- await element_tap({ elementRef: { selector: ".item", index: 2 } });
470
-
471
- // Method 4: Use XPath
472
- await element_tap({ elementRef: { xpath: "//button[@class='submit']" } });
473
- ```
474
-
475
- ## See Also
476
-
477
- - [Setup Guide](../setup-guide.md) - Environment configuration
478
- - [Examples](../../examples/) - Usage scenarios
479
- - [Troubleshooting](../troubleshooting.md) - Common issues and debugging
480
- - [System Architecture](../architecture.md) - Design decisions
481
- ```
482
-
483
- #### 3.2.2 Tool Documentation Template
484
-
485
- **File**: `docs/api/{category}.md` (e.g., `automator.md`, `element.md`)
486
-
487
- **Per-Tool Format**:
488
- ```markdown
489
- ## tool_name
490
-
491
- **Category**: Automator | MiniProgram | Page | Element | Assert | Snapshot | Record
492
-
493
- **Description**:
494
- Brief 1-2 sentence description of what the tool does and when to use it.
495
-
496
- **Parameters**:
497
-
498
- | Name | Type | Required | Default | Description |
499
- |------|------|----------|---------|-------------|
500
- | param1 | string | Yes | - | Parameter description with purpose and constraints |
501
- | param2 | number | No | 5000 | Optional parameter description |
502
- | elementRef | ElementRef | Yes | - | Element reference (see [ElementRef Protocol](#elementref-protocol)) |
503
-
504
- **Return Value**:
505
-
506
- ```typescript
507
- {
508
- success: boolean; // Operation success status
509
- message: string; // Human-readable result message
510
- data?: { // Tool-specific data (if success = true)
511
- refId?: string; // Element handle (if save = true)
512
- value?: any; // Tool-specific return value
513
- // ... other fields
514
- };
515
- error?: { // Error details (if success = false)
516
- code: string; // Error code (e.g., ERR_ELEMENT_NOT_FOUND)
517
- details: string; // Detailed error message
518
- };
519
- }
520
- ```
521
-
522
- **Example**:
523
-
524
- ```javascript
525
- // Example 1: Basic usage
526
- const result = await tool_name({
527
- param1: "value",
528
- param2: 3000,
529
- elementRef: {
530
- selector: ".my-element",
531
- save: true
532
- }
533
- });
534
-
535
- if (result.success) {
536
- console.log(result.data);
537
- } else {
538
- console.error(result.error);
539
- }
540
-
541
- // Example 2: Error handling
542
- try {
543
- await tool_name({ param1: "invalid" });
544
- } catch (err) {
545
- console.error("Tool failed:", err.message);
546
- }
547
- ```
548
-
549
- **Usage Notes**:
550
- - ⚠️ Important behavior, performance, or edge case notes
551
- - 💡 Tips for optimal usage
552
- - 🔗 Dependencies on other tools or session state requirements
553
-
554
- **Common Errors**:
555
-
556
- | Error Code | Cause | Solution |
557
- |------------|-------|----------|
558
- | ERR_NOT_LAUNCHED | MiniProgram not launched | Call `automator_launch` first |
559
- | ERR_ELEMENT_NOT_FOUND | Element does not exist | Check selector, ensure page is loaded |
560
- | ERR_TIMEOUT | Operation timeout | Increase timeout parameter, check element state |
561
-
562
- **See Also**:
563
- - [Related Tool 1](#{category}.md#related_tool_1)
564
- - [Example: Scenario Name](../../examples/XX-scenario.md)
565
- ```
566
-
567
- **Tool Count by Category**:
568
- - `automator.md`: 4 tools
569
- - `miniprogram.md`: 6 tools
570
- - `page.md`: 8 tools
571
- - `element.md`: 23 tools
572
- - `assert.md`: 9 tools
573
- - `snapshot.md`: 3 tools
574
- - `record.md`: 6 tools
575
- - **Total**: 59 tools
576
-
577
- ---
578
-
579
- ### 3.3 Usage Examples (examples/)
580
-
581
- #### Example File Structure
582
-
583
- **File**: `examples/XX-scenario-name.md`
584
-
585
- **Template**:
586
- ```markdown
587
- # Example: [Scenario Name]
588
-
589
- > **Difficulty**: 🟢 Basic | 🟡 Intermediate | 🔴 Advanced
590
-
591
- ## Scenario Description
592
-
593
- [1-2 paragraphs describing the use case, user goal, and expected outcome]
594
-
595
- ## Prerequisites
596
-
597
- - [ ] WeChat DevTools installed and configured
598
- - [ ] MCP server built (`pnpm build`)
599
- - [ ] MCP client configured (Claude Desktop/Cline)
600
- - [ ] Mini Program project at `/path/to/project`
601
- - [ ] Specific page `/pages/[page-name]` exists in the project
602
-
603
- ## Tools Used
604
-
605
- | Tool | Purpose |
606
- |------|---------|
607
- | `tool_1` | Description of usage in this scenario |
608
- | `tool_2` | Description of usage in this scenario |
609
-
610
- ## Complete Code
611
-
612
- ```javascript
613
- // Full runnable code combining all steps
614
- async function runScenario() {
615
- // Step 1: Launch and navigate
616
- await automator_launch({ projectPath: "/path/to/project" });
617
- await miniprogram_navigateTo({ url: "/pages/target/target" });
618
-
619
- // Step 2: Interact with elements
620
- await element_tap({ elementRef: { selector: ".btn" } });
621
-
622
- // Step 3: Verify results
623
- await assert_elementExists({ elementRef: { selector: ".result" } });
624
-
625
- // Step 4: Cleanup
626
- await automator_close();
627
- }
628
-
629
- runScenario();
630
- ```
631
-
632
- ## Step-by-Step Walkthrough
633
-
634
- ### Step 1: [Action Name]
635
-
636
- **Goal**: [What this step achieves]
637
-
638
- **Code**:
639
- ```javascript
640
- // [Code explanation]
641
- const result = await tool_name({
642
- // parameters with inline comments
643
- });
644
- ```
645
-
646
- **Expected Result**:
647
- ```json
648
- {
649
- "success": true,
650
- "message": "...",
651
- "data": { ... }
652
- }
653
- ```
654
-
655
- **Explanation**:
656
- [Why this step is necessary, what it does, any important details]
657
-
658
- ---
659
-
660
- ### Step 2: [Action Name]
661
-
662
- [Same structure as Step 1]
663
-
664
- ---
665
-
666
- [Continue for all steps...]
667
-
668
- ## Expected Output
669
-
670
- ```
671
- [Console output or screenshot description showing final result]
672
- ```
673
-
674
- ## Troubleshooting
675
-
676
- ### Issue: [Common Problem 1]
677
- **Symptom**: [What user sees]
678
- **Cause**: [Why it happens]
679
- **Solution**: [How to fix]
680
-
681
- ### Issue: [Common Problem 2]
682
- [Same structure]
683
-
684
- ## Variations
685
-
686
- - **Variation 1**: [How to adapt this example for a different scenario]
687
- - **Variation 2**: [Alternative approach or tool usage]
688
-
689
- ## See Also
690
-
691
- - [API Documentation: tool_name](../docs/api/[category].md#tool_name)
692
- - [Related Example: XX-other-example.md](XX-other-example.md)
693
- - [Troubleshooting Guide](../docs/troubleshooting.md#specific-topic)
694
- ```
695
-
696
- #### Planned Examples
697
-
698
- 1. **01-basic-navigation.md** (Existing - Review/Enhance)
699
- **Difficulty**: 🟢 Basic
700
- **Topics**: Launch, navigate between pages, query elements, basic interactions
701
-
702
- 2. **02-element-interaction.md** (New)
703
- **Difficulty**: 🟢 Basic
704
- **Topics**: Tap buttons, input text, swipe swiper, scroll views, select picker options
705
-
706
- 3. **03-assertion-testing.md** (New)
707
- **Difficulty**: 🟡 Intermediate
708
- **Topics**: Launch → navigate → assert existence → assert text → assert attributes → cleanup
709
-
710
- 4. **04-snapshot-debugging.md** (New)
711
- **Difficulty**: 🟡 Intermediate
712
- **Topics**: Capture initial state → perform actions → capture new state → compare snapshots → restore state
713
-
714
- 5. **05-record-replay.md** (New)
715
- **Difficulty**: 🔴 Advanced
716
- **Topics**: Start recording → perform multi-step flow → stop/save → list recordings → replay → delete
717
-
718
- 6. **06-e2e-shopping.md** (Optional)
719
- **Difficulty**: 🔴 Advanced
720
- **Topics**: Browse products → filter → add to cart → update quantity → checkout → validate → assert success
721
-
722
- ---
723
-
724
- ### 3.4 Troubleshooting Guide (docs/troubleshooting.md)
725
-
726
- **Purpose**: Error resolution, debugging workflows, best practices
727
-
728
- **Target Audience**: All users encountering issues
729
-
730
- **Enhanced Structure** (from existing basic structure):
731
- ```markdown
732
- # Troubleshooting Guide
733
-
734
- ## Table of Contents
735
- 1. [Frequently Asked Questions](#faq)
736
- 2. [Error Reference](#error-reference)
737
- 3. [Debugging Workflows](#debugging-workflows)
738
- 4. [Best Practices](#best-practices)
739
- 5. [Common Pitfalls](#common-pitfalls)
740
-
741
- ---
742
-
743
- ## FAQ
744
-
745
- ### Q1: How do I enable automation in WeChat DevTools?
746
- **A**: Go to DevTools → Settings → Security → Enable "Service Port" and check "Allow CLI/HTTP calls to service port". Default port is 9420.
747
-
748
- ### Q2: Why does `automator_launch` fail with "Command not found"?
749
- **A**: The WeChat CLI path is incorrect. On macOS, verify `/Applications/wechatwebdevtools.app/Contents/MacOS/cli` exists. See [Setup Guide](setup-guide.md#wechat-devtools-configuration).
750
-
751
- ### Q3: What's the difference between `refId`, `selector`, and `xpath`?
752
- **A**:
753
- - `refId`: Cached element handle (fastest, but invalidated on page change)
754
- - `selector`: CSS/WXML selector (re-queries every time)
755
- - `xpath`: XPath selector (most flexible, slowest)
756
- See [ElementRef Protocol](api/README.md#elementref-protocol).
757
-
758
- ### Q4: Can I use this MCP server with clients other than Claude Desktop?
759
- **A**: Yes! Any MCP-compatible client works (Cline, custom clients via `@modelcontextprotocol/sdk`). See [Setup Guide](setup-guide.md#mcp-client-configuration).
760
-
761
- ### Q5: How do I debug "Element not found" errors?
762
- **A**: Follow the [Element Not Found Debugging Workflow](#workflow-1-element-not-found).
763
-
764
- [... 5-10 more FAQs covering common user questions]
765
-
766
- ---
767
-
768
- ## Error Reference
769
-
770
- ### Automator Errors
771
-
772
- #### ERR_LAUNCH_FAILED
773
- **Cause**: WeChat DevTools failed to start or automation port unavailable
774
-
775
- **Common Reasons**:
776
- - WeChat DevTools not installed
777
- - Automation port already in use (default 9420)
778
- - Project path does not exist or invalid `project.config.json`
779
- - Insufficient permissions (macOS/Linux)
780
-
781
- **Solutions**:
782
- 1. Verify DevTools installation:
783
- ```bash
784
- ls /Applications/wechatwebdevtools.app
785
- ```
786
-
787
- 2. Check port availability:
788
- ```bash
789
- lsof -i :9420
790
- # Kill process if occupied
791
- kill -9 <PID>
792
- ```
793
-
794
- 3. Verify project path and `project.config.json`:
795
- ```bash
796
- ls /path/to/project/project.config.json
797
- ```
798
-
799
- 4. Kill existing DevTools processes:
800
- ```bash
801
- pkill -f wechatwebdevtools
802
- ```
803
-
804
- **Example Error**:
805
- ```json
806
- {
807
- "success": false,
808
- "error": {
809
- "code": "ERR_LAUNCH_FAILED",
810
- "details": "Port 9420 already in use"
811
- }
812
- }
813
- ```
814
-
815
- ---
816
-
817
- #### ERR_CONNECT_TIMEOUT
818
- **Cause**: Connection to automation port timed out
819
-
820
- **Solutions**:
821
- - Ensure DevTools is running
822
- - Verify automation port is enabled (Settings → Security)
823
- - Check firewall settings
824
- - Increase timeout in `.mcp.json` (default: 30000ms)
825
-
826
- ---
827
-
828
- ### MiniProgram Errors
829
-
830
- #### ERR_NAVIGATION_FAILED
831
- **Cause**: Page navigation failed
832
-
833
- **Common Reasons**:
834
- - Invalid page path (page doesn't exist in `app.json`)
835
- - Page not registered in `pages` array
836
- - Network issues (for web-view pages)
837
-
838
- **Solutions**:
839
- - Verify page path in `app.json`
840
- - Use absolute path starting with `/pages/...`
841
- - Check DevTools console for navigation errors
842
-
843
- ---
844
-
845
- ### Page Errors
846
-
847
- #### ERR_ELEMENT_NOT_FOUND
848
- **Cause**: Element query returned no results
849
-
850
- **Common Reasons**:
851
- - Selector syntax incorrect
852
- - Element not yet rendered (timing issue)
853
- - Element on different page
854
- - Dynamic content not loaded
855
-
856
- **Solutions**:
857
- - Use `page_waitFor` before querying
858
- - Verify selector in DevTools WXML inspector
859
- - Try alternative selectors (class → id → xpath)
860
- - Check if on correct page (`miniprogram_currentPage`)
861
-
862
- ---
863
-
864
- ### Element Errors
865
-
866
- #### ERR_ELEMENT_INVALID
867
- **Cause**: Element reference (`refId`) is invalid or stale
868
-
869
- **Common Reasons**:
870
- - Page navigation invalidated cached element
871
- - Element removed from DOM
872
- - Session expired
873
-
874
- **Solutions**:
875
- - Re-query element after page navigation
876
- - Use `selector` instead of `refId` for stability
877
- - Check element existence before interaction
878
-
879
- ---
880
-
881
- #### ERR_INTERACTION_FAILED
882
- **Cause**: Element interaction failed
883
-
884
- **Common Reasons**:
885
- - Element not interactable (disabled, hidden, covered)
886
- - Element type doesn't support interaction (e.g., `tap` on `<text>`)
887
- - Timing issue (animation in progress)
888
-
889
- **Solutions**:
890
- - Wait for element to be visible/enabled
891
- - Use `element_attribute` to check `disabled` state
892
- - Add delay before interaction
893
-
894
- ---
895
-
896
- [... 15+ more error codes across all categories]
897
-
898
- ---
899
-
900
- ## Debugging Workflows
901
-
902
- ### Workflow 1: Element Not Found
903
-
904
- **Symptom**: `page_querySelector` or `element_tap` returns `ERR_ELEMENT_NOT_FOUND`
905
-
906
- **Step-by-Step Diagnosis**:
907
-
908
- 1. **Verify Page Load**
909
- ```javascript
910
- const pageInfo = await miniprogram_currentPage();
911
- console.log("Current page:", pageInfo.data.path);
912
- ```
913
-
914
- 2. **Inspect WXML Structure**
915
- - Open DevTools UI manually
916
- - Use "WXML Panel" to inspect actual element structure
917
- - Verify selector matches rendered markup
918
-
919
- 3. **Try Alternative Selectors**
920
- ```javascript
921
- // CSS class
922
- await page_querySelector({ selector: ".btn-submit" });
923
-
924
- // ID
925
- await page_querySelector({ selector: "#submit-btn" });
926
-
927
- // XPath
928
- await page_querySelector({ xpath: "//button[@class='btn-submit']" });
929
-
930
- // Tag + attribute
931
- await page_querySelector({ selector: "button[type='primary']" });
932
- ```
933
-
934
- 4. **Add Wait Condition**
935
- ```javascript
936
- // Wait for element to appear
937
- await page_waitFor({
938
- condition: "element",
939
- selector: ".btn-submit",
940
- timeout: 5000
941
- });
942
-
943
- // Then query
944
- const result = await page_querySelector({ selector: ".btn-submit" });
945
- ```
946
-
947
- 5. **Check Page Data**
948
- ```javascript
949
- // Verify page is in expected state
950
- const data = await page_data({ path: "" });
951
- console.log("Page data:", data);
952
- ```
953
-
954
- **Expected Outcome**: Element query succeeds or root cause identified
955
-
956
- ---
957
-
958
- ### Workflow 2: Session State Issues
959
-
960
- **Symptom**: Tools fail with "Session not initialized" or "MiniProgram not launched"
961
-
962
- **Diagnosis**:
963
- 1. Check if `automator_launch` was called
964
- 2. Verify session hasn't expired
965
- 3. Check if client reconnected to MCP server
966
-
967
- **Solution**:
968
- ```javascript
969
- // Always start with launch
970
- await automator_launch({ projectPath: "/path/to/project" });
971
-
972
- // Perform operations
973
- // ...
974
-
975
- // Clean up
976
- await automator_close();
977
- ```
978
-
979
- ---
980
-
981
- ### Workflow 3: Performance Degradation
982
-
983
- **Symptom**: Tools becoming slower over time
984
-
985
- **Diagnosis**:
986
- 1. Check element cache size (large caches slow down lookups)
987
- 2. Verify no memory leaks in DevTools
988
- 3. Check if too many snapshots/recordings stored
989
-
990
- **Solution**:
991
- - Clear element cache periodically (happens automatically on page navigation)
992
- - Delete old snapshots/recordings
993
- - Restart DevTools if memory usage high
994
-
995
- ---
996
-
997
- ## Best Practices
998
-
999
- ### Performance Optimization
1000
-
1001
- 1. **Reuse Element Handles**
1002
- ```javascript
1003
- // ❌ Bad: Query element multiple times
1004
- await element_tap({ elementRef: { selector: ".btn" } });
1005
- await element_attribute({ elementRef: { selector: ".btn" }, name: "class" });
1006
-
1007
- // ✅ Good: Save handle on first query
1008
- const tap = await element_tap({
1009
- elementRef: { selector: ".btn", save: true }
1010
- });
1011
- const refId = tap.data.refId;
1012
- await element_attribute({ elementRef: { refId }, name: "class" });
1013
- ```
1014
-
1015
- 2. **Batch Operations When Possible**
1016
- ```javascript
1017
- // Use page_data to get multiple values at once
1018
- const data = await page_data({ path: "" });
1019
- console.log(data.username, data.email, data.age);
1020
- ```
1021
-
1022
- 3. **Use Appropriate Timeouts**
1023
- - Short timeout (1-2s) for fast operations
1024
- - Medium timeout (5s) for animations
1025
- - Long timeout (10s+) for network requests
1026
-
1027
- ### Reliability Best Practices
1028
-
1029
- 1. **Wait for Page Transitions**
1030
- ```javascript
1031
- await miniprogram_navigateTo({ url: "/pages/detail/detail" });
1032
- await page_waitFor({ condition: "idle", timeout: 3000 });
1033
- ```
1034
-
1035
- 2. **Handle Errors Gracefully**
1036
- ```javascript
1037
- try {
1038
- await element_tap({ elementRef: { selector: ".btn" } });
1039
- } catch (err) {
1040
- console.error("Tap failed, trying alternative:", err);
1041
- await element_tap({ elementRef: { xpath: "//button" } });
1042
- }
1043
- ```
1044
-
1045
- 3. **Clean Up Sessions**
1046
- ```javascript
1047
- try {
1048
- // Your automation code
1049
- } finally {
1050
- await automator_close(); // Always close
1051
- }
1052
- ```
1053
-
1054
- ### Maintainability Best Practices
1055
-
1056
- 1. **Use Snapshots for Complex State**
1057
- ```javascript
1058
- await snapshot_capture({ snapshotId: "clean-state" });
1059
- // ... perform test
1060
- await snapshot_restore({ snapshotId: "clean-state" }); // Reset for next test
1061
- ```
1062
-
1063
- 2. **Record Flows for Regression Testing**
1064
- ```javascript
1065
- await record_start({ recordId: "checkout" });
1066
- // ... manual or automated actions
1067
- await record_save({ recordId: "checkout", path: "./regressions/checkout.json" });
1068
- ```
1069
-
1070
- 3. **Document Custom Selectors**
1071
- ```javascript
1072
- // Good: Document why selector is complex
1073
- // This selector targets the 3rd item card in the product list
1074
- const selector = ".product-list .item-card:nth-child(3)";
1075
- ```
1076
-
1077
- ---
1078
-
1079
- ## Common Pitfalls
1080
-
1081
- ### Pitfall 1: Stale Element References
1082
- **Problem**: Element `refId` becomes invalid after page navigation
1083
-
1084
- **Why**: ElementRef cache is cleared on page transitions for memory management
1085
-
1086
- **Solution**: Re-query elements after navigation, or use `selector` instead of `refId`
1087
-
1088
- ```javascript
1089
- // ❌ Bad
1090
- const tap = await element_tap({
1091
- elementRef: { selector: ".btn", save: true }
1092
- });
1093
- const refId = tap.data.refId;
1094
-
1095
- await miniprogram_navigateTo({ url: "/pages/other/other" });
1096
- await element_tap({ elementRef: { refId } }); // FAILS: refId invalid
1097
-
1098
- // ✅ Good
1099
- await miniprogram_navigateTo({ url: "/pages/other/other" });
1100
- await element_tap({ elementRef: { selector: ".btn" } }); // Re-queries
1101
- ```
1102
-
1103
- ---
1104
-
1105
- ### Pitfall 2: Incorrect Selector Syntax
1106
- **Problem**: WXML selector differs from web CSS
1107
-
1108
- **Why**: WeChat uses custom components (`<view>`, `<button>`, `<picker>`)
1109
-
1110
- **Solution**: Use DevTools WXML inspector to verify actual element structure
1111
-
1112
- ```javascript
1113
- // ❌ Bad (web CSS)
1114
- await page_querySelector({ selector: "div.container" });
1115
-
1116
- // ✅ Good (WXML)
1117
- await page_querySelector({ selector: "view.container" });
1118
- ```
1119
-
1120
- ---
1121
-
1122
- ### Pitfall 3: Timing Issues
1123
- **Problem**: Interaction fails because element not ready
1124
-
1125
- **Why**: Async data loading, animations, network requests
1126
-
1127
- **Solution**: Use `page_waitFor` with appropriate conditions
1128
-
1129
- ```javascript
1130
- // ❌ Bad
1131
- await miniprogram_navigateTo({ url: "/pages/list/list" });
1132
- await element_tap({ elementRef: { selector: ".item" } }); // May fail
1133
-
1134
- // ✅ Good
1135
- await miniprogram_navigateTo({ url: "/pages/list/list" });
1136
- await page_waitFor({ condition: "idle", timeout: 3000 });
1137
- await element_tap({ elementRef: { selector: ".item" } });
1138
- ```
1139
-
1140
- ---
1141
-
1142
- [... 2-5 more common pitfalls]
1143
-
1144
- ---
1145
-
1146
- ## Getting Help
1147
-
1148
- If you can't resolve your issue:
1149
- 1. Check [Usage Examples](../examples/) for similar scenarios
1150
- 2. Review [API Documentation](api/README.md) for tool details
1151
- 3. Search [GitHub Issues](https://github.com/rn1024/creatoria-miniapp-mcp/issues)
1152
- 4. Open a new issue with:
1153
- - Minimal reproduction case
1154
- - Error messages
1155
- - Environment details (OS, Node version, WeChat DevTools version)
1156
- ```
1157
-
1158
- ---
1159
-
1160
- ### 3.5 Setup Guide (docs/setup-guide.md)
1161
-
1162
- **Enhancements to Existing File**:
1163
- - Add detailed WeChat DevTools configuration steps
1164
- - Expand MCP client configuration examples (Claude Desktop, Cline, custom)
1165
- - Add verification steps with expected output
1166
- - Document all `.mcp.json` configuration options
1167
- - Add troubleshooting for common setup issues
1168
-
1169
- ---
1170
-
1171
- ### 3.6 Architecture Document (docs/architecture.md)
1172
-
1173
- **Purpose**: System design overview, component relationships, design decisions
1174
-
1175
- **Structure** (see existing Chinese version for inspiration, enhance with):
1176
- - C4 diagrams (Context, Container, Component)
1177
- - Sequence diagrams for key flows (launch → navigate → interact)
1178
- - Design decisions (ADRs): SessionStore, ElementRef protocol, OutputManager
1179
- - Extension points (adding new tools, custom capabilities)
1180
-
1181
- ---
1182
-
1183
- ### 3.7 Contributing Guide (CONTRIBUTING.md)
1184
-
1185
- **Enhancements to Existing File**:
1186
- - Add detailed 6A workflow explanation with examples
1187
- - Add tool development guide (step-by-step: create tool → register → test → document)
1188
- - Add commit message conventions with examples
1189
- - Add PR checklist template
1190
- - Add testing requirements and how to run tests
1191
-
1192
- ---
1193
-
1194
- ## 4. Technical Design Decisions
1195
-
1196
- ### 4.1 Documentation Format
1197
- **Decision**: Markdown
1198
- **Rationale**: Git-friendly, GitHub-native rendering, lightweight, convertible to HTML/PDF
1199
-
1200
- ### 4.2 API Documentation Organization
1201
- **Decision**: Separate file per category
1202
- **Rationale**: Manageable file sizes (200-500 lines), easier maintenance, clear navigation
1203
-
1204
- ### 4.3 Example Code Style
1205
- **Decision**: JavaScript + Comments (not TypeScript)
1206
- **Rationale**: Lower barrier to entry, focus on functionality not types (types in API docs)
1207
-
1208
- ### 4.4 Documentation Versioning
1209
- **Decision**: Docs tracked with code in git (no separate versioning)
1210
- **Rationale**: Simplicity, ensures doc-code synchronization, git tags serve as doc versions
1211
-
1212
- ### 4.5 Diagram Tool
1213
- **Decision**: Mermaid (Markdown-embedded)
1214
- **Rationale**: GitHub-native support, code-as-diagram (version control friendly), sufficient for needs
1215
-
1216
- ---
1217
-
1218
- ## 5. Documentation Plan
1219
-
1220
- ### 5.1 Writing Order (Priority)
1221
-
1222
- **Phase 1: Core Docs** (2 hours)
1223
- 1. README.md (quickstart, core entry point)
1224
- 2. docs/architecture.md (system overview)
1225
- 3. docs/api/README.md (tool catalog)
1226
-
1227
- **Phase 2: API Reference** (3 hours)
1228
- 1. docs/api/automator.md (foundation)
1229
- 2. docs/api/miniprogram.md (common)
1230
- 3. docs/api/page.md (common)
1231
- 4. docs/api/element.md (most tools)
1232
- 5. docs/api/assert.md (testing)
1233
- 6. docs/api/snapshot.md (debugging)
1234
- 7. docs/api/record.md (automation)
1235
-
1236
- **Phase 3: Examples** (2 hours)
1237
- 1. examples/01-basic-navigation.md (review/enhance)
1238
- 2. examples/02-element-interaction.md
1239
- 3. examples/03-assertion-testing.md
1240
- 4. examples/04-snapshot-debugging.md
1241
- 5. examples/05-record-replay.md
1242
- 6. examples/README.md (index)
1243
-
1244
- **Phase 4: Support Docs** (1.5 hours)
1245
- 1. docs/troubleshooting.md (FAQ, errors, debugging)
1246
- 2. docs/setup-guide.md (enhance existing)
1247
- 3. CONTRIBUTING.md (enhance existing)
1248
-
1249
- ### 5.2 Content Sources
1250
-
1251
- - **API Docs**: `src/tools/index.ts` (schemas), `src/tools/*.ts` (implementations), `tests/unit/*.test.ts` (examples)
1252
- - **Architecture**: `src/` directory structure, design docs in `docs/charter.*.yaml`, session logs
1253
- - **Examples**: `tests/unit/*.test.ts`, common usage patterns
1254
-
1255
- ### 5.3 Quality Checklist
1256
-
1257
- **Content**:
1258
- - [ ] Technically accurate (matches code)
1259
- - [ ] Clear expression
1260
- - [ ] Complete (no gaps)
1261
- - [ ] Practical (actionable)
1262
-
1263
- **Format**:
1264
- - [ ] Valid Markdown syntax
1265
- - [ ] Consistent heading levels (H1 → H2 → H3)
1266
- - [ ] Code blocks with language tags
1267
- - [ ] Tables aligned
1268
- - [ ] Links valid
1269
-
1270
- **Consistency**:
1271
- - [ ] Terminology unified
1272
- - [ ] Formatting unified
1273
- - [ ] Style unified
1274
-
1275
- ---
1276
-
1277
- ## 6. Design Outputs
1278
-
1279
- ### 6.1 Deliverables
1280
-
1281
- **Documentation Files** (15+ total):
1282
- - [ ] README.md (enhanced)
1283
- - [ ] CONTRIBUTING.md (enhanced)
1284
- - [ ] docs/architecture.md (new)
1285
- - [ ] docs/troubleshooting.md (enhanced)
1286
- - [ ] docs/setup-guide.md (enhanced)
1287
- - [ ] docs/api/README.md (new)
1288
- - [ ] docs/api/automator.md (new)
1289
- - [ ] docs/api/miniprogram.md (new)
1290
- - [ ] docs/api/page.md (new)
1291
- - [ ] docs/api/element.md (new)
1292
- - [ ] docs/api/assert.md (new)
1293
- - [ ] docs/api/snapshot.md (new)
1294
- - [ ] docs/api/record.md (new)
1295
- - [ ] examples/README.md (new)
1296
- - [ ] examples/01-basic-navigation.md (enhance)
1297
- - [ ] examples/02-element-interaction.md (new)
1298
- - [ ] examples/03-assertion-testing.md (new)
1299
- - [ ] examples/04-snapshot-debugging.md (new)
1300
- - [ ] examples/05-record-replay.md (new)
1301
-
1302
- **Templates** (reusable):
1303
- - API documentation template (Section 3.2.2)
1304
- - Example documentation template (Section 3.3)
1305
-
1306
- ### 6.2 Effort Estimate
1307
-
1308
- | Document Type | Count | Est. Words | Est. Time |
1309
- |--------------|-------|------------|-----------|
1310
- | README.md | 1 | 2000 | 30 min |
1311
- | architecture.md | 1 | 3000 | 45 min |
1312
- | API docs | 7 files | 500-2000/file | 3 hours |
1313
- | Examples | 5 files | 400-800/file | 2 hours |
1314
- | troubleshooting.md | 1 | 2000 | 1 hour |
1315
- | setup-guide.md | 1 (enhance) | +500 | 30 min |
1316
- | CONTRIBUTING.md | 1 (enhance) | +1000 | 30 min |
1317
- | Indexes | 2 | 300/file | 15 min |
1318
- | **Total** | **19** | **~15000** | **8-9 hours** |
1319
-
1320
- ---
1321
-
1322
- ## 7. Risks & Mitigation
1323
-
1324
- | Risk | Likelihood | Impact | Mitigation |
1325
- |------|-----------|--------|------------|
1326
- | Docs out of sync with code | Medium | High | Manual protocol in CONTRIBUTING.md, PR checklist |
1327
- | Examples non-runnable | Medium | High | Extract from test files, manual verification |
1328
- | Work underestimated | Medium | Medium | Focus core content, avoid over-polishing |
1329
- | Broken links | Low | Medium | Relative paths, pre-commit validation |
1330
-
1331
- ---
1332
-
1333
- ## 8. Next Steps
1334
-
1335
- ### 8.1 Architect Stage Complete
1336
- - [x] Documentation structure designed
1337
- - [x] Component specifications defined
1338
- - [x] Templates created
1339
- - [x] Technical decisions documented
1340
- - [x] Effort estimated
1341
-
1342
- ### 8.2 Proceed to Atomize
1343
- Create `docs/tasks.E1.atomize.md` with granular tasks:
1344
- - E1-1: README + Setup Guide + Architecture (Phase 1)
1345
- - E1-2: API Documentation - Automator/MiniProgram/Page (Phase 2a)
1346
- - E1-3: API Documentation - Element/Assert/Snapshot/Record (Phase 2b)
1347
- - E1-4: Examples - Navigation/Interaction/Testing (Phase 3a)
1348
- - E1-5: Examples - Snapshot/Record + Indexes (Phase 3b)
1349
- - E1-6: Troubleshooting + CONTRIBUTING (Phase 4)
1350
- - E1-7: Review and cross-reference validation
1351
-
1352
- Each task: <2 hours, clear inputs/outputs, DoD
1353
-
1354
- ---
1355
-
1356
- **Status**: ✅ COMPLETED
1357
- **Author**: Claude Code
1358
- **Date**: 2025-10-02
1359
- **Next**: Await approval, then proceed to Atomize stage