mcp-probe-kit 1.15.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +113 -1642
  2. package/build/index.js +75 -42
  3. package/build/lib/elicitation-helper.d.ts +73 -0
  4. package/build/lib/elicitation-helper.js +130 -0
  5. package/build/lib/response.d.ts +32 -0
  6. package/build/lib/response.js +28 -0
  7. package/build/lib/tasks-manager.d.ts +116 -0
  8. package/build/lib/tasks-manager.js +217 -0
  9. package/build/lib/toolset-manager.d.ts +48 -0
  10. package/build/lib/toolset-manager.js +112 -0
  11. package/build/schemas/basic-tools.d.ts +0 -32
  12. package/build/schemas/basic-tools.js +0 -34
  13. package/build/schemas/code-analysis-tools.d.ts +0 -36
  14. package/build/schemas/code-analysis-tools.js +0 -38
  15. package/build/schemas/code-gen-tools.d.ts +0 -44
  16. package/build/schemas/code-gen-tools.js +0 -46
  17. package/build/schemas/doc-util-tools.d.ts +0 -54
  18. package/build/schemas/doc-util-tools.js +0 -58
  19. package/build/schemas/index.d.ts +0 -188
  20. package/build/schemas/orchestration-tools.d.ts +0 -22
  21. package/build/schemas/orchestration-tools.js +0 -23
  22. package/build/schemas/output/core-tools.d.ts +817 -0
  23. package/build/schemas/output/core-tools.js +421 -0
  24. package/build/schemas/output/generation-tools.d.ts +936 -0
  25. package/build/schemas/output/generation-tools.js +446 -0
  26. package/build/schemas/output/helper-tools.d.ts +243 -0
  27. package/build/schemas/output/helper-tools.js +138 -0
  28. package/build/schemas/output/index.d.ts +76 -0
  29. package/build/schemas/output/index.js +96 -0
  30. package/build/schemas/output/project-tools.d.ts +702 -0
  31. package/build/schemas/output/project-tools.js +339 -0
  32. package/build/schemas/output/ui-ux-tools.d.ts +469 -0
  33. package/build/schemas/output/ui-ux-tools.js +218 -0
  34. package/build/schemas/output/workflow-tools.d.ts +267 -0
  35. package/build/schemas/output/workflow-tools.js +179 -0
  36. package/build/schemas/structured-output.d.ts +1317 -0
  37. package/build/schemas/structured-output.js +1017 -0
  38. package/build/tools/__tests__/start_ui.integration.test.js +5 -5
  39. package/build/tools/__tests__/start_ui.property.test.js +11 -11
  40. package/build/tools/add_feature.d.ts +1 -13
  41. package/build/tools/add_feature.js +48 -13
  42. package/build/tools/analyze_project.js +57 -18
  43. package/build/tools/check_deps.d.ts +1 -13
  44. package/build/tools/check_deps.js +24 -15
  45. package/build/tools/code_review.d.ts +1 -13
  46. package/build/tools/code_review.js +19 -16
  47. package/build/tools/debug.d.ts +1 -13
  48. package/build/tools/debug.js +18 -16
  49. package/build/tools/estimate.d.ts +1 -19
  50. package/build/tools/estimate.js +36 -6
  51. package/build/tools/fix_bug.d.ts +1 -13
  52. package/build/tools/fix_bug.js +24 -6
  53. package/build/tools/gen_mock.d.ts +1 -19
  54. package/build/tools/gen_mock.js +42 -227
  55. package/build/tools/genapi.d.ts +1 -13
  56. package/build/tools/genapi.js +18 -15
  57. package/build/tools/genchangelog.d.ts +1 -13
  58. package/build/tools/genchangelog.js +36 -212
  59. package/build/tools/gencommit.d.ts +1 -7
  60. package/build/tools/gencommit.js +21 -13
  61. package/build/tools/gendoc.d.ts +1 -13
  62. package/build/tools/gendoc.js +18 -15
  63. package/build/tools/genpr.d.ts +1 -13
  64. package/build/tools/genpr.js +28 -157
  65. package/build/tools/genreadme.d.ts +1 -13
  66. package/build/tools/genreadme.js +22 -587
  67. package/build/tools/gensql.d.ts +1 -13
  68. package/build/tools/gensql.js +24 -283
  69. package/build/tools/gentest.d.ts +1 -13
  70. package/build/tools/gentest.js +49 -16
  71. package/build/tools/index.d.ts +0 -10
  72. package/build/tools/index.js +0 -10
  73. package/build/tools/init_component_catalog.d.ts +3 -20
  74. package/build/tools/init_component_catalog.js +141 -786
  75. package/build/tools/init_project.d.ts +7 -13
  76. package/build/tools/init_project.js +54 -16
  77. package/build/tools/init_project_context.d.ts +1 -13
  78. package/build/tools/init_project_context.js +41 -14
  79. package/build/tools/perf.d.ts +1 -13
  80. package/build/tools/perf.js +18 -15
  81. package/build/tools/refactor.d.ts +1 -13
  82. package/build/tools/refactor.js +54 -15
  83. package/build/tools/render_ui.d.ts +2 -19
  84. package/build/tools/render_ui.js +201 -347
  85. package/build/tools/resolve_conflict.d.ts +1 -13
  86. package/build/tools/resolve_conflict.js +18 -15
  87. package/build/tools/security_scan.d.ts +1 -13
  88. package/build/tools/security_scan.js +16 -5
  89. package/build/tools/start_api.d.ts +7 -13
  90. package/build/tools/start_api.js +69 -157
  91. package/build/tools/start_bugfix.d.ts +1 -7
  92. package/build/tools/start_bugfix.js +38 -2
  93. package/build/tools/start_doc.d.ts +7 -13
  94. package/build/tools/start_doc.js +76 -169
  95. package/build/tools/start_feature.d.ts +1 -7
  96. package/build/tools/start_feature.js +54 -2
  97. package/build/tools/start_onboard.d.ts +1 -7
  98. package/build/tools/start_onboard.js +40 -2
  99. package/build/tools/start_ralph.d.ts +1 -7
  100. package/build/tools/start_ralph.js +88 -2
  101. package/build/tools/start_refactor.d.ts +7 -13
  102. package/build/tools/start_refactor.js +75 -148
  103. package/build/tools/start_release.d.ts +7 -13
  104. package/build/tools/start_release.js +56 -131
  105. package/build/tools/start_review.d.ts +7 -13
  106. package/build/tools/start_review.js +70 -142
  107. package/build/tools/start_ui.d.ts +1 -7
  108. package/build/tools/start_ui.js +98 -8
  109. package/build/tools/ui-ux-tools.d.ts +3 -39
  110. package/build/tools/ui-ux-tools.js +201 -125
  111. package/docs/data/tools.js +864 -0
  112. package/docs/index.html +594 -0
  113. package/docs/pages/all-tools.html +649 -0
  114. package/docs/pages/examples.html +564 -0
  115. package/docs/pages/getting-started.html +529 -0
  116. package/docs/pages/migration.html +308 -0
  117. package/docs/specs/algorithm-enhancement/roadmap.md +619 -0
  118. package/docs/specs/vnext-upgrade/00-OVERVIEW.md +258 -0
  119. package/docs/specs/vnext-upgrade/BETA_RELEASE_GUIDE.md +328 -0
  120. package/docs/specs/vnext-upgrade/GITHUB_DISCUSSION_TEMPLATE.md +236 -0
  121. package/docs/specs/vnext-upgrade/M8.9-PROGRESS-UPDATE.md +248 -0
  122. package/docs/specs/vnext-upgrade/PROGRESS-SUMMARY.md +195 -0
  123. package/docs/specs/vnext-upgrade/QUICK_REFERENCE.md +338 -0
  124. package/docs/specs/vnext-upgrade/README.md +125 -0
  125. package/docs/specs/vnext-upgrade/STATUS-UPDATE-2026-01-26.md +230 -0
  126. package/docs/specs/vnext-upgrade/TOOL_CLEANUP.md +343 -0
  127. package/docs/specs/vnext-upgrade/completed/M1-M2-SUMMARY.md +27 -0
  128. package/docs/specs/vnext-upgrade/completed/M3_COMPLETION_SUMMARY.md +273 -0
  129. package/docs/specs/vnext-upgrade/completed/M4-SUMMARY.md +19 -0
  130. package/docs/specs/vnext-upgrade/completed/M5_COMPLETION_SUMMARY.md +0 -0
  131. package/docs/specs/vnext-upgrade/completed/M8.1-SUMMARY.md +247 -0
  132. package/docs/specs/vnext-upgrade/completed/M8.2-SUMMARY.md +296 -0
  133. package/docs/specs/vnext-upgrade/completed/M8.3-SUMMARY.md +241 -0
  134. package/docs/specs/vnext-upgrade/completed/M8.3-TEST-SUMMARY.md +216 -0
  135. package/docs/specs/vnext-upgrade/completed/M8.4-SUMMARY.md +217 -0
  136. package/docs/specs/vnext-upgrade/completed/M8.4-TEST-SUMMARY.md +198 -0
  137. package/docs/specs/vnext-upgrade/completed/M8.5-SUMMARY.md +202 -0
  138. package/docs/specs/vnext-upgrade/completed/M8.5-TEST-SUMMARY.md +223 -0
  139. package/docs/specs/vnext-upgrade/completed/M8.6-SUMMARY.md +299 -0
  140. package/docs/specs/vnext-upgrade/completed/M8.8-TEST-SUMMARY.md +216 -0
  141. package/docs/specs/vnext-upgrade/completed/TOOL-CLEANUP-SUMMARY.md +210 -0
  142. package/docs/specs/vnext-upgrade/design.md +848 -0
  143. package/docs/specs/vnext-upgrade/requirements.md +221 -0
  144. package/docs/specs/vnext-upgrade/tasks/00-INDEX.md +335 -0
  145. package/docs/specs/vnext-upgrade/tasks/M8.1-SCHEMA-DEFINITION.md +300 -0
  146. package/docs/specs/vnext-upgrade/tasks/M8.2-P1-TOOLS.md +249 -0
  147. package/docs/specs/vnext-upgrade/tasks/M8.3-GENERATION-TOOLS.md +49 -0
  148. package/docs/specs/vnext-upgrade/tasks/M8.4-ORCHESTRATION-TOOLS.md +28 -0
  149. package/docs/specs/vnext-upgrade/tasks/M8.5-PROJECT-TOOLS.md +29 -0
  150. package/docs/specs/vnext-upgrade/tasks/M8.6-UI-TOOLS.md +66 -0
  151. package/docs/specs/vnext-upgrade/tasks/M8.7-HELPER-TOOLS.md +24 -0
  152. package/docs/specs/vnext-upgrade/tasks/M8.8-INTEGRATION-TESTS.md +90 -0
  153. package/docs/specs/vnext-upgrade/tasks/M8.9-DOCUMENTATION.md +103 -0
  154. package/docs/styles/docs.css +556 -0
  155. package/docs/styles/page.css +815 -0
  156. package/docs/vnext/MCP_2025-11-25_GUIDE.md +276 -0
  157. package/docs/vnext/vNext-PRD.md +488 -0
  158. package/package.json +6 -6
  159. package/docs/BEST_PRACTICES.md +0 -1185
  160. package/docs/HOW_TO_TRIGGER.md +0 -1141
  161. package/docs/MCP-Probe-Kit-/344/275/277/347/224/250/346/211/213/345/206/214.html +0 -544
  162. package/docs/MCP-Probe-Kit-/344/275/277/347/224/250/346/211/213/345/206/214.md +0 -1447
@@ -0,0 +1,848 @@
1
+ # vNext 架构升级 - 设计文档
2
+
3
+ ## 📐 技术架构
4
+
5
+ ### 整体架构图
6
+
7
+ ```
8
+ ┌─────────────────────────────────────────────────────────────┐
9
+ │ MCP Probe Kit v2.0 │
10
+ │ (MCP Protocol 2025-11-25) │
11
+ └─────────────────────────────────────────────────────────────┘
12
+
13
+
14
+ ┌─────────────────────────────────────────────────────────────┐
15
+ │ 工具集过滤层 │
16
+ │ ┌──────────┬──────────┬──────────┬──────────┐ │
17
+ │ │ full │ core │ ui │ workflow │ │
18
+ │ │ (49工具) │ (15工具) │ (10工具) │ (25工具) │ │
19
+ │ └──────────┴──────────┴──────────┴──────────┘ │
20
+ └─────────────────────────────────────────────────────────────┘
21
+
22
+
23
+ ┌─────────────────────────────────────────────────────────────┐
24
+ │ 统一输出封装层 │
25
+ │ ┌────────────────────────────────────────────┐ │
26
+ │ │ okText(text, meta?) │ │
27
+ │ │ okStructured({schema, data, textFallback})│ │
28
+ │ └────────────────────────────────────────────┘ │
29
+ └─────────────────────────────────────────────────────────────┘
30
+
31
+
32
+ ┌─────────────────────────────────────────────────────────────┐
33
+ │ 工具执行层 │
34
+ │ ┌──────────────┬──────────────┬──────────────┐ │
35
+ │ │ 基础工具 │ 编排工具 │ UI/UX工具 │ │
36
+ │ │ (37个) │ (9个) │ (3个) │ │
37
+ │ └──────────────┴──────────────┴──────────────┘ │
38
+ └─────────────────────────────────────────────────────────────┘
39
+
40
+
41
+ ┌─────────────────────────────────────────────────────────────┐
42
+ │ 高级功能层 │
43
+ │ ┌──────────────┬──────────────┬──────────────┐ │
44
+ │ │ Tasks API │ Elicitation │ Schema验证 │ │
45
+ │ │ (长任务) │ (表单/URL) │ (结构化) │ │
46
+ │ └──────────────┴──────────────┴──────────────┘ │
47
+ └─────────────────────────────────────────────────────────────┘
48
+ ```
49
+
50
+ ## 🏗️ 核心组件设计
51
+
52
+ ### 1. 工具集管理器(Toolset Manager)
53
+
54
+ **职责:** 根据环境变量过滤和组织工具列表
55
+
56
+ **接口:**
57
+ ```typescript
58
+ interface ToolsetManager {
59
+ // 获取当前工具集配置
60
+ getCurrentToolset(): ToolsetType;
61
+
62
+ // 根据工具集过滤工具列表
63
+ filterTools(allTools: Tool[], toolset: ToolsetType): Tool[];
64
+
65
+ // 检查工具是否在当前工具集中
66
+ isToolAvailable(toolName: string, toolset: ToolsetType): boolean;
67
+ }
68
+
69
+ type ToolsetType = 'full' | 'core' | 'ui' | 'workflow';
70
+ ```
71
+
72
+ **工具集定义:**
73
+
74
+ ```typescript
75
+ const TOOLSET_DEFINITIONS = {
76
+ // 核心工具集(15个)- 日常高频使用
77
+ core: [
78
+ 'interview',
79
+ 'ask_user',
80
+ 'init_project_context',
81
+ 'analyze_project',
82
+ 'code_review',
83
+ 'security_scan',
84
+ 'perf',
85
+ 'debug',
86
+ 'fix',
87
+ 'gentest',
88
+ 'genapi',
89
+ 'genpr',
90
+ 'gencommit', // 必须包含
91
+ 'estimate',
92
+ 'start_bugfix', // 至少一个编排入口
93
+ ],
94
+
95
+ // UI/UX 工具集(6个)- 基于 ui-ux-pro-max-skill + json-render
96
+ ui: [
97
+ 'start_ui', // ⭐ 统一入口(推荐)
98
+ 'ui_search', // BM25 搜索(基于 ui-ux-pro-max-skill)
99
+ 'ui_design_system', // 设计系统生成(基于 ui-ux-pro-max-skill)
100
+ 'design2code', // 设计稿转代码
101
+ 'genui', // 通用 UI 生成
102
+ 'sync_ui_data', // 数据同步
103
+ // 注意:init_component_catalog 和 render_ui 作为 start_ui 的内部步骤
104
+ // 不在 ui toolset 暴露,但在 full 模式下仍可用
105
+ ],
106
+
107
+ // 工作流工具集(25-30个)- 推荐给 AI 代理
108
+ workflow: [
109
+ // P0 编排入口
110
+ 'start_feature',
111
+ 'start_onboard',
112
+ 'start_bugfix',
113
+ 'start_ui',
114
+ 'start_ralph',
115
+
116
+ // 其他编排工具
117
+ 'start_review',
118
+ 'start_release',
119
+ 'start_refactor',
120
+ 'start_api',
121
+ 'start_doc',
122
+
123
+ // 关键依赖基础工具(最小闭环)
124
+ 'interview',
125
+ 'ask_user',
126
+ 'init_project_context',
127
+ 'analyze_project',
128
+ 'add_feature',
129
+ 'estimate',
130
+ 'code_review',
131
+ 'security_scan',
132
+ 'perf',
133
+ 'debug',
134
+ 'fix',
135
+ 'gentest',
136
+ 'gencommit',
137
+ 'genpr',
138
+ 'genchangelog',
139
+ 'genapi',
140
+ 'gen_mock',
141
+ 'design2code',
142
+ 'ui_design_system',
143
+ 'ui_search',
144
+ ],
145
+
146
+ // 完整工具集(49个)- 默认,向后兼容
147
+ full: 'all', // 特殊标记,表示所有工具
148
+ };
149
+ ```
150
+
151
+ **UI 工具简化说明**:
152
+ - v1.15 有 9 个 UI 工具,用户经常困惑该用哪个
153
+ - v2.0 在 `ui` toolset 中只暴露 6 个对外工具
154
+ - `init_component_catalog` 和 `render_ui` 作为 `start_ui` 的内部步骤隐藏
155
+ - 推荐用户使用 `start_ui` 作为统一入口
156
+ - 详见:[UI 工具简化策略](./ui-tools-strategy.md)
157
+
158
+ ### 2. 统一输出封装(Response Helpers)
159
+
160
+ **职责:** 确保所有工具输出同时包含人类可读文本和机器可读结构
161
+
162
+ **实现:**
163
+
164
+ ```typescript
165
+ // src/lib/response.ts
166
+
167
+ /**
168
+ * 返回纯文本响应(向后兼容)
169
+ */
170
+ export function okText(text: string, meta?: Record<string, any>) {
171
+ return {
172
+ content: [{ type: "text", text }],
173
+ _meta: meta,
174
+ };
175
+ }
176
+
177
+ /**
178
+ * 返回结构化响应(新版)
179
+ * @param schema - JSON Schema 定义
180
+ * @param data - 符合 schema 的数据
181
+ * @param textFallback - 人类可读的文本(必填,用于旧客户端)
182
+ */
183
+ export function okStructured<T>({
184
+ schema,
185
+ data,
186
+ textFallback,
187
+ meta,
188
+ }: {
189
+ schema: object;
190
+ data: T;
191
+ textFallback: string;
192
+ meta?: Record<string, any>;
193
+ }) {
194
+ return {
195
+ content: [{ type: "text", text: textFallback }],
196
+ structuredContent: data,
197
+ _meta: {
198
+ ...meta,
199
+ schema,
200
+ },
201
+ };
202
+ }
203
+
204
+ /**
205
+ * 返回错误响应
206
+ */
207
+ export function errorResponse(message: string, details?: any) {
208
+ return {
209
+ content: [{ type: "text", text: `❌ 错误: ${message}` }],
210
+ isError: true,
211
+ _meta: { error: details },
212
+ };
213
+ }
214
+ ```
215
+
216
+ ### 3. Schema 定义(Schemas)
217
+
218
+ **职责:** 定义核心数据结构的 JSON Schema
219
+
220
+ #### 3.1 WorkflowReport Schema
221
+
222
+ ```typescript
223
+ // src/schemas/workflow-report.ts
224
+
225
+ export const WorkflowReportSchema = {
226
+ type: "object",
227
+ properties: {
228
+ workflowName: {
229
+ type: "string",
230
+ description: "工作流名称(如 start_bugfix)",
231
+ },
232
+ summary: {
233
+ type: "string",
234
+ description: "一句话总结",
235
+ },
236
+ steps: {
237
+ type: "array",
238
+ description: "执行步骤",
239
+ items: {
240
+ type: "object",
241
+ properties: {
242
+ name: { type: "string" },
243
+ status: {
244
+ type: "string",
245
+ enum: ["pending", "running", "completed", "failed", "skipped"]
246
+ },
247
+ input: { type: "object" },
248
+ outputs: { type: "array" },
249
+ notes: { type: "string" },
250
+ duration: { type: "number" },
251
+ },
252
+ required: ["name", "status"],
253
+ },
254
+ },
255
+ artifacts: {
256
+ type: "array",
257
+ description: "产出物",
258
+ items: {
259
+ type: "object",
260
+ properties: {
261
+ type: {
262
+ type: "string",
263
+ enum: ["file", "code", "config", "doc", "test"]
264
+ },
265
+ path: { type: "string" },
266
+ description: { type: "string" },
267
+ contentPreview: { type: "string" },
268
+ },
269
+ required: ["type", "path", "description"],
270
+ },
271
+ },
272
+ risks: {
273
+ type: "array",
274
+ description: "风险点",
275
+ items: {
276
+ type: "object",
277
+ properties: {
278
+ level: { type: "string", enum: ["low", "medium", "high"] },
279
+ description: { type: "string" },
280
+ mitigation: { type: "string" },
281
+ },
282
+ },
283
+ },
284
+ assumptions: {
285
+ type: "array",
286
+ description: "假设条件",
287
+ items: { type: "string" },
288
+ },
289
+ nextActions: {
290
+ type: "array",
291
+ description: "下一步建议",
292
+ items: {
293
+ type: "object",
294
+ properties: {
295
+ priority: { type: "number" },
296
+ action: { type: "string" },
297
+ reason: { type: "string" },
298
+ },
299
+ required: ["priority", "action"],
300
+ },
301
+ },
302
+ timestamps: {
303
+ type: "object",
304
+ properties: {
305
+ started: { type: "string", format: "date-time" },
306
+ completed: { type: "string", format: "date-time" },
307
+ },
308
+ },
309
+ },
310
+ required: ["workflowName", "summary", "steps", "nextActions"],
311
+ };
312
+
313
+ export interface WorkflowReport {
314
+ workflowName: string;
315
+ summary: string;
316
+ steps: WorkflowStep[];
317
+ artifacts?: Artifact[];
318
+ risks?: Risk[];
319
+ assumptions?: string[];
320
+ nextActions: NextAction[];
321
+ timestamps?: {
322
+ started: string;
323
+ completed?: string;
324
+ };
325
+ }
326
+ ```
327
+
328
+ #### 3.2 CommitMessage Schema
329
+
330
+ ```typescript
331
+ // src/schemas/commit-message.ts
332
+
333
+ export const CommitMessageSchema = {
334
+ type: "object",
335
+ properties: {
336
+ type: {
337
+ type: "string",
338
+ enum: ["feat", "fix", "docs", "style", "refactor", "test", "chore", "perf", "build", "ci", "revert"],
339
+ description: "提交类型",
340
+ },
341
+ scope: {
342
+ type: "string",
343
+ description: "影响范围(可选)",
344
+ },
345
+ subject: {
346
+ type: "string",
347
+ description: "简短描述",
348
+ },
349
+ body: {
350
+ type: "string",
351
+ description: "详细描述(可选)",
352
+ },
353
+ breaking: {
354
+ type: "boolean",
355
+ description: "是否包含破坏性更改",
356
+ },
357
+ footers: {
358
+ type: "array",
359
+ description: "页脚信息(如 Closes #123)",
360
+ items: { type: "string" },
361
+ },
362
+ finalMessage: {
363
+ type: "string",
364
+ description: "完整的提交消息(可直接复制)",
365
+ },
366
+ },
367
+ required: ["type", "subject", "finalMessage"],
368
+ };
369
+
370
+ export interface CommitMessage {
371
+ type: string;
372
+ scope?: string;
373
+ subject: string;
374
+ body?: string;
375
+ breaking: boolean;
376
+ footers?: string[];
377
+ finalMessage: string;
378
+ }
379
+ ```
380
+
381
+ ### 4. Tasks 管理器(Tasks Manager)
382
+
383
+ **职责:** 管理长时运行任务的生命周期
384
+
385
+ **实现:**
386
+
387
+ ```typescript
388
+ // src/lib/tasks-manager.ts
389
+
390
+ interface Task {
391
+ taskId: string;
392
+ status: 'queued' | 'working' | 'input_required' | 'completed' | 'failed' | 'cancelled';
393
+ statusMessage?: string;
394
+ createdAt: string;
395
+ lastUpdatedAt: string;
396
+ ttl?: number;
397
+ pollInterval?: number;
398
+ result?: any;
399
+ error?: any;
400
+ }
401
+
402
+ export class TasksManager {
403
+ private tasks: Map<string, Task> = new Map();
404
+
405
+ /**
406
+ * 创建新任务
407
+ */
408
+ createTask(ttl?: number): Task {
409
+ const taskId = crypto.randomUUID();
410
+ const task: Task = {
411
+ taskId,
412
+ status: 'queued',
413
+ createdAt: new Date().toISOString(),
414
+ lastUpdatedAt: new Date().toISOString(),
415
+ ttl,
416
+ pollInterval: 5000, // 5秒
417
+ };
418
+
419
+ this.tasks.set(taskId, task);
420
+ return task;
421
+ }
422
+
423
+ /**
424
+ * 更新任务状态
425
+ */
426
+ updateTask(taskId: string, updates: Partial<Task>): Task | null {
427
+ const task = this.tasks.get(taskId);
428
+ if (!task) return null;
429
+
430
+ Object.assign(task, updates, {
431
+ lastUpdatedAt: new Date().toISOString(),
432
+ });
433
+
434
+ return task;
435
+ }
436
+
437
+ /**
438
+ * 获取任务
439
+ */
440
+ getTask(taskId: string): Task | null {
441
+ return this.tasks.get(taskId) || null;
442
+ }
443
+
444
+ /**
445
+ * 取消任务
446
+ */
447
+ cancelTask(taskId: string): boolean {
448
+ const task = this.tasks.get(taskId);
449
+ if (!task || task.status === 'completed' || task.status === 'failed') {
450
+ return false;
451
+ }
452
+
453
+ task.status = 'cancelled';
454
+ task.lastUpdatedAt = new Date().toISOString();
455
+ return true;
456
+ }
457
+
458
+ /**
459
+ * 清理过期任务
460
+ */
461
+ cleanupExpiredTasks(): void {
462
+ const now = Date.now();
463
+ for (const [taskId, task] of this.tasks.entries()) {
464
+ if (task.ttl) {
465
+ const createdTime = new Date(task.createdAt).getTime();
466
+ if (now - createdTime > task.ttl) {
467
+ this.tasks.delete(taskId);
468
+ }
469
+ }
470
+ }
471
+ }
472
+ }
473
+ ```
474
+
475
+ ### 5. Elicitation 处理器(Elicitation Handler)
476
+
477
+ **职责:** 处理表单式提问和 URL 引导
478
+
479
+ **实现:**
480
+
481
+ ```typescript
482
+ // src/lib/elicitation-handler.ts
483
+
484
+ interface ElicitationRequest {
485
+ mode: 'form' | 'url';
486
+ message: string;
487
+ requestedSchema?: object; // form 模式
488
+ url?: string; // url 模式
489
+ elicitationId?: string; // url 模式
490
+ }
491
+
492
+ export class ElicitationHandler {
493
+ /**
494
+ * 创建表单式提问
495
+ */
496
+ createFormElicitation(message: string, schema: object) {
497
+ return {
498
+ mode: 'form',
499
+ message,
500
+ requestedSchema: schema,
501
+ };
502
+ }
503
+
504
+ /**
505
+ * 创建 URL 引导
506
+ */
507
+ createUrlElicitation(message: string, url: string, elicitationId: string) {
508
+ return {
509
+ mode: 'url',
510
+ message,
511
+ url,
512
+ elicitationId,
513
+ };
514
+ }
515
+
516
+ /**
517
+ * 检测客户端是否支持 Elicitation
518
+ */
519
+ isSupported(capabilities: any): boolean {
520
+ return capabilities?.elicitation === true;
521
+ }
522
+
523
+ /**
524
+ * 回退到文本提问
525
+ */
526
+ fallbackToText(message: string, options?: string[]): string {
527
+ let text = `❓ ${message}\n\n`;
528
+
529
+ if (options && options.length > 0) {
530
+ text += '可选项:\n';
531
+ options.forEach((opt, i) => {
532
+ text += `${i + 1}. ${opt}\n`;
533
+ });
534
+ }
535
+
536
+ text += '\n请回答:';
537
+ return text;
538
+ }
539
+ }
540
+ ```
541
+
542
+ ## 🔄 工具迁移策略
543
+
544
+ ### P0 工具迁移优先级
545
+
546
+ 1. **gencommit** - 最高优先级,必须保留且增强
547
+ 2. **start_bugfix** - 高频使用,需要 Tasks 支持
548
+ 3. **start_feature** - 高频使用,需要 Tasks 支持
549
+ 4. **start_ui** - UI 工作流核心,统一入口
550
+ 5. **start_onboard** - 新用户入口
551
+ 6. **start_ralph** - 循环开发核心
552
+
553
+ ### UI 工具特殊说明
554
+
555
+ **start_ui 的角色变化**:
556
+ - v1.15:9 个 UI 工具之一
557
+ - v2.0:UI 工具集的统一入口(推荐)
558
+
559
+ **内部工具处理**:
560
+ - `init_component_catalog` 和 `render_ui` 不在 `ui` toolset 暴露
561
+ - 但 `start_ui` 内部仍可调用它们
562
+ - 在 `full` 模式下用户仍可直接访问
563
+
564
+ **迁移影响**:
565
+ - 使用 `full` 模式(默认):无影响
566
+ - 使用 `ui` 模式:推荐改用 `start_ui`
567
+
568
+ ### 迁移步骤(以 gencommit 为例)
569
+
570
+ **Before(当前):**
571
+ ```typescript
572
+ export async function gencommit(args: any) {
573
+ const message = `生成的提交消息...`;
574
+ return {
575
+ content: [{ type: "text", text: message }],
576
+ };
577
+ }
578
+ ```
579
+
580
+ **After(v2.0):**
581
+ ```typescript
582
+ import { okStructured } from '../lib/response.js';
583
+ import { CommitMessageSchema } from '../schemas/commit-message.js';
584
+
585
+ export async function gencommit(args: any) {
586
+ // 1. 分析变更
587
+ const analysis = analyzeChanges(args);
588
+
589
+ // 2. 生成结构化数据
590
+ const commitData: CommitMessage = {
591
+ type: analysis.type,
592
+ scope: analysis.scope,
593
+ subject: analysis.subject,
594
+ body: analysis.body,
595
+ breaking: analysis.breaking,
596
+ footers: analysis.footers,
597
+ finalMessage: formatCommitMessage(analysis),
598
+ };
599
+
600
+ // 3. 生成人类可读文本
601
+ const textFallback = `
602
+ 📝 生成的提交消息:
603
+
604
+ ${commitData.finalMessage}
605
+
606
+ ---
607
+ 类型: ${commitData.type}
608
+ ${commitData.scope ? `范围: ${commitData.scope}` : ''}
609
+ ${commitData.breaking ? '⚠️ 包含破坏性更改' : ''}
610
+ `.trim();
611
+
612
+ // 4. 返回结构化响应
613
+ return okStructured({
614
+ schema: CommitMessageSchema,
615
+ data: commitData,
616
+ textFallback,
617
+ });
618
+ }
619
+ ```
620
+
621
+ ## 🧪 测试策略
622
+
623
+ ### 1. 契约测试(Contract Tests)
624
+
625
+ 确保工具输出符合 schema:
626
+
627
+ ```typescript
628
+ // tests/contracts/gencommit.test.ts
629
+
630
+ import { describe, it, expect } from 'vitest';
631
+ import { gencommit } from '../src/tools/gencommit.js';
632
+ import { CommitMessageSchema } from '../src/schemas/commit-message.js';
633
+ import Ajv from 'ajv';
634
+
635
+ describe('gencommit 契约测试', () => {
636
+ const ajv = new Ajv();
637
+ const validate = ajv.compile(CommitMessageSchema);
638
+
639
+ it('应该返回符合 schema 的结构化内容', async () => {
640
+ const result = await gencommit({ changes: 'test changes' });
641
+
642
+ // 验证包含 content.text
643
+ expect(result.content).toBeDefined();
644
+ expect(result.content[0].text).toBeTruthy();
645
+
646
+ // 验证 structuredContent 符合 schema
647
+ expect(result.structuredContent).toBeDefined();
648
+ const valid = validate(result.structuredContent);
649
+ expect(valid).toBe(true);
650
+ });
651
+
652
+ it('应该包含 finalMessage 字段', async () => {
653
+ const result = await gencommit({ changes: 'test changes' });
654
+ expect(result.structuredContent.finalMessage).toBeTruthy();
655
+ });
656
+ });
657
+ ```
658
+
659
+ ### 2. 集成测试(Integration Tests)
660
+
661
+ 测试工具集过滤:
662
+
663
+ ```typescript
664
+ // tests/integration/toolset.test.ts
665
+
666
+ describe('工具集过滤', () => {
667
+ it('core 工具集应该包含 gencommit', () => {
668
+ const tools = filterTools(allTools, 'core');
669
+ const hasGencommit = tools.some(t => t.name === 'gencommit');
670
+ expect(hasGencommit).toBe(true);
671
+ });
672
+
673
+ it('workflow 工具集应该包含所有 P0 start_* 工具', () => {
674
+ const tools = filterTools(allTools, 'workflow');
675
+ const p0Tools = ['start_feature', 'start_bugfix', 'start_ui', 'start_onboard', 'start_ralph'];
676
+
677
+ p0Tools.forEach(toolName => {
678
+ const hasTool = tools.some(t => t.name === toolName);
679
+ expect(hasTool).toBe(true);
680
+ });
681
+ });
682
+ });
683
+ ```
684
+
685
+ ### 3. 兼容性测试(Compatibility Tests)
686
+
687
+ 确保向后兼容:
688
+
689
+ ```typescript
690
+ // tests/compatibility/backward-compat.test.ts
691
+
692
+ describe('向后兼容性', () => {
693
+ it('所有工具都应该返回 content.text', async () => {
694
+ for (const tool of allTools) {
695
+ const result = await tool.handler({});
696
+ expect(result.content).toBeDefined();
697
+ expect(result.content[0].text).toBeTruthy();
698
+ }
699
+ });
700
+
701
+ it('full 模式应该包含所有 49 个工具', () => {
702
+ const tools = filterTools(allTools, 'full');
703
+ expect(tools.length).toBe(49);
704
+ });
705
+ });
706
+ ```
707
+
708
+ ## 📊 性能考虑
709
+
710
+ ### 1. 工具列表缓存
711
+
712
+ ```typescript
713
+ // 缓存过滤后的工具列表
714
+ const toolsetCache = new Map<ToolsetType, Tool[]>();
715
+
716
+ function getFilteredTools(toolset: ToolsetType): Tool[] {
717
+ if (toolsetCache.has(toolset)) {
718
+ return toolsetCache.get(toolset)!;
719
+ }
720
+
721
+ const filtered = filterTools(allTools, toolset);
722
+ toolsetCache.set(toolset, filtered);
723
+ return filtered;
724
+ }
725
+ ```
726
+
727
+ ### 2. Schema 验证优化
728
+
729
+ ```typescript
730
+ // 预编译 schema 验证器
731
+ const validators = new Map<string, ValidateFunction>();
732
+
733
+ function getValidator(schemaName: string): ValidateFunction {
734
+ if (!validators.has(schemaName)) {
735
+ const schema = schemas[schemaName];
736
+ validators.set(schemaName, ajv.compile(schema));
737
+ }
738
+ return validators.get(schemaName)!;
739
+ }
740
+ ```
741
+
742
+ ## 🔐 安全考虑
743
+
744
+ ### 1. 敏感信息处理
745
+
746
+ - **不在表单中收集敏感信息**(token/密码/密钥)
747
+ - 使用 URL 模式引导到安全页面
748
+ - 在文档中明确标注安全最佳实践
749
+
750
+ ### 2. 输入验证
751
+
752
+ ```typescript
753
+ // 验证用户输入
754
+ function validateInput(input: any, schema: object): boolean {
755
+ const validate = ajv.compile(schema);
756
+ return validate(input);
757
+ }
758
+ ```
759
+
760
+ ## 📝 配置管理
761
+
762
+ ### 环境变量
763
+
764
+ ```bash
765
+ # 工具集选择
766
+ MCP_TOOLSET=full|core|ui|workflow # 默认: full
767
+
768
+ # 调试模式
769
+ MCP_DEBUG=1 # 启用详细日志
770
+
771
+ # 显示所有工具(调试用)
772
+ MCP_SHOW_ALL=1 # 忽略工具集过滤
773
+ ```
774
+
775
+ ### 配置文件示例
776
+
777
+ ```json
778
+ {
779
+ "mcpServers": {
780
+ "mcp-probe-kit": {
781
+ "command": "npx",
782
+ "args": ["mcp-probe-kit@2.0.0"],
783
+ "env": {
784
+ "MCP_TOOLSET": "workflow"
785
+ }
786
+ }
787
+ }
788
+ }
789
+ ```
790
+
791
+ **UI 工具集配置示例**:
792
+
793
+ ```json
794
+ {
795
+ "mcpServers": {
796
+ "mcp-probe-kit-ui": {
797
+ "command": "npx",
798
+ "args": ["mcp-probe-kit@2.0.0"],
799
+ "env": {
800
+ "MCP_TOOLSET": "ui"
801
+ }
802
+ }
803
+ }
804
+ }
805
+ ```
806
+
807
+ **说明**:
808
+ - `ui` 模式只显示 6 个 UI 工具
809
+ - 推荐使用 `start_ui` 作为统一入口
810
+ - 内部工具(`init_component_catalog`, `render_ui`)不可见
811
+ - 如需访问内部工具,使用 `full` 模式(默认)
812
+
813
+ ## 🚀 部署策略
814
+
815
+ ### Beta 发布
816
+
817
+ 1. 发布 `mcp-probe-kit@2.0.0-beta.1`
818
+ 2. 在 README 中添加 beta 测试说明
819
+ 3. 收集用户反馈
820
+ 4. 修复问题并发布 beta.2, beta.3...
821
+
822
+ ### 稳定版发布
823
+
824
+ 1. 所有 P0 功能完成
825
+ 2. 通过所有测试
826
+ 3. 文档完整
827
+ 4. 至少 2 周 beta 测试期
828
+ 5. 发布 `mcp-probe-kit@2.0.0`
829
+
830
+ ## 📚 文档更新
831
+
832
+ ### 需要更新的文档
833
+
834
+ 1. **README.md** - 添加工具集配置说明
835
+ 2. **CHANGELOG.md** - 详细的变更日志
836
+ 3. **MIGRATION.md** - 从 v1.x 迁移指南
837
+ 4. **API.md** - 新的 API 文档
838
+ 5. **SCHEMAS.md** - Schema 定义文档
839
+ 6. **COMPATIBILITY.md** - 客户端兼容性矩阵
840
+
841
+ ## 🔄 回滚计划
842
+
843
+ 如果 v2.0 出现严重问题:
844
+
845
+ 1. 立即发布 v1.15.1(修复版本)
846
+ 2. 在 npm 上将 `latest` 标签指向 v1.15.1
847
+ 3. 在 README 中添加警告
848
+ 4. 修复 v2.0 问题后重新发布 v2.0.1