@defai.digital/mcp-server 13.0.3
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.
- package/LICENSE +214 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +7 -0
- package/dist/bin.js.map +1 -0
- package/dist/bootstrap.d.ts +89 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +161 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/rate-limiter.d.ts +136 -0
- package/dist/middleware/rate-limiter.d.ts.map +1 -0
- package/dist/middleware/rate-limiter.js +262 -0
- package/dist/middleware/rate-limiter.js.map +1 -0
- package/dist/prompts/agent-guide.d.ts +16 -0
- package/dist/prompts/agent-guide.d.ts.map +1 -0
- package/dist/prompts/agent-guide.js +391 -0
- package/dist/prompts/agent-guide.js.map +1 -0
- package/dist/prompts/explain-workflow.d.ts +15 -0
- package/dist/prompts/explain-workflow.d.ts.map +1 -0
- package/dist/prompts/explain-workflow.js +157 -0
- package/dist/prompts/explain-workflow.js.map +1 -0
- package/dist/prompts/index.d.ts +39 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +83 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/review-changes.d.ts +15 -0
- package/dist/prompts/review-changes.d.ts.map +1 -0
- package/dist/prompts/review-changes.js +102 -0
- package/dist/prompts/review-changes.js.map +1 -0
- package/dist/prompts/troubleshoot-session.d.ts +15 -0
- package/dist/prompts/troubleshoot-session.d.ts.map +1 -0
- package/dist/prompts/troubleshoot-session.js +156 -0
- package/dist/prompts/troubleshoot-session.js.map +1 -0
- package/dist/registry-accessor.d.ts +83 -0
- package/dist/registry-accessor.d.ts.map +1 -0
- package/dist/registry-accessor.js +153 -0
- package/dist/registry-accessor.js.map +1 -0
- package/dist/resources/agents.d.ts +40 -0
- package/dist/resources/agents.d.ts.map +1 -0
- package/dist/resources/agents.js +123 -0
- package/dist/resources/agents.js.map +1 -0
- package/dist/resources/config.d.ts +57 -0
- package/dist/resources/config.d.ts.map +1 -0
- package/dist/resources/config.js +222 -0
- package/dist/resources/config.js.map +1 -0
- package/dist/resources/index.d.ts +38 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +132 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/policies.d.ts +40 -0
- package/dist/resources/policies.d.ts.map +1 -0
- package/dist/resources/policies.js +122 -0
- package/dist/resources/policies.js.map +1 -0
- package/dist/resources/sessions.d.ts +30 -0
- package/dist/resources/sessions.d.ts.map +1 -0
- package/dist/resources/sessions.js +64 -0
- package/dist/resources/sessions.js.map +1 -0
- package/dist/resources/workflows.d.ts +40 -0
- package/dist/resources/workflows.d.ts.map +1 -0
- package/dist/resources/workflows.js +143 -0
- package/dist/resources/workflows.js.map +1 -0
- package/dist/schema-registry.d.ts +23 -0
- package/dist/schema-registry.d.ts.map +1 -0
- package/dist/schema-registry.js +225 -0
- package/dist/schema-registry.js.map +1 -0
- package/dist/server.d.ts +63 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +393 -0
- package/dist/server.js.map +1 -0
- package/dist/session-accessor.d.ts +23 -0
- package/dist/session-accessor.d.ts.map +1 -0
- package/dist/session-accessor.js +39 -0
- package/dist/session-accessor.js.map +1 -0
- package/dist/shared-registry.d.ts +23 -0
- package/dist/shared-registry.d.ts.map +1 -0
- package/dist/shared-registry.js +235 -0
- package/dist/shared-registry.js.map +1 -0
- package/dist/stdio.d.ts +6 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +152 -0
- package/dist/stdio.js.map +1 -0
- package/dist/tool-namespacing.d.ts +28 -0
- package/dist/tool-namespacing.d.ts.map +1 -0
- package/dist/tool-namespacing.js +80 -0
- package/dist/tool-namespacing.js.map +1 -0
- package/dist/tools/ability.d.ts +55 -0
- package/dist/tools/ability.d.ts.map +1 -0
- package/dist/tools/ability.js +560 -0
- package/dist/tools/ability.js.map +1 -0
- package/dist/tools/agent.d.ts +73 -0
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/agent.js +895 -0
- package/dist/tools/agent.js.map +1 -0
- package/dist/tools/config.d.ts +36 -0
- package/dist/tools/config.d.ts.map +1 -0
- package/dist/tools/config.js +265 -0
- package/dist/tools/config.js.map +1 -0
- package/dist/tools/design.d.ts +42 -0
- package/dist/tools/design.d.ts.map +1 -0
- package/dist/tools/design.js +736 -0
- package/dist/tools/design.js.map +1 -0
- package/dist/tools/discuss.d.ts +40 -0
- package/dist/tools/discuss.d.ts.map +1 -0
- package/dist/tools/discuss.js +331 -0
- package/dist/tools/discuss.js.map +1 -0
- package/dist/tools/file-system.d.ts +63 -0
- package/dist/tools/file-system.d.ts.map +1 -0
- package/dist/tools/file-system.js +513 -0
- package/dist/tools/file-system.js.map +1 -0
- package/dist/tools/guard.d.ts +29 -0
- package/dist/tools/guard.d.ts.map +1 -0
- package/dist/tools/guard.js +311 -0
- package/dist/tools/guard.js.map +1 -0
- package/dist/tools/index.d.ts +35 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +178 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/memory.d.ts +101 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/memory.js +704 -0
- package/dist/tools/memory.js.map +1 -0
- package/dist/tools/orchestration.d.ts +58 -0
- package/dist/tools/orchestration.d.ts.map +1 -0
- package/dist/tools/orchestration.js +714 -0
- package/dist/tools/orchestration.js.map +1 -0
- package/dist/tools/review.d.ts +40 -0
- package/dist/tools/review.d.ts.map +1 -0
- package/dist/tools/review.js +319 -0
- package/dist/tools/review.js.map +1 -0
- package/dist/tools/scaffold.d.ts +27 -0
- package/dist/tools/scaffold.d.ts.map +1 -0
- package/dist/tools/scaffold.js +495 -0
- package/dist/tools/scaffold.js.map +1 -0
- package/dist/tools/session.d.ts +75 -0
- package/dist/tools/session.d.ts.map +1 -0
- package/dist/tools/session.js +749 -0
- package/dist/tools/session.js.map +1 -0
- package/dist/tools/telemetry.d.ts +58 -0
- package/dist/tools/telemetry.d.ts.map +1 -0
- package/dist/tools/telemetry.js +638 -0
- package/dist/tools/telemetry.js.map +1 -0
- package/dist/tools/trace.d.ts +29 -0
- package/dist/tools/trace.d.ts.map +1 -0
- package/dist/tools/trace.js +191 -0
- package/dist/tools/trace.js.map +1 -0
- package/dist/tools/workflow.d.ts +26 -0
- package/dist/tools/workflow.d.ts.map +1 -0
- package/dist/tools/workflow.js +269 -0
- package/dist/tools/workflow.js.map +1 -0
- package/dist/trace-wrapper.d.ts +79 -0
- package/dist/trace-wrapper.d.ts.map +1 -0
- package/dist/trace-wrapper.js +151 -0
- package/dist/trace-wrapper.js.map +1 -0
- package/dist/types.d.ts +185 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/artifact-store.d.ts +49 -0
- package/dist/utils/artifact-store.d.ts.map +1 -0
- package/dist/utils/artifact-store.js +102 -0
- package/dist/utils/artifact-store.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/response.d.ts +139 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/utils/response.js +293 -0
- package/dist/utils/response.js.map +1 -0
- package/dist/validation.d.ts +223 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +372 -0
- package/dist/validation.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
/**
|
|
3
|
+
* API design tool definition
|
|
4
|
+
*/
|
|
5
|
+
export const designApiTool = {
|
|
6
|
+
name: 'design_api',
|
|
7
|
+
description: 'Generate API design artifacts (OpenAPI/AsyncAPI specifications)',
|
|
8
|
+
idempotent: true,
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
name: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: 'API name',
|
|
15
|
+
},
|
|
16
|
+
description: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'API description',
|
|
19
|
+
},
|
|
20
|
+
endpoints: {
|
|
21
|
+
type: 'array',
|
|
22
|
+
description: 'List of API endpoints',
|
|
23
|
+
items: {
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
path: { type: 'string' },
|
|
27
|
+
method: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
|
|
30
|
+
},
|
|
31
|
+
summary: { type: 'string' },
|
|
32
|
+
description: { type: 'string' },
|
|
33
|
+
},
|
|
34
|
+
required: ['path', 'method', 'summary'],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
baseUrl: {
|
|
38
|
+
type: 'string',
|
|
39
|
+
description: 'Base URL for the API',
|
|
40
|
+
},
|
|
41
|
+
version: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
description: 'API version',
|
|
44
|
+
default: '1.0.0',
|
|
45
|
+
},
|
|
46
|
+
format: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
description: 'Output format (openapi, asyncapi)',
|
|
49
|
+
enum: ['openapi', 'asyncapi'],
|
|
50
|
+
default: 'openapi',
|
|
51
|
+
},
|
|
52
|
+
outputPath: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
description: 'Optional file path to write the design',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
required: ['name', 'endpoints'],
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Component design tool definition
|
|
62
|
+
*/
|
|
63
|
+
export const designComponentTool = {
|
|
64
|
+
name: 'design_component',
|
|
65
|
+
description: 'Generate component design (interface, implementation skeleton)',
|
|
66
|
+
idempotent: true,
|
|
67
|
+
inputSchema: {
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: {
|
|
70
|
+
name: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
description: 'Component name',
|
|
73
|
+
},
|
|
74
|
+
type: {
|
|
75
|
+
type: 'string',
|
|
76
|
+
description: 'Component type',
|
|
77
|
+
enum: [
|
|
78
|
+
'function',
|
|
79
|
+
'class',
|
|
80
|
+
'module',
|
|
81
|
+
'service',
|
|
82
|
+
'controller',
|
|
83
|
+
'repository',
|
|
84
|
+
'factory',
|
|
85
|
+
'adapter',
|
|
86
|
+
'hook',
|
|
87
|
+
'component',
|
|
88
|
+
'other',
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
description: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
description: 'Component description and purpose',
|
|
94
|
+
},
|
|
95
|
+
inputs: {
|
|
96
|
+
type: 'array',
|
|
97
|
+
description: 'Input parameters',
|
|
98
|
+
items: {
|
|
99
|
+
type: 'object',
|
|
100
|
+
properties: {
|
|
101
|
+
name: { type: 'string' },
|
|
102
|
+
type: { type: 'string' },
|
|
103
|
+
description: { type: 'string' },
|
|
104
|
+
required: { type: 'boolean', default: true },
|
|
105
|
+
},
|
|
106
|
+
required: ['name', 'type'],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
outputs: {
|
|
110
|
+
type: 'array',
|
|
111
|
+
description: 'Output values',
|
|
112
|
+
items: {
|
|
113
|
+
type: 'object',
|
|
114
|
+
properties: {
|
|
115
|
+
name: { type: 'string' },
|
|
116
|
+
type: { type: 'string' },
|
|
117
|
+
description: { type: 'string' },
|
|
118
|
+
},
|
|
119
|
+
required: ['name', 'type'],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
dependencies: {
|
|
123
|
+
type: 'array',
|
|
124
|
+
description: 'Dependencies (packages, services)',
|
|
125
|
+
items: { type: 'string' },
|
|
126
|
+
},
|
|
127
|
+
patterns: {
|
|
128
|
+
type: 'array',
|
|
129
|
+
description: 'Design patterns to apply',
|
|
130
|
+
items: { type: 'string' },
|
|
131
|
+
},
|
|
132
|
+
language: {
|
|
133
|
+
type: 'string',
|
|
134
|
+
description: 'Programming language',
|
|
135
|
+
enum: ['typescript', 'javascript', 'python', 'go', 'rust', 'java', 'other'],
|
|
136
|
+
default: 'typescript',
|
|
137
|
+
},
|
|
138
|
+
outputPath: {
|
|
139
|
+
type: 'string',
|
|
140
|
+
description: 'Optional file path to write the design',
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
required: ['name', 'type', 'description'],
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Schema design tool definition
|
|
148
|
+
*/
|
|
149
|
+
export const designSchemaTool = {
|
|
150
|
+
name: 'design_schema',
|
|
151
|
+
description: 'Generate data schema design (Zod, JSON Schema, TypeScript types)',
|
|
152
|
+
idempotent: true,
|
|
153
|
+
inputSchema: {
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: {
|
|
156
|
+
name: {
|
|
157
|
+
type: 'string',
|
|
158
|
+
description: 'Schema name',
|
|
159
|
+
},
|
|
160
|
+
description: {
|
|
161
|
+
type: 'string',
|
|
162
|
+
description: 'Schema description',
|
|
163
|
+
},
|
|
164
|
+
fields: {
|
|
165
|
+
type: 'array',
|
|
166
|
+
description: 'Schema fields',
|
|
167
|
+
items: {
|
|
168
|
+
type: 'object',
|
|
169
|
+
properties: {
|
|
170
|
+
name: { type: 'string' },
|
|
171
|
+
type: {
|
|
172
|
+
type: 'string',
|
|
173
|
+
enum: [
|
|
174
|
+
'string',
|
|
175
|
+
'number',
|
|
176
|
+
'integer',
|
|
177
|
+
'boolean',
|
|
178
|
+
'array',
|
|
179
|
+
'object',
|
|
180
|
+
'null',
|
|
181
|
+
'date',
|
|
182
|
+
'datetime',
|
|
183
|
+
'uuid',
|
|
184
|
+
'email',
|
|
185
|
+
'url',
|
|
186
|
+
'enum',
|
|
187
|
+
'ref',
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
description: { type: 'string' },
|
|
191
|
+
required: { type: 'boolean', default: false },
|
|
192
|
+
nullable: { type: 'boolean', default: false },
|
|
193
|
+
enumValues: {
|
|
194
|
+
type: 'array',
|
|
195
|
+
items: { type: 'string' },
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
required: ['name', 'type'],
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
format: {
|
|
202
|
+
type: 'string',
|
|
203
|
+
description: 'Output format',
|
|
204
|
+
enum: ['zod', 'json-schema', 'typescript', 'prisma', 'drizzle'],
|
|
205
|
+
default: 'zod',
|
|
206
|
+
},
|
|
207
|
+
outputPath: {
|
|
208
|
+
type: 'string',
|
|
209
|
+
description: 'Optional file path to write the schema',
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
required: ['name', 'fields'],
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Architecture design tool definition
|
|
217
|
+
*/
|
|
218
|
+
export const designArchitectureTool = {
|
|
219
|
+
name: 'design_architecture',
|
|
220
|
+
description: 'Generate architecture design diagrams and documentation',
|
|
221
|
+
idempotent: true,
|
|
222
|
+
inputSchema: {
|
|
223
|
+
type: 'object',
|
|
224
|
+
properties: {
|
|
225
|
+
name: {
|
|
226
|
+
type: 'string',
|
|
227
|
+
description: 'Architecture name',
|
|
228
|
+
},
|
|
229
|
+
description: {
|
|
230
|
+
type: 'string',
|
|
231
|
+
description: 'Architecture description',
|
|
232
|
+
},
|
|
233
|
+
pattern: {
|
|
234
|
+
type: 'string',
|
|
235
|
+
description: 'Architecture pattern',
|
|
236
|
+
enum: [
|
|
237
|
+
'hexagonal',
|
|
238
|
+
'clean',
|
|
239
|
+
'layered',
|
|
240
|
+
'microservices',
|
|
241
|
+
'event-driven',
|
|
242
|
+
'cqrs',
|
|
243
|
+
'ddd',
|
|
244
|
+
'mvc',
|
|
245
|
+
'mvvm',
|
|
246
|
+
'pipe-filter',
|
|
247
|
+
'other',
|
|
248
|
+
],
|
|
249
|
+
},
|
|
250
|
+
components: {
|
|
251
|
+
type: 'array',
|
|
252
|
+
description: 'Architecture components',
|
|
253
|
+
items: {
|
|
254
|
+
type: 'object',
|
|
255
|
+
properties: {
|
|
256
|
+
id: { type: 'string' },
|
|
257
|
+
name: { type: 'string' },
|
|
258
|
+
type: {
|
|
259
|
+
type: 'string',
|
|
260
|
+
enum: [
|
|
261
|
+
'domain',
|
|
262
|
+
'application',
|
|
263
|
+
'infrastructure',
|
|
264
|
+
'presentation',
|
|
265
|
+
'adapter',
|
|
266
|
+
'port',
|
|
267
|
+
'service',
|
|
268
|
+
'database',
|
|
269
|
+
'queue',
|
|
270
|
+
'cache',
|
|
271
|
+
'external',
|
|
272
|
+
],
|
|
273
|
+
},
|
|
274
|
+
description: { type: 'string' },
|
|
275
|
+
dependencies: {
|
|
276
|
+
type: 'array',
|
|
277
|
+
items: { type: 'string' },
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
required: ['id', 'name', 'type'],
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
format: {
|
|
284
|
+
type: 'string',
|
|
285
|
+
description: 'Output format for diagram',
|
|
286
|
+
enum: ['mermaid', 'plantuml', 'markdown', 'c4'],
|
|
287
|
+
default: 'mermaid',
|
|
288
|
+
},
|
|
289
|
+
outputPath: {
|
|
290
|
+
type: 'string',
|
|
291
|
+
description: 'Optional file path to write the design',
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
required: ['name', 'description', 'pattern', 'components'],
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* Design list tool definition
|
|
299
|
+
*/
|
|
300
|
+
export const designListTool = {
|
|
301
|
+
name: 'design_list',
|
|
302
|
+
description: 'List generated design artifacts',
|
|
303
|
+
idempotent: true,
|
|
304
|
+
inputSchema: {
|
|
305
|
+
type: 'object',
|
|
306
|
+
properties: {
|
|
307
|
+
type: {
|
|
308
|
+
type: 'string',
|
|
309
|
+
description: 'Filter by design type',
|
|
310
|
+
enum: ['api', 'component', 'schema', 'architecture', 'flow', 'data-model', 'interface', 'other'],
|
|
311
|
+
},
|
|
312
|
+
status: {
|
|
313
|
+
type: 'string',
|
|
314
|
+
description: 'Filter by status',
|
|
315
|
+
enum: ['draft', 'review', 'approved', 'implemented', 'deprecated'],
|
|
316
|
+
},
|
|
317
|
+
limit: {
|
|
318
|
+
type: 'number',
|
|
319
|
+
description: 'Maximum number of results',
|
|
320
|
+
default: 50,
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
// In-memory storage for design artifacts
|
|
326
|
+
const designStore = new Map();
|
|
327
|
+
/**
|
|
328
|
+
* Handler for design_api tool
|
|
329
|
+
*/
|
|
330
|
+
export const handleDesignApi = async (args) => {
|
|
331
|
+
const name = args.name;
|
|
332
|
+
const description = args.description ?? '';
|
|
333
|
+
const endpoints = args.endpoints;
|
|
334
|
+
const baseUrl = args.baseUrl ?? 'http://localhost:3000';
|
|
335
|
+
const version = args.version ?? '1.0.0';
|
|
336
|
+
const format = args.format ?? 'openapi';
|
|
337
|
+
try {
|
|
338
|
+
const designId = randomUUID();
|
|
339
|
+
// Generate OpenAPI spec
|
|
340
|
+
const openApiSpec = {
|
|
341
|
+
openapi: '3.0.3',
|
|
342
|
+
info: {
|
|
343
|
+
title: name,
|
|
344
|
+
description,
|
|
345
|
+
version,
|
|
346
|
+
},
|
|
347
|
+
servers: [{ url: baseUrl }],
|
|
348
|
+
paths: endpoints.reduce((acc, endpoint) => {
|
|
349
|
+
const path = endpoint.path;
|
|
350
|
+
if (acc[path] === undefined) {
|
|
351
|
+
acc[path] = {};
|
|
352
|
+
}
|
|
353
|
+
acc[path][endpoint.method.toLowerCase()] = {
|
|
354
|
+
summary: endpoint.summary,
|
|
355
|
+
description: endpoint.description,
|
|
356
|
+
responses: {
|
|
357
|
+
'200': { description: 'Successful response' },
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
return acc;
|
|
361
|
+
}, {}),
|
|
362
|
+
};
|
|
363
|
+
const content = JSON.stringify(openApiSpec, null, 2);
|
|
364
|
+
// Store design
|
|
365
|
+
designStore.set(designId, {
|
|
366
|
+
designId,
|
|
367
|
+
type: 'api',
|
|
368
|
+
format,
|
|
369
|
+
name,
|
|
370
|
+
description,
|
|
371
|
+
content,
|
|
372
|
+
status: 'draft',
|
|
373
|
+
createdAt: new Date().toISOString(),
|
|
374
|
+
});
|
|
375
|
+
return {
|
|
376
|
+
content: [
|
|
377
|
+
{
|
|
378
|
+
type: 'text',
|
|
379
|
+
text: JSON.stringify({
|
|
380
|
+
designId,
|
|
381
|
+
name,
|
|
382
|
+
format,
|
|
383
|
+
content,
|
|
384
|
+
createdAt: new Date().toISOString(),
|
|
385
|
+
}, null, 2),
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
392
|
+
return {
|
|
393
|
+
content: [
|
|
394
|
+
{
|
|
395
|
+
type: 'text',
|
|
396
|
+
text: JSON.stringify({
|
|
397
|
+
error: 'GENERATION_FAILED',
|
|
398
|
+
message,
|
|
399
|
+
name,
|
|
400
|
+
}),
|
|
401
|
+
},
|
|
402
|
+
],
|
|
403
|
+
isError: true,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
/**
|
|
408
|
+
* Handler for design_component tool
|
|
409
|
+
*/
|
|
410
|
+
export const handleDesignComponent = async (args) => {
|
|
411
|
+
const name = args.name;
|
|
412
|
+
const type = args.type;
|
|
413
|
+
const description = args.description;
|
|
414
|
+
const inputs = args.inputs ?? [];
|
|
415
|
+
const outputs = args.outputs ?? [];
|
|
416
|
+
const language = args.language ?? 'typescript';
|
|
417
|
+
try {
|
|
418
|
+
const designId = randomUUID();
|
|
419
|
+
// Generate TypeScript interface
|
|
420
|
+
const inputTypes = inputs.map((i) => ` ${i.name}${i.required === false ? '?' : ''}: ${i.type};`).join('\n');
|
|
421
|
+
const outputType = outputs.length > 0 ? outputs[0]?.type ?? 'void' : 'void';
|
|
422
|
+
const interfaceCode = `/**
|
|
423
|
+
* ${description}
|
|
424
|
+
*/
|
|
425
|
+
export interface ${name}Input {
|
|
426
|
+
${inputTypes || ' // No inputs defined'}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export interface ${name}Output {
|
|
430
|
+
${outputs.map((o) => ` ${o.name}: ${o.type};`).join('\n') || ' // No outputs defined'}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export interface I${name} {
|
|
434
|
+
execute(input: ${name}Input): Promise<${outputType}>;
|
|
435
|
+
}`;
|
|
436
|
+
const implementationCode = `import type { I${name}, ${name}Input, ${name}Output } from './${name}.interface.js';
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* ${description}
|
|
440
|
+
*
|
|
441
|
+
* TODO: Implement the business logic for this component.
|
|
442
|
+
*/
|
|
443
|
+
export class ${name} implements I${name} {
|
|
444
|
+
async execute(input: ${name}Input): Promise<${outputType}> {
|
|
445
|
+
// TODO: Replace this placeholder with actual implementation
|
|
446
|
+
console.warn('[${name}] Using placeholder implementation - real logic needed');
|
|
447
|
+
|
|
448
|
+
// Return a placeholder response indicating implementation is needed
|
|
449
|
+
// Remove this and implement actual business logic
|
|
450
|
+
return {
|
|
451
|
+
success: false,
|
|
452
|
+
message: '${name} implementation required',
|
|
453
|
+
input,
|
|
454
|
+
} as unknown as ${outputType};
|
|
455
|
+
}
|
|
456
|
+
}`;
|
|
457
|
+
const content = `// Interface\n${interfaceCode}\n\n// Implementation\n${implementationCode}`;
|
|
458
|
+
// Store design
|
|
459
|
+
designStore.set(designId, {
|
|
460
|
+
designId,
|
|
461
|
+
type: 'component',
|
|
462
|
+
format: language,
|
|
463
|
+
name,
|
|
464
|
+
description,
|
|
465
|
+
content,
|
|
466
|
+
status: 'draft',
|
|
467
|
+
createdAt: new Date().toISOString(),
|
|
468
|
+
});
|
|
469
|
+
return {
|
|
470
|
+
content: [
|
|
471
|
+
{
|
|
472
|
+
type: 'text',
|
|
473
|
+
text: JSON.stringify({
|
|
474
|
+
designId,
|
|
475
|
+
name,
|
|
476
|
+
type,
|
|
477
|
+
interface: interfaceCode,
|
|
478
|
+
implementation: implementationCode,
|
|
479
|
+
createdAt: new Date().toISOString(),
|
|
480
|
+
}, null, 2),
|
|
481
|
+
},
|
|
482
|
+
],
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
catch (error) {
|
|
486
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
487
|
+
return {
|
|
488
|
+
content: [
|
|
489
|
+
{
|
|
490
|
+
type: 'text',
|
|
491
|
+
text: JSON.stringify({
|
|
492
|
+
error: 'GENERATION_FAILED',
|
|
493
|
+
message,
|
|
494
|
+
name,
|
|
495
|
+
}),
|
|
496
|
+
},
|
|
497
|
+
],
|
|
498
|
+
isError: true,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
/**
|
|
503
|
+
* Handler for design_schema tool
|
|
504
|
+
*/
|
|
505
|
+
export const handleDesignSchema = async (args) => {
|
|
506
|
+
const name = args.name;
|
|
507
|
+
const description = args.description ?? '';
|
|
508
|
+
const fields = args.fields;
|
|
509
|
+
const format = args.format ?? 'zod';
|
|
510
|
+
try {
|
|
511
|
+
const designId = randomUUID();
|
|
512
|
+
// Generate Zod schema
|
|
513
|
+
const zodFieldMap = {
|
|
514
|
+
string: 'z.string()',
|
|
515
|
+
number: 'z.number()',
|
|
516
|
+
integer: 'z.number().int()',
|
|
517
|
+
boolean: 'z.boolean()',
|
|
518
|
+
array: 'z.array(z.unknown())',
|
|
519
|
+
object: 'z.object({})',
|
|
520
|
+
null: 'z.null()',
|
|
521
|
+
date: 'z.date()',
|
|
522
|
+
datetime: 'z.string().datetime()',
|
|
523
|
+
uuid: 'z.string().uuid()',
|
|
524
|
+
email: 'z.string().email()',
|
|
525
|
+
url: 'z.string().url()',
|
|
526
|
+
enum: 'z.enum([])',
|
|
527
|
+
ref: 'z.lazy(() => Schema)',
|
|
528
|
+
};
|
|
529
|
+
const schemaFields = fields
|
|
530
|
+
.map((f) => {
|
|
531
|
+
let zodType = zodFieldMap[f.type] ?? 'z.unknown()';
|
|
532
|
+
if (f.type === 'enum' && f.enumValues !== undefined && f.enumValues.length > 0) {
|
|
533
|
+
zodType = `z.enum([${f.enumValues.map((v) => `'${v}'`).join(', ')}])`;
|
|
534
|
+
}
|
|
535
|
+
if (f.nullable === true) {
|
|
536
|
+
zodType += '.nullable()';
|
|
537
|
+
}
|
|
538
|
+
if (f.required === false) {
|
|
539
|
+
zodType += '.optional()';
|
|
540
|
+
}
|
|
541
|
+
return ` ${f.name}: ${zodType},`;
|
|
542
|
+
})
|
|
543
|
+
.join('\n');
|
|
544
|
+
const content = `import { z } from 'zod';
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* ${description}
|
|
548
|
+
*/
|
|
549
|
+
export const ${name}Schema = z.object({
|
|
550
|
+
${schemaFields}
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
export type ${name} = z.infer<typeof ${name}Schema>;`;
|
|
554
|
+
// Store design
|
|
555
|
+
designStore.set(designId, {
|
|
556
|
+
designId,
|
|
557
|
+
type: 'schema',
|
|
558
|
+
format,
|
|
559
|
+
name,
|
|
560
|
+
description,
|
|
561
|
+
content,
|
|
562
|
+
status: 'draft',
|
|
563
|
+
createdAt: new Date().toISOString(),
|
|
564
|
+
});
|
|
565
|
+
return {
|
|
566
|
+
content: [
|
|
567
|
+
{
|
|
568
|
+
type: 'text',
|
|
569
|
+
text: JSON.stringify({
|
|
570
|
+
designId,
|
|
571
|
+
name,
|
|
572
|
+
format,
|
|
573
|
+
content,
|
|
574
|
+
createdAt: new Date().toISOString(),
|
|
575
|
+
}, null, 2),
|
|
576
|
+
},
|
|
577
|
+
],
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
catch (error) {
|
|
581
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
582
|
+
return {
|
|
583
|
+
content: [
|
|
584
|
+
{
|
|
585
|
+
type: 'text',
|
|
586
|
+
text: JSON.stringify({
|
|
587
|
+
error: 'GENERATION_FAILED',
|
|
588
|
+
message,
|
|
589
|
+
name,
|
|
590
|
+
}),
|
|
591
|
+
},
|
|
592
|
+
],
|
|
593
|
+
isError: true,
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
/**
|
|
598
|
+
* Handler for design_architecture tool
|
|
599
|
+
*/
|
|
600
|
+
export const handleDesignArchitecture = async (args) => {
|
|
601
|
+
const name = args.name;
|
|
602
|
+
const description = args.description;
|
|
603
|
+
const pattern = args.pattern;
|
|
604
|
+
const components = args.components;
|
|
605
|
+
const format = args.format ?? 'mermaid';
|
|
606
|
+
try {
|
|
607
|
+
const designId = randomUUID();
|
|
608
|
+
// Generate Mermaid diagram
|
|
609
|
+
const componentLines = components.map((c) => ` ${c.id}[${c.name}]`).join('\n');
|
|
610
|
+
const dependencyLines = components
|
|
611
|
+
.flatMap((c) => (c.dependencies ?? []).map((dep) => ` ${c.id} --> ${dep}`))
|
|
612
|
+
.join('\n');
|
|
613
|
+
const diagram = `graph TD
|
|
614
|
+
subgraph ${name}
|
|
615
|
+
${componentLines}
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
${dependencyLines}`;
|
|
619
|
+
const documentation = `# ${name}
|
|
620
|
+
|
|
621
|
+
## Overview
|
|
622
|
+
${description}
|
|
623
|
+
|
|
624
|
+
## Architecture Pattern
|
|
625
|
+
**${pattern}**
|
|
626
|
+
|
|
627
|
+
## Components
|
|
628
|
+
|
|
629
|
+
${components.map((c) => `### ${c.name}
|
|
630
|
+
- **Type**: ${c.type}
|
|
631
|
+
- **Description**: ${c.description ?? 'N/A'}
|
|
632
|
+
- **Dependencies**: ${(c.dependencies ?? []).join(', ') || 'None'}
|
|
633
|
+
`).join('\n')}
|
|
634
|
+
|
|
635
|
+
## Diagram
|
|
636
|
+
|
|
637
|
+
\`\`\`mermaid
|
|
638
|
+
${diagram}
|
|
639
|
+
\`\`\`
|
|
640
|
+
`;
|
|
641
|
+
// Store design
|
|
642
|
+
designStore.set(designId, {
|
|
643
|
+
designId,
|
|
644
|
+
type: 'architecture',
|
|
645
|
+
format,
|
|
646
|
+
name,
|
|
647
|
+
description,
|
|
648
|
+
content: documentation,
|
|
649
|
+
status: 'draft',
|
|
650
|
+
createdAt: new Date().toISOString(),
|
|
651
|
+
});
|
|
652
|
+
return {
|
|
653
|
+
content: [
|
|
654
|
+
{
|
|
655
|
+
type: 'text',
|
|
656
|
+
text: JSON.stringify({
|
|
657
|
+
designId,
|
|
658
|
+
name,
|
|
659
|
+
pattern,
|
|
660
|
+
diagram,
|
|
661
|
+
documentation,
|
|
662
|
+
createdAt: new Date().toISOString(),
|
|
663
|
+
}, null, 2),
|
|
664
|
+
},
|
|
665
|
+
],
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
catch (error) {
|
|
669
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
670
|
+
return {
|
|
671
|
+
content: [
|
|
672
|
+
{
|
|
673
|
+
type: 'text',
|
|
674
|
+
text: JSON.stringify({
|
|
675
|
+
error: 'GENERATION_FAILED',
|
|
676
|
+
message,
|
|
677
|
+
name,
|
|
678
|
+
}),
|
|
679
|
+
},
|
|
680
|
+
],
|
|
681
|
+
isError: true,
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
/**
|
|
686
|
+
* Handler for design_list tool
|
|
687
|
+
*/
|
|
688
|
+
export const handleDesignList = async (args) => {
|
|
689
|
+
const type = args.type;
|
|
690
|
+
const status = args.status;
|
|
691
|
+
const limit = args.limit ?? 50;
|
|
692
|
+
try {
|
|
693
|
+
let designs = Array.from(designStore.values());
|
|
694
|
+
if (type !== undefined) {
|
|
695
|
+
designs = designs.filter((d) => d.type === type);
|
|
696
|
+
}
|
|
697
|
+
if (status !== undefined) {
|
|
698
|
+
designs = designs.filter((d) => d.status === status);
|
|
699
|
+
}
|
|
700
|
+
designs = designs.slice(0, limit);
|
|
701
|
+
return {
|
|
702
|
+
content: [
|
|
703
|
+
{
|
|
704
|
+
type: 'text',
|
|
705
|
+
text: JSON.stringify({
|
|
706
|
+
designs: designs.map((d) => ({
|
|
707
|
+
designId: d.designId,
|
|
708
|
+
type: d.type,
|
|
709
|
+
format: d.format,
|
|
710
|
+
name: d.name,
|
|
711
|
+
status: d.status,
|
|
712
|
+
createdAt: d.createdAt,
|
|
713
|
+
})),
|
|
714
|
+
total: designs.length,
|
|
715
|
+
}, null, 2),
|
|
716
|
+
},
|
|
717
|
+
],
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
catch (error) {
|
|
721
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
722
|
+
return {
|
|
723
|
+
content: [
|
|
724
|
+
{
|
|
725
|
+
type: 'text',
|
|
726
|
+
text: JSON.stringify({
|
|
727
|
+
error: 'LIST_FAILED',
|
|
728
|
+
message,
|
|
729
|
+
}),
|
|
730
|
+
},
|
|
731
|
+
],
|
|
732
|
+
isError: true,
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
//# sourceMappingURL=design.js.map
|