@creatoria/miniapp-mcp 0.1.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 (160) hide show
  1. package/README.md +469 -0
  2. package/dist/cli.d.ts +6 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +144 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/config/defaults.d.ts +73 -0
  7. package/dist/config/defaults.d.ts.map +1 -0
  8. package/dist/config/defaults.js +118 -0
  9. package/dist/config/defaults.js.map +1 -0
  10. package/dist/config/loader.d.ts +50 -0
  11. package/dist/config/loader.d.ts.map +1 -0
  12. package/dist/config/loader.js +189 -0
  13. package/dist/config/loader.js.map +1 -0
  14. package/dist/core/element-ref.d.ts +44 -0
  15. package/dist/core/element-ref.d.ts.map +1 -0
  16. package/dist/core/element-ref.js +213 -0
  17. package/dist/core/element-ref.js.map +1 -0
  18. package/dist/core/logger.d.ts +55 -0
  19. package/dist/core/logger.d.ts.map +1 -0
  20. package/dist/core/logger.js +378 -0
  21. package/dist/core/logger.js.map +1 -0
  22. package/dist/core/output.d.ts +21 -0
  23. package/dist/core/output.d.ts.map +1 -0
  24. package/dist/core/output.js +56 -0
  25. package/dist/core/output.js.map +1 -0
  26. package/dist/core/report-generator.d.ts +24 -0
  27. package/dist/core/report-generator.d.ts.map +1 -0
  28. package/dist/core/report-generator.js +212 -0
  29. package/dist/core/report-generator.js.map +1 -0
  30. package/dist/core/session.d.ts +83 -0
  31. package/dist/core/session.d.ts.map +1 -0
  32. package/dist/core/session.js +306 -0
  33. package/dist/core/session.js.map +1 -0
  34. package/dist/core/timeout.d.ts +49 -0
  35. package/dist/core/timeout.d.ts.map +1 -0
  36. package/dist/core/timeout.js +67 -0
  37. package/dist/core/timeout.js.map +1 -0
  38. package/dist/core/tool-logger.d.ts +83 -0
  39. package/dist/core/tool-logger.d.ts.map +1 -0
  40. package/dist/core/tool-logger.js +453 -0
  41. package/dist/core/tool-logger.js.map +1 -0
  42. package/dist/core/validation.d.ts +39 -0
  43. package/dist/core/validation.d.ts.map +1 -0
  44. package/dist/core/validation.js +93 -0
  45. package/dist/core/validation.js.map +1 -0
  46. package/dist/index.d.ts +7 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +6 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/server.d.ts +7 -0
  51. package/dist/server.d.ts.map +1 -0
  52. package/dist/server.js +85 -0
  53. package/dist/server.js.map +1 -0
  54. package/dist/tools/assert.d.ts +108 -0
  55. package/dist/tools/assert.d.ts.map +1 -0
  56. package/dist/tools/assert.js +291 -0
  57. package/dist/tools/assert.js.map +1 -0
  58. package/dist/tools/automator.d.ts +45 -0
  59. package/dist/tools/automator.d.ts.map +1 -0
  60. package/dist/tools/automator.js +186 -0
  61. package/dist/tools/automator.js.map +1 -0
  62. package/dist/tools/element.d.ts +253 -0
  63. package/dist/tools/element.d.ts.map +1 -0
  64. package/dist/tools/element.js +615 -0
  65. package/dist/tools/element.js.map +1 -0
  66. package/dist/tools/index.d.ts +97 -0
  67. package/dist/tools/index.d.ts.map +1 -0
  68. package/dist/tools/index.js +1565 -0
  69. package/dist/tools/index.js.map +1 -0
  70. package/dist/tools/miniprogram.d.ts +79 -0
  71. package/dist/tools/miniprogram.d.ts.map +1 -0
  72. package/dist/tools/miniprogram.js +245 -0
  73. package/dist/tools/miniprogram.js.map +1 -0
  74. package/dist/tools/network.d.ts +65 -0
  75. package/dist/tools/network.d.ts.map +1 -0
  76. package/dist/tools/network.js +205 -0
  77. package/dist/tools/network.js.map +1 -0
  78. package/dist/tools/page.d.ts +108 -0
  79. package/dist/tools/page.d.ts.map +1 -0
  80. package/dist/tools/page.js +307 -0
  81. package/dist/tools/page.js.map +1 -0
  82. package/dist/tools/record.d.ts +86 -0
  83. package/dist/tools/record.d.ts.map +1 -0
  84. package/dist/tools/record.js +316 -0
  85. package/dist/tools/record.js.map +1 -0
  86. package/dist/tools/snapshot.d.ts +82 -0
  87. package/dist/tools/snapshot.d.ts.map +1 -0
  88. package/dist/tools/snapshot.js +258 -0
  89. package/dist/tools/snapshot.js.map +1 -0
  90. package/dist/types.d.ts +240 -0
  91. package/dist/types.d.ts.map +1 -0
  92. package/dist/types.js +5 -0
  93. package/dist/types.js.map +1 -0
  94. package/docs/SIMPLE_USAGE.md +210 -0
  95. package/docs/api/README.md +244 -0
  96. package/docs/api/assert.md +1015 -0
  97. package/docs/api/automator.md +345 -0
  98. package/docs/api/element.md +1454 -0
  99. package/docs/api/miniprogram.md +558 -0
  100. package/docs/api/network.md +883 -0
  101. package/docs/api/page.md +909 -0
  102. package/docs/api/record.md +963 -0
  103. package/docs/api/snapshot.md +792 -0
  104. package/docs/architecture.E-Docs.md +1359 -0
  105. package/docs/architecture.F1.md +720 -0
  106. package/docs/architecture.F2.md +871 -0
  107. package/docs/architecture.F3.md +905 -0
  108. package/docs/architecture.md +90 -0
  109. package/docs/charter.A1.align.yaml +170 -0
  110. package/docs/charter.A2.align.yaml +199 -0
  111. package/docs/charter.A3.align.yaml +242 -0
  112. package/docs/charter.A4.align.yaml +227 -0
  113. package/docs/charter.B1.align.yaml +179 -0
  114. package/docs/charter.B2.align.yaml +200 -0
  115. package/docs/charter.B3.align.yaml +200 -0
  116. package/docs/charter.B4.align.yaml +188 -0
  117. package/docs/charter.C1.align.yaml +190 -0
  118. package/docs/charter.C2.align.yaml +202 -0
  119. package/docs/charter.C3.align.yaml +211 -0
  120. package/docs/charter.C4.align.yaml +263 -0
  121. package/docs/charter.C5.align.yaml +220 -0
  122. package/docs/charter.D1.align.yaml +190 -0
  123. package/docs/charter.D2.align.yaml +234 -0
  124. package/docs/charter.D3.align.yaml +206 -0
  125. package/docs/charter.E-Docs.align.yaml +294 -0
  126. package/docs/charter.F1.align.yaml +193 -0
  127. package/docs/charter.F2.align.yaml +248 -0
  128. package/docs/charter.F3.align.yaml +287 -0
  129. package/docs/charter.G.align.yaml +174 -0
  130. package/docs/charter.align.yaml +111 -0
  131. package/docs/examples/session-report-usage.md +449 -0
  132. package/docs/maintenance.md +682 -0
  133. package/docs/playwright-mcp/350/260/203/347/240/224.md +53 -0
  134. package/docs/setup-guide.md +775 -0
  135. package/docs/tasks.A1.atomize.md +296 -0
  136. package/docs/tasks.A2.atomize.md +408 -0
  137. package/docs/tasks.A3.atomize.md +564 -0
  138. package/docs/tasks.A4.atomize.md +496 -0
  139. package/docs/tasks.B1.atomize.md +352 -0
  140. package/docs/tasks.B2.atomize.md +561 -0
  141. package/docs/tasks.B3.atomize.md +508 -0
  142. package/docs/tasks.B4.atomize.md +504 -0
  143. package/docs/tasks.C1.atomize.md +540 -0
  144. package/docs/tasks.C2.atomize.md +665 -0
  145. package/docs/tasks.C3.atomize.md +745 -0
  146. package/docs/tasks.C4.atomize.md +908 -0
  147. package/docs/tasks.C5.atomize.md +755 -0
  148. package/docs/tasks.D1.atomize.md +547 -0
  149. package/docs/tasks.D2.atomize.md +619 -0
  150. package/docs/tasks.D3.atomize.md +790 -0
  151. package/docs/tasks.E-Docs.atomize.md +1204 -0
  152. package/docs/tasks.atomize.md +189 -0
  153. package/docs/troubleshooting.md +855 -0
  154. package/docs//345/256/214/346/225/264/345/256/236/347/216/260/346/226/271/346/241/210.md +155 -0
  155. package/docs//345/274/200/345/217/221/344/273/273/345/212/241/350/256/241/345/210/222.md +110 -0
  156. package/docs//345/276/256/344/277/241/345/260/217/347/250/213/345/272/217/350/207/252/345/212/250/345/214/226API/345/256/214/346/225/264/346/226/207/346/241/243.md +894 -0
  157. package/docs//345/276/256/344/277/241/345/260/217/347/250/213/345/272/217/350/207/252/345/212/250/345/214/226/345/256/214/346/225/264/346/223/215/344/275/234/346/211/213/345/206/214.md +1885 -0
  158. package/docs//346/216/245/345/217/243/346/226/271/346/241/210.md +565 -0
  159. package/docs//347/254/254/344/270/200/347/211/210/346/234/254/346/226/271/346/241/210.md +380 -0
  160. package/package.json +87 -0
@@ -0,0 +1,682 @@
1
+ # Maintenance Guide
2
+
3
+ This document provides guidance for maintaining the creatoria-miniapp-mcp project, including regular tasks, updates, monitoring, and troubleshooting.
4
+
5
+ ---
6
+
7
+ ## 📋 Table of Contents
8
+
9
+ - [Regular Maintenance Tasks](#regular-maintenance-tasks)
10
+ - [Dependency Management](#dependency-management)
11
+ - [Release Process](#release-process)
12
+ - [Monitoring & Health Checks](#monitoring--health-checks)
13
+ - [Backup & Recovery](#backup--recovery)
14
+ - [Performance Tuning](#performance-tuning)
15
+ - [Security Updates](#security-updates)
16
+ - [Troubleshooting](#troubleshooting)
17
+
18
+ ---
19
+
20
+ ## Regular Maintenance Tasks
21
+
22
+ ### Weekly Tasks
23
+
24
+ #### 1. Run Smoke Tests
25
+
26
+ Ensure core functionality is working:
27
+
28
+ ```bash
29
+ pnpm smoke-test
30
+ ```
31
+
32
+ **Expected Output**:
33
+ - ✅ Unit Tests: 545 passing
34
+ - ✅ Tool Count: 65 tools
35
+ - ✅ Lint: No errors
36
+ - ✅ Format: All files formatted
37
+
38
+ **If Failed**: See [Troubleshooting](#troubleshooting) section
39
+
40
+ ---
41
+
42
+ #### 2. Check for Security Vulnerabilities
43
+
44
+ Run npm audit:
45
+
46
+ ```bash
47
+ pnpm audit
48
+ ```
49
+
50
+ **Action Required**:
51
+ - **High/Critical**: Fix immediately
52
+ - **Moderate**: Schedule fix within 1 week
53
+ - **Low**: Review and fix in next release
54
+
55
+ **Fix Vulnerabilities**:
56
+ ```bash
57
+ # Automatic fix (if available)
58
+ pnpm audit fix
59
+
60
+ # Manual fix (update specific package)
61
+ pnpm update <package-name>
62
+ ```
63
+
64
+ ---
65
+
66
+ #### 3. Review Open Issues
67
+
68
+ Check GitHub Issues for:
69
+ - Bug reports requiring triage
70
+ - Feature requests to evaluate
71
+ - Questions needing answers
72
+
73
+ **Triage Labels**:
74
+ - `bug` - Confirmed bugs
75
+ - `enhancement` - Feature requests
76
+ - `question` - User questions
77
+ - `good first issue` - Good for new contributors
78
+
79
+ ---
80
+
81
+ ### Monthly Tasks
82
+
83
+ #### 1. Dependency Updates
84
+
85
+ Check for outdated dependencies:
86
+
87
+ ```bash
88
+ pnpm outdated
89
+ ```
90
+
91
+ **Update Strategy**:
92
+ - **Patch updates** (0.1.0 → 0.1.1): Update immediately
93
+ - **Minor updates** (0.1.0 → 0.2.0): Test thoroughly, update monthly
94
+ - **Major updates** (0.1.0 → 1.0.0): Review breaking changes, plan migration
95
+
96
+ **Update Process**:
97
+ ```bash
98
+ # Update all patch versions
99
+ pnpm update
100
+
101
+ # Update specific package to latest
102
+ pnpm update <package-name>@latest
103
+
104
+ # After updating, run full test suite
105
+ pnpm test
106
+ pnpm smoke-test
107
+ ```
108
+
109
+ ---
110
+
111
+ #### 2. Review and Update Documentation
112
+
113
+ - [ ] Check if README.md tool count matches actual tools (65)
114
+ - [ ] Update examples if API changes occurred
115
+ - [ ] Review troubleshooting guide for new issues
116
+ - [ ] Check if architecture docs are up to date
117
+
118
+ **Update Tool Count**:
119
+ ```bash
120
+ pnpm update-readme
121
+ ```
122
+
123
+ ---
124
+
125
+ #### 3. Performance Monitoring
126
+
127
+ Check for performance regressions:
128
+
129
+ ```bash
130
+ # Run unit tests with timing
131
+ pnpm test:unit --verbose
132
+
133
+ # Check for slow tests (>1s)
134
+ ```
135
+
136
+ **Performance Metrics**:
137
+ - Unit test suite: < 10 seconds
138
+ - Smoke test: < 20 seconds
139
+ - Individual test: < 1 second (warn if exceeded)
140
+
141
+ ---
142
+
143
+ ### Quarterly Tasks
144
+
145
+ #### 1. Major Version Updates
146
+
147
+ Review and plan major dependency updates:
148
+ - TypeScript
149
+ - Node.js (LTS versions)
150
+ - @modelcontextprotocol/sdk
151
+ - Jest
152
+ - ESLint/Prettier
153
+
154
+ **Process**:
155
+ 1. Create feature branch: `chore/update-deps-Q2-2025`
156
+ 2. Update one major dependency at a time
157
+ 3. Run full test suite after each update
158
+ 4. Document breaking changes in CHANGELOG.md
159
+ 5. Create PR for review
160
+
161
+ ---
162
+
163
+ #### 2. Security Audit
164
+
165
+ Perform comprehensive security review:
166
+
167
+ ```bash
168
+ # Run npm audit
169
+ pnpm audit
170
+
171
+ # Check for known vulnerabilities in dependencies
172
+ npm outdated --long
173
+ ```
174
+
175
+ **Review**:
176
+ - [ ] No high/critical vulnerabilities
177
+ - [ ] All dependencies actively maintained
178
+ - [ ] No deprecated packages
179
+
180
+ ---
181
+
182
+ #### 3. Code Quality Review
183
+
184
+ Run full quality checks:
185
+
186
+ ```bash
187
+ # Type coverage
188
+ pnpm typecheck
189
+
190
+ # Lint entire codebase
191
+ pnpm lint
192
+
193
+ # Check code formatting
194
+ pnpm format:check
195
+
196
+ # Run all tests
197
+ pnpm test
198
+ ```
199
+
200
+ ---
201
+
202
+ ## Dependency Management
203
+
204
+ ### Updating Dependencies
205
+
206
+ #### Safe Update Process
207
+
208
+ ```bash
209
+ # 1. Create branch
210
+ git checkout -b chore/update-dependencies
211
+
212
+ # 2. Update patch versions
213
+ pnpm update
214
+
215
+ # 3. Run smoke test
216
+ pnpm smoke-test
217
+
218
+ # 4. Commit
219
+ git add package.json pnpm-lock.yaml
220
+ git commit -m "chore: update dependencies (patch)"
221
+
222
+ # 5. Push and create PR
223
+ git push origin chore/update-dependencies
224
+ ```
225
+
226
+ ---
227
+
228
+ ### Critical Dependencies
229
+
230
+ Monitor these closely for updates:
231
+
232
+ | Dependency | Purpose | Update Frequency |
233
+ |------------|---------|------------------|
234
+ | `miniprogram-automator` | Core automation SDK | Check monthly |
235
+ | `@modelcontextprotocol/sdk` | MCP protocol | Check weekly |
236
+ | `typescript` | Type system | Minor updates only |
237
+ | `jest` | Testing framework | Quarterly |
238
+
239
+ ---
240
+
241
+ ### Known Issues
242
+
243
+ #### miniprogram-automator Type Declarations
244
+
245
+ **Issue**: Incomplete TypeScript type definitions
246
+
247
+ **Impact**: Build warnings (not errors), does not affect runtime
248
+
249
+ **Workaround**: Treated as warnings in smoke-test.sh
250
+
251
+ **Long-term Fix**:
252
+ - Contribute to upstream package
253
+ - Or create local `.d.ts` declarations
254
+
255
+ ---
256
+
257
+ ## Release Process
258
+
259
+ ### Automated Release via Script
260
+
261
+ Use the release script for version bumping and tagging:
262
+
263
+ ```bash
264
+ # Patch release (0.1.0 → 0.1.1)
265
+ pnpm release:patch
266
+
267
+ # Minor release (0.1.0 → 0.2.0)
268
+ pnpm release:minor
269
+
270
+ # Major release (0.1.0 → 1.0.0)
271
+ pnpm release:major
272
+
273
+ # Pre-release (0.1.0 → 0.1.1-0)
274
+ pnpm release:prerelease
275
+ ```
276
+
277
+ **The script will**:
278
+ 1. Run smoke tests
279
+ 2. Bump version in package.json
280
+ 3. Update README.md "Last Updated" date
281
+ 4. Create git commit
282
+ 5. Create git tag (v0.1.1)
283
+ 6. Display next steps
284
+
285
+ **After Script Completes**:
286
+ ```bash
287
+ # Push to GitHub (triggers CI/CD)
288
+ git push origin main --tags
289
+ ```
290
+
291
+ **GitHub Actions will**:
292
+ - Create GitHub release with changelog
293
+ - Publish to npm (stable releases only)
294
+
295
+ ---
296
+
297
+ ### Manual Release Process
298
+
299
+ If the script fails or you need more control:
300
+
301
+ ```bash
302
+ # 1. Ensure clean working directory
303
+ git status
304
+
305
+ # 2. Run smoke test manually
306
+ pnpm smoke-test
307
+
308
+ # 3. Bump version
309
+ pnpm version patch # or minor/major
310
+
311
+ # 4. Update docs
312
+ # Edit README.md "Last Updated" date
313
+
314
+ # 5. Commit and tag
315
+ git add .
316
+ git commit -m "chore: release v0.1.1"
317
+ git tag -a v0.1.1 -m "Release v0.1.1"
318
+
319
+ # 6. Push
320
+ git push origin main --tags
321
+ ```
322
+
323
+ ---
324
+
325
+ ### Release Checklist
326
+
327
+ Before creating a release:
328
+
329
+ - [ ] All smoke tests passing
330
+ - [ ] README.md tool count updated (if tools changed)
331
+ - [ ] CHANGELOG.md updated with release notes
332
+ - [ ] No open critical bugs
333
+ - [ ] Documentation up to date
334
+ - [ ] Examples tested
335
+
336
+ ---
337
+
338
+ ## Monitoring & Health Checks
339
+
340
+ ### Automated Health Checks
341
+
342
+ #### GitHub Actions CI
343
+
344
+ Monitors:
345
+ - Every PR merge
346
+ - Every push to main branch
347
+ - Node.js 18.x and 20.x compatibility
348
+
349
+ **Check Status**: https://github.com/your-org/creatoria-miniapp-mcp/actions
350
+
351
+ ---
352
+
353
+ #### Smoke Test Coverage
354
+
355
+ The smoke test validates:
356
+
357
+ 1. **Build**: TypeScript compilation
358
+ 2. **Type Check**: tsc --noEmit
359
+ 3. **Unit Tests**: 354 tests across all tool categories
360
+ 4. **Tool Count**: Exactly 65 tools registered
361
+ 5. **Lint**: ESLint with 0 errors
362
+ 6. **Format**: Prettier compliance
363
+
364
+ **Run Locally**:
365
+ ```bash
366
+ pnpm smoke-test
367
+ ```
368
+
369
+ ---
370
+
371
+ ### Manual Health Checks
372
+
373
+ #### 1. Tool Registration Integrity
374
+
375
+ Verify tool count hasn't regressed:
376
+
377
+ ```bash
378
+ pnpm update-readme 2>&1 | grep "Total:"
379
+ # Expected: 📊 Total: 65 tools
380
+ ```
381
+
382
+ ---
383
+
384
+ #### 2. Session Cleanup
385
+
386
+ Verify session cleanup works correctly:
387
+
388
+ ```bash
389
+ # Run session tests
390
+ pnpm test tests/unit/session.test.ts
391
+ ```
392
+
393
+ **Expected**: All tests pass with proper cleanup logs
394
+
395
+ ---
396
+
397
+ #### 3. Example Scripts
398
+
399
+ Periodically run example scripts to ensure they work:
400
+
401
+ ```bash
402
+ # Set test project
403
+ export TEST_PROJECT_PATH="/path/to/test/miniprogram"
404
+
405
+ # Run basic example
406
+ npx tsx examples/scripts/01-basic-navigation.ts
407
+ ```
408
+
409
+ ---
410
+
411
+ ## Backup & Recovery
412
+
413
+ ### What to Backup
414
+
415
+ 1. **Source Code**: Stored in Git (GitHub)
416
+ 2. **Configuration Files**:
417
+ - `.mcp.json` (user-specific, not in git)
418
+ - `package.json`
419
+ - `tsconfig.json`
420
+ - `.eslintrc.cjs`
421
+
422
+ 3. **Documentation**: All in git under `docs/`
423
+
424
+ 4. **Test Artifacts** (optional):
425
+ - `.mcp-artifacts/` (generated, can be recreated)
426
+
427
+ ---
428
+
429
+ ### Recovery Procedures
430
+
431
+ #### Recover from Git
432
+
433
+ ```bash
434
+ # Clone fresh repository
435
+ git clone https://github.com/your-org/creatoria-miniapp-mcp.git
436
+ cd creatoria-miniapp-mcp
437
+
438
+ # Install dependencies
439
+ pnpm install
440
+
441
+ # Build
442
+ pnpm build
443
+
444
+ # Verify
445
+ pnpm smoke-test
446
+ ```
447
+
448
+ ---
449
+
450
+ #### Recover Lost Configuration
451
+
452
+ If `.mcp.json` is lost:
453
+
454
+ ```json
455
+ // Create new .mcp.json
456
+ {
457
+ "projectPath": "/path/to/your/miniprogram",
458
+ "cliPath": "/Applications/wechatwebdevtools.app/Contents/MacOS/cli",
459
+ "port": 9420
460
+ }
461
+ ```
462
+
463
+ ---
464
+
465
+ ## Performance Tuning
466
+
467
+ ### Identify Slow Tests
468
+
469
+ ```bash
470
+ # Run tests with verbose timing
471
+ pnpm test:unit --verbose | grep -E "PASS|FAIL|\\([0-9]+\\s*ms\\)"
472
+ ```
473
+
474
+ **Action Thresholds**:
475
+ - Test > 1 second: Investigate and optimize
476
+ - Test suite > 10 seconds: Review test structure
477
+
478
+ ---
479
+
480
+ ### Optimize Session Cleanup
481
+
482
+ Default session timeout: 30 minutes
483
+
484
+ **Reduce timeout for faster cleanup**:
485
+ ```javascript
486
+ // In server config
487
+ {
488
+ sessionTimeout: 10 * 60 * 1000 // 10 minutes
489
+ }
490
+ ```
491
+
492
+ **Trade-off**: Shorter timeout = more frequent cleanups, but less idle time tolerance
493
+
494
+ ---
495
+
496
+ ### Tool Call Optimization
497
+
498
+ Use element references to avoid repeated queries:
499
+
500
+ ```javascript
501
+ // ❌ Slow: Query element each time
502
+ await element_tap({ selector: '.btn' })
503
+ await element_get_text({ selector: '.btn' })
504
+
505
+ // ✅ Fast: Query once, use refId
506
+ const btn = await page_query({ selector: '.btn', save: true })
507
+ await element_tap({ refId: btn.refId })
508
+ await element_get_text({ refId: btn.refId })
509
+ ```
510
+
511
+ ---
512
+
513
+ ## Security Updates
514
+
515
+ ### Vulnerability Response Process
516
+
517
+ 1. **Detection**: `pnpm audit` or GitHub Dependabot alert
518
+
519
+ 2. **Assessment**:
520
+ - Severity: Critical/High/Moderate/Low
521
+ - Exploitability: Is the vulnerable code path used?
522
+ - Availability of fix: Is patch available?
523
+
524
+ 3. **Response Timeline**:
525
+ - **Critical**: Fix within 24 hours
526
+ - **High**: Fix within 1 week
527
+ - **Moderate**: Fix in next release cycle
528
+ - **Low**: Track for future update
529
+
530
+ 4. **Fix Application**:
531
+ ```bash
532
+ # Update vulnerable package
533
+ pnpm update <package-name>@<safe-version>
534
+
535
+ # Run full test suite
536
+ pnpm smoke-test
537
+
538
+ # Create hotfix PR
539
+ git checkout -b security/fix-<vulnerability-id>
540
+ git commit -m "security: fix <vulnerability-description>"
541
+ ```
542
+
543
+ 5. **Release**:
544
+ - Create patch release if critical/high
545
+ - Include in regular release if moderate/low
546
+
547
+ ---
548
+
549
+ ### Regular Security Practices
550
+
551
+ - [ ] Enable Dependabot alerts on GitHub
552
+ - [ ] Review `pnpm audit` output weekly
553
+ - [ ] Keep Node.js updated to LTS versions
554
+ - [ ] Subscribe to security advisories for critical dependencies
555
+
556
+ ---
557
+
558
+ ## Troubleshooting
559
+
560
+ ### Common Maintenance Issues
561
+
562
+ #### Issue: Smoke Test Fails After Dependency Update
563
+
564
+ **Symptoms**:
565
+ ```bash
566
+ $ pnpm smoke-test
567
+ ❌ Unit Tests FAILED
568
+ ```
569
+
570
+ **Diagnosis**:
571
+ ```bash
572
+ # Run tests with verbose output
573
+ pnpm test:unit --verbose
574
+
575
+ # Check for breaking changes in updated packages
576
+ git diff HEAD~1 package.json
577
+ ```
578
+
579
+ **Resolution**:
580
+ 1. Identify which dependency caused failure
581
+ 2. Check changelog for breaking changes
582
+ 3. Update code to accommodate changes
583
+ 4. Or revert update: `pnpm install <package>@<previous-version>`
584
+
585
+ ---
586
+
587
+ #### Issue: Tool Count Mismatch
588
+
589
+ **Symptoms**:
590
+ ```bash
591
+ $ pnpm update-readme
592
+ ❌ Expected 65 tools, found 63
593
+ ```
594
+
595
+ **Diagnosis**:
596
+ ```bash
597
+ # Check which tools are missing
598
+ pnpm update-readme 2>&1 | less
599
+ ```
600
+
601
+ **Resolution**:
602
+ 1. Verify all tool files in `src/tools/` are exporting tools correctly
603
+ 2. Check `src/tools/index.ts` registration
604
+ 3. Ensure CATEGORY_METADATA matches tool arrays
605
+
606
+ ---
607
+
608
+ #### Issue: Build Fails on CI but Passes Locally
609
+
610
+ **Symptoms**: GitHub Actions fail, local build succeeds
611
+
612
+ **Common Causes**:
613
+ - Node version mismatch
614
+ - Missing environment variables
615
+ - File system case sensitivity (macOS vs Linux)
616
+
617
+ **Resolution**:
618
+ ```bash
619
+ # Test with same Node version as CI
620
+ nvm use 20
621
+
622
+ # Clean install
623
+ rm -rf node_modules pnpm-lock.yaml
624
+ pnpm install
625
+
626
+ # Build
627
+ pnpm build
628
+ ```
629
+
630
+ ---
631
+
632
+ #### Issue: Release Script Fails
633
+
634
+ **Symptoms**:
635
+ ```bash
636
+ $ pnpm release:patch
637
+ ❌ Uncommitted changes detected
638
+ ```
639
+
640
+ **Resolution**:
641
+ ```bash
642
+ # Commit or stash changes first
643
+ git status
644
+ git add .
645
+ git commit -m "chore: prepare for release"
646
+
647
+ # Retry release
648
+ pnpm release:patch
649
+ ```
650
+
651
+ ---
652
+
653
+ ## Additional Resources
654
+
655
+ ### Documentation
656
+
657
+ - [Troubleshooting Guide](./troubleshooting.md) - Common issues and solutions
658
+ - [Contributing Guide](../CONTRIBUTING.md) - How to contribute
659
+ - [Architecture](./architecture.md) - System design overview
660
+ - [API Reference](./api/README.md) - Complete tool documentation
661
+
662
+ ### External Resources
663
+
664
+ - [MCP Specification](https://modelcontextprotocol.io/)
665
+ - [miniprogram-automator Docs](https://developers.weixin.qq.com/miniprogram/dev/devtools/auto/)
666
+ - [TypeScript Handbook](https://www.typescriptlang.org/docs/)
667
+ - [Jest Documentation](https://jestjs.io/docs/getting-started)
668
+
669
+ ---
670
+
671
+ ## Getting Help
672
+
673
+ If you encounter issues not covered in this guide:
674
+
675
+ 1. **Check Existing Issues**: [GitHub Issues](https://github.com/your-org/creatoria-miniapp-mcp/issues)
676
+ 2. **Start Discussion**: [GitHub Discussions](https://github.com/your-org/creatoria-miniapp-mcp/discussions)
677
+ 3. **Contact Maintainers**: Open an issue with `question` label
678
+
679
+ ---
680
+
681
+ **Last Updated**: 2025-10-03
682
+ **Next Review**: 2026-01-03 (Quarterly)
@@ -0,0 +1,53 @@
1
+ # Playwright MCP 调研
2
+
3
+ ## 仓库定位与分发形态
4
+ - `microsoft/playwright-mcp` 提供的是一个 **薄封装**,入口文件 `index.js` 只导出 `createConnection`,实际逻辑来自 Playwright 主仓库内的 `playwright/lib/mcp/index`。
5
+ - CLI (`cli.js`) 调用 `playwright/lib/mcp/program`,负责解析命令行并挂接 Playwright 提供的标准命令体系。
6
+ - `src/README.md` 明确说明源码已经迁移至 Playwright monorepo;当前仓库主要承载 NPM 包装、文档与发行物。
7
+ - NPM 包通过 `bin.mcp-server-playwright` 暴露命令行,同时支持 `exports`(默认 CommonJS、类型定义 `index.d.ts`)。
8
+ - `package.json` 指向 Playwright alpha 版本依赖(`playwright` 与 `playwright-core` 一致版本),并依赖 `@modelcontextprotocol/sdk`、`zod-to-json-schema` 等生成工具。
9
+
10
+ ## Playwright 实现概览(位于 Playwright monorepo)
11
+ ### 服务器入口 (`lib/mcp/index.js`)
12
+ - `createConnection(config, contextGetter?)` 解析配置后创建 `BrowserServerBackend`,并通过 `createServer("Playwright", version, backend)` 生成 MCP Server。
13
+ - 支持自定义 `contextGetter`,默认使用 `contextFactory` 根据配置创建浏览器上下文。
14
+
15
+ ### 浏览器上下文工厂 (`lib/mcp/browser/browserContextFactory.js`)
16
+ - 根据配置选择不同工厂:
17
+ - `PersistentContextFactory`:持久化 profile,默认模式。
18
+ - `IsolatedContextFactory`:每次会话全新 profile,适合测试。
19
+ - `RemoteContextFactory` 与 `CdpContextFactory`:分别连接 Playwright 远程服务或已有浏览器(CDP)。
20
+ - `SharedContextFactory`:多个客户端复用同一个浏览器上下文。
21
+ - 负责注入初始化脚本、管理 userDataDir、处理追踪(trace/video)保存、CDP 端口注入等。
22
+
23
+ ### 服务后端 (`lib/mcp/browser/browserServerBackend.js`)
24
+ - 在 `initialize` 中创建 `Context`(见下),并构建工具清单。
25
+ - `callTool`:根据工具名称查找定义、校验参数(Zod schema),执行并收集响应(日志、输出、错误)。
26
+
27
+ ### 会话上下文 (`lib/mcp/browser/context.js`)
28
+ - 管理 Playwright `BrowserContext` 生命周期:
29
+ - 懒加载创建(含网络拦截、init script、trace、session log)。
30
+ - 维护标签页 `Tab` 列表、当前标签切换、关闭逻辑。
31
+ - `InputRecorder` 记录用户操作(避免工具执行时干扰)。
32
+ - `outputFile` / `lookupSecret` 等辅助能力。
33
+ - 根据配置启用网络白名单/黑名单、trace/live 截图等。
34
+
35
+ ### 工具体系 (`lib/mcp/browser/tools/*`)
36
+ - 工具根据能力分组:核心自动化(导航、选择、点击、输入、截图)、标签管理、安装浏览器、坐标点击(vision 能力)、PDF、Tracing、Verify 等。
37
+ - 文档 (`README.md`) 中的工具清单由 `update-readme.js` 读取工具 schema 自动生成,确保与实现同步。
38
+
39
+ ## 配置与运行模式
40
+ - CLI 支持丰富参数:浏览器选择、CDP/Remote 连接、白/黑名单、持久化目录、init script、权限、storage state、trace/video 输出、capabilities(`vision`/`pdf`/`tracing`/`verify`)等。
41
+ - 可作为本地 MCP (`stdio`)、HTTP 服务(`--port`)或通过浏览器扩展桥接现有浏览器会话。
42
+ - Profile 模式:持久化(默认)/隔离/扩展(Chrome 扩展 `extension/README.md` 说明)。
43
+
44
+ ## 构建与发布
45
+ - `scripts.roll` 会同步 Playwright 主仓库的 `config.d.ts` 到当前包,确保类型定义一致。
46
+ - 使用 Playwright Test (`playwright test`) 做端到端验证,并提供 Docker 构建脚本与 CI 工作流。
47
+
48
+ ## 对小程序 MCP 项目的启发
49
+ 1. **工具粒度与文档生成**:Playwright 通过中心化 schema(Zod)定义工具,自动生成 README 与客户端说明;我们也可以复用这一思路,为小程序工具集提供机器可解析的描述与自动文档。
50
+ 2. **上下文管理模式**:`Context` 统一管理会话状态、标签与资源回收,适合迁移到 miniprogram-automator(例如管理 IDE 进程、页面栈、元素引用缓存)。
51
+ 3. **配置分层**:支持 CLI 参数、配置文件、环境变量三层合并(`resolveConfig`),可借鉴用于管理小程序项目路径、端口、Mock 配置等。
52
+ 4. **扩展能力开关**:通过 `capabilities` 控制额外工具(vision/pdf/tracing),小程序侧可类比启用录制、网络桩、真机远程等特性。
53
+ 5. **会话产物输出**:Playwright MCP 自动保存 trace/video/session log;我们可将截图、页面数据、断言结果统一输出,便于调试与 CI。