@opensaas/stack-cli 0.1.6 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +215 -0
- package/CLAUDE.md +60 -12
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +10 -1
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/mcp.d.ts +6 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +116 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/generator/context.d.ts.map +1 -1
- package/dist/generator/context.js +21 -3
- package/dist/generator/context.js.map +1 -1
- package/dist/generator/index.d.ts +3 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +3 -0
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/lists.d.ts +31 -0
- package/dist/generator/lists.d.ts.map +1 -0
- package/dist/generator/lists.js +91 -0
- package/dist/generator/lists.js.map +1 -0
- package/dist/generator/plugin-types.d.ts +10 -0
- package/dist/generator/plugin-types.d.ts.map +1 -0
- package/dist/generator/plugin-types.js +122 -0
- package/dist/generator/plugin-types.js.map +1 -0
- package/dist/generator/prisma-config.d.ts +17 -0
- package/dist/generator/prisma-config.d.ts.map +1 -0
- package/dist/generator/prisma-config.js +40 -0
- package/dist/generator/prisma-config.js.map +1 -0
- package/dist/generator/prisma.d.ts.map +1 -1
- package/dist/generator/prisma.js +1 -2
- package/dist/generator/prisma.js.map +1 -1
- package/dist/generator/types.d.ts.map +1 -1
- package/dist/generator/types.js +53 -1
- package/dist/generator/types.js.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/lib/documentation-provider.d.ts +43 -0
- package/dist/mcp/lib/documentation-provider.d.ts.map +1 -0
- package/dist/mcp/lib/documentation-provider.js +163 -0
- package/dist/mcp/lib/documentation-provider.js.map +1 -0
- package/dist/mcp/lib/features/catalog.d.ts +26 -0
- package/dist/mcp/lib/features/catalog.d.ts.map +1 -0
- package/dist/mcp/lib/features/catalog.js +291 -0
- package/dist/mcp/lib/features/catalog.js.map +1 -0
- package/dist/mcp/lib/generators/feature-generator.d.ts +35 -0
- package/dist/mcp/lib/generators/feature-generator.d.ts.map +1 -0
- package/dist/mcp/lib/generators/feature-generator.js +546 -0
- package/dist/mcp/lib/generators/feature-generator.js.map +1 -0
- package/dist/mcp/lib/types.d.ts +80 -0
- package/dist/mcp/lib/types.d.ts.map +1 -0
- package/dist/mcp/lib/types.js +5 -0
- package/dist/mcp/lib/types.js.map +1 -0
- package/dist/mcp/lib/wizards/wizard-engine.d.ts +71 -0
- package/dist/mcp/lib/wizards/wizard-engine.d.ts.map +1 -0
- package/dist/mcp/lib/wizards/wizard-engine.js +356 -0
- package/dist/mcp/lib/wizards/wizard-engine.js.map +1 -0
- package/dist/mcp/server/index.d.ts +8 -0
- package/dist/mcp/server/index.d.ts.map +1 -0
- package/dist/mcp/server/index.js +202 -0
- package/dist/mcp/server/index.js.map +1 -0
- package/dist/mcp/server/stack-mcp-server.d.ts +92 -0
- package/dist/mcp/server/stack-mcp-server.d.ts.map +1 -0
- package/dist/mcp/server/stack-mcp-server.js +265 -0
- package/dist/mcp/server/stack-mcp-server.js.map +1 -0
- package/package.json +9 -7
- package/src/commands/__snapshots__/generate.test.ts.snap +61 -21
- package/src/commands/dev.test.ts +0 -1
- package/src/commands/generate.test.ts +18 -8
- package/src/commands/generate.ts +12 -0
- package/src/commands/mcp.ts +135 -0
- package/src/generator/__snapshots__/context.test.ts.snap +8 -8
- package/src/generator/__snapshots__/prisma.test.ts.snap +8 -16
- package/src/generator/__snapshots__/types.test.ts.snap +605 -9
- package/src/generator/context.test.ts +13 -8
- package/src/generator/context.ts +21 -3
- package/src/generator/index.ts +3 -0
- package/src/generator/lists.test.ts +335 -0
- package/src/generator/lists.ts +102 -0
- package/src/generator/plugin-types.ts +147 -0
- package/src/generator/prisma-config.ts +46 -0
- package/src/generator/prisma.test.ts +0 -10
- package/src/generator/prisma.ts +1 -2
- package/src/generator/types.test.ts +0 -12
- package/src/generator/types.ts +56 -1
- package/src/index.ts +4 -0
- package/src/mcp/lib/documentation-provider.ts +203 -0
- package/src/mcp/lib/features/catalog.ts +301 -0
- package/src/mcp/lib/generators/feature-generator.ts +598 -0
- package/src/mcp/lib/types.ts +89 -0
- package/src/mcp/lib/wizards/wizard-engine.ts +427 -0
- package/src/mcp/server/index.ts +240 -0
- package/src/mcp/server/stack-mcp-server.ts +301 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wizard engine for multi-step feature implementation flows
|
|
3
|
+
*/
|
|
4
|
+
import type { WizardSession } from '../types.js';
|
|
5
|
+
export declare class WizardEngine {
|
|
6
|
+
private sessions;
|
|
7
|
+
/**
|
|
8
|
+
* Start a new feature implementation wizard
|
|
9
|
+
*/
|
|
10
|
+
startFeature(featureId: string): Promise<{
|
|
11
|
+
content: Array<{
|
|
12
|
+
type: string;
|
|
13
|
+
text: string;
|
|
14
|
+
}>;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Process an answer and move to next question or complete the wizard
|
|
18
|
+
*/
|
|
19
|
+
answerQuestion(sessionId: string, answer: string | boolean | string[]): Promise<{
|
|
20
|
+
content: Array<{
|
|
21
|
+
type: string;
|
|
22
|
+
text: string;
|
|
23
|
+
}>;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Handle follow-up question answers
|
|
27
|
+
*/
|
|
28
|
+
answerFollowUp(sessionId: string, answer: string): Promise<{
|
|
29
|
+
content: Array<{
|
|
30
|
+
type: string;
|
|
31
|
+
text: string;
|
|
32
|
+
}>;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Generate the complete feature implementation
|
|
36
|
+
*/
|
|
37
|
+
private generateFeatureImplementation;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new wizard session
|
|
40
|
+
*/
|
|
41
|
+
private createSession;
|
|
42
|
+
/**
|
|
43
|
+
* Generate a unique session ID
|
|
44
|
+
*/
|
|
45
|
+
private generateSessionId;
|
|
46
|
+
/**
|
|
47
|
+
* Render a question for the user
|
|
48
|
+
*/
|
|
49
|
+
private renderQuestion;
|
|
50
|
+
/**
|
|
51
|
+
* Validate an answer against question requirements
|
|
52
|
+
*/
|
|
53
|
+
private validateAnswer;
|
|
54
|
+
/**
|
|
55
|
+
* Render a progress bar
|
|
56
|
+
*/
|
|
57
|
+
private renderProgressBar;
|
|
58
|
+
/**
|
|
59
|
+
* Format an answer for display
|
|
60
|
+
*/
|
|
61
|
+
private formatAnswer;
|
|
62
|
+
/**
|
|
63
|
+
* Get session by ID (for debugging/testing)
|
|
64
|
+
*/
|
|
65
|
+
getSession(sessionId: string): WizardSession | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Clear completed sessions (cleanup)
|
|
68
|
+
*/
|
|
69
|
+
clearCompletedSessions(): void;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=wizard-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wizard-engine.d.ts","sourceRoot":"","sources":["../../../../src/mcp/lib/wizards/wizard-engine.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAW,aAAa,EAAmC,MAAM,aAAa,CAAA;AAI1F,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAqB;IAErC;;OAEG;IACG,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;QAC7C,OAAO,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAC/C,CAAC;IA4DF;;OAEG;IACG,cAAc,CAClB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAClC,OAAO,CAAC;QACT,OAAO,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAC/C,CAAC;IA2EF;;OAEG;IACG,cAAc,CAClB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QACT,OAAO,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAC/C,CAAC;IA4CF;;OAEG;YACW,6BAA6B;IA8E3C;;OAEG;IACH,OAAO,CAAC,aAAa;IAcrB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,OAAO,CAAC,cAAc;IAyBtB;;OAEG;IACH,OAAO,CAAC,cAAc;IAwCtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;OAEG;IACH,OAAO,CAAC,YAAY;IAUpB;;OAEG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAIxD;;OAEG;IACH,sBAAsB,IAAI,IAAI;CAO/B"}
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wizard engine for multi-step feature implementation flows
|
|
3
|
+
*/
|
|
4
|
+
import { getFeature } from '../features/catalog.js';
|
|
5
|
+
import { FeatureGenerator } from '../generators/feature-generator.js';
|
|
6
|
+
export class WizardEngine {
|
|
7
|
+
sessions = {};
|
|
8
|
+
/**
|
|
9
|
+
* Start a new feature implementation wizard
|
|
10
|
+
*/
|
|
11
|
+
async startFeature(featureId) {
|
|
12
|
+
const feature = getFeature(featureId);
|
|
13
|
+
if (!feature) {
|
|
14
|
+
return {
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
type: 'text',
|
|
18
|
+
text: `❌ Unknown feature: "${featureId}"\n\nAvailable features: authentication, blog, comments, file-upload, semantic-search`,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const sessionId = this.generateSessionId();
|
|
24
|
+
const session = this.createSession(sessionId, feature);
|
|
25
|
+
this.sessions[sessionId] = session;
|
|
26
|
+
const progressBar = this.renderProgressBar(1, feature.questions.length);
|
|
27
|
+
const firstQuestion = this.renderQuestion(feature.questions[0], session, 1);
|
|
28
|
+
return {
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: 'text',
|
|
32
|
+
text: `🚀 **${feature.name} Implementation**
|
|
33
|
+
|
|
34
|
+
${feature.description}
|
|
35
|
+
|
|
36
|
+
**What's included**:
|
|
37
|
+
${feature.includes.map((item) => `- ${item}`).join('\n')}
|
|
38
|
+
|
|
39
|
+
${feature.dependsOn && feature.dependsOn.length > 0 ? `\n⚠️ **Dependencies**: This feature requires: ${feature.dependsOn.join(', ')}\n` : ''}
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Let's configure this feature
|
|
44
|
+
|
|
45
|
+
${firstQuestion}
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
**Progress**: ${progressBar} 1/${feature.questions.length}
|
|
50
|
+
**Session ID**: \`${sessionId}\`
|
|
51
|
+
|
|
52
|
+
<details>
|
|
53
|
+
<summary>💡 **Instructions for Claude Code**</summary>
|
|
54
|
+
|
|
55
|
+
1. Present this question to the user naturally in conversation
|
|
56
|
+
2. When they respond, call \`opensaas_answer_feature\` with:
|
|
57
|
+
- sessionId: "${sessionId}"
|
|
58
|
+
- answer: <their response>
|
|
59
|
+
3. Continue the conversation flow with the next question
|
|
60
|
+
4. Keep it natural - don't mention session IDs to the user
|
|
61
|
+
|
|
62
|
+
</details>`,
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Process an answer and move to next question or complete the wizard
|
|
69
|
+
*/
|
|
70
|
+
async answerQuestion(sessionId, answer) {
|
|
71
|
+
const session = this.sessions[sessionId];
|
|
72
|
+
if (!session) {
|
|
73
|
+
return {
|
|
74
|
+
content: [
|
|
75
|
+
{
|
|
76
|
+
type: 'text',
|
|
77
|
+
text: `❌ Session not found: ${sessionId}\n\nPlease start a new feature implementation.`,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const currentQ = session.feature.questions[session.currentQuestionIndex];
|
|
83
|
+
// Validate answer
|
|
84
|
+
const validation = this.validateAnswer(answer, currentQ);
|
|
85
|
+
if (!validation.valid) {
|
|
86
|
+
return {
|
|
87
|
+
content: [
|
|
88
|
+
{
|
|
89
|
+
type: 'text',
|
|
90
|
+
text: `❌ **Invalid answer**: ${validation.message}\n\n${this.renderQuestion(currentQ, session, session.currentQuestionIndex + 1)}`,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// Store answer
|
|
96
|
+
session.answers[currentQ.id] = answer;
|
|
97
|
+
session.updatedAt = new Date();
|
|
98
|
+
// Check for follow-up questions
|
|
99
|
+
if (currentQ.followUp) {
|
|
100
|
+
const shouldAskFollowUp = currentQ.followUp.if === answer ||
|
|
101
|
+
(typeof currentQ.followUp.if === 'boolean' && currentQ.followUp.if === answer);
|
|
102
|
+
if (shouldAskFollowUp) {
|
|
103
|
+
const followUpText = `**Follow-up**: ${currentQ.followUp.ask}`;
|
|
104
|
+
return {
|
|
105
|
+
content: [
|
|
106
|
+
{
|
|
107
|
+
type: 'text',
|
|
108
|
+
text: `✓ Recorded: ${this.formatAnswer(answer)}\n\n${followUpText}\n\n---\n\n💡 **Claude Code**: Ask this follow-up question and call \`opensaas_answer_followup\` with sessionId "${sessionId}" and their response.`,
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Move to next question
|
|
115
|
+
session.currentQuestionIndex++;
|
|
116
|
+
// Check if complete
|
|
117
|
+
if (session.currentQuestionIndex >= session.feature.questions.length) {
|
|
118
|
+
session.isComplete = true;
|
|
119
|
+
return this.generateFeatureImplementation(session);
|
|
120
|
+
}
|
|
121
|
+
// Render next question
|
|
122
|
+
const nextQ = session.feature.questions[session.currentQuestionIndex];
|
|
123
|
+
const questionNum = session.currentQuestionIndex + 1;
|
|
124
|
+
const progressBar = this.renderProgressBar(questionNum, session.feature.questions.length);
|
|
125
|
+
return {
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
type: 'text',
|
|
129
|
+
text: `✓ Recorded: ${this.formatAnswer(answer)}\n\n${this.renderQuestion(nextQ, session, questionNum)}\n\n---\n\n**Progress**: ${progressBar} ${questionNum}/${session.feature.questions.length}`,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Handle follow-up question answers
|
|
136
|
+
*/
|
|
137
|
+
async answerFollowUp(sessionId, answer) {
|
|
138
|
+
const session = this.sessions[sessionId];
|
|
139
|
+
if (!session) {
|
|
140
|
+
return {
|
|
141
|
+
content: [
|
|
142
|
+
{
|
|
143
|
+
type: 'text',
|
|
144
|
+
text: `❌ Session not found: ${sessionId}`,
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const currentQ = session.feature.questions[session.currentQuestionIndex];
|
|
150
|
+
const followUpKey = `${currentQ.id}_followup`;
|
|
151
|
+
// Store follow-up answer
|
|
152
|
+
session.followUpAnswers[followUpKey] = answer;
|
|
153
|
+
session.updatedAt = new Date();
|
|
154
|
+
// Move to next question
|
|
155
|
+
session.currentQuestionIndex++;
|
|
156
|
+
// Check if complete
|
|
157
|
+
if (session.currentQuestionIndex >= session.feature.questions.length) {
|
|
158
|
+
session.isComplete = true;
|
|
159
|
+
return this.generateFeatureImplementation(session);
|
|
160
|
+
}
|
|
161
|
+
// Render next question
|
|
162
|
+
const nextQ = session.feature.questions[session.currentQuestionIndex];
|
|
163
|
+
const questionNum = session.currentQuestionIndex + 1;
|
|
164
|
+
const progressBar = this.renderProgressBar(questionNum, session.feature.questions.length);
|
|
165
|
+
return {
|
|
166
|
+
content: [
|
|
167
|
+
{
|
|
168
|
+
type: 'text',
|
|
169
|
+
text: `✓ Recorded: ${answer}\n\n${this.renderQuestion(nextQ, session, questionNum)}\n\n---\n\n**Progress**: ${progressBar} ${questionNum}/${session.feature.questions.length}`,
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Generate the complete feature implementation
|
|
176
|
+
*/
|
|
177
|
+
async generateFeatureImplementation(session) {
|
|
178
|
+
const generator = new FeatureGenerator(session.feature, session.answers, session.followUpAnswers);
|
|
179
|
+
const implementation = generator.generate();
|
|
180
|
+
return {
|
|
181
|
+
content: [
|
|
182
|
+
{
|
|
183
|
+
type: 'text',
|
|
184
|
+
text: `✅ **${session.feature.name} Implementation Complete!**
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## 📝 Update \`opensaas.config.ts\`
|
|
189
|
+
|
|
190
|
+
\`\`\`typescript
|
|
191
|
+
${implementation.configUpdates}
|
|
192
|
+
\`\`\`
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## 📁 Create these files:
|
|
197
|
+
|
|
198
|
+
${implementation.files.map((file) => `### ${file.path}\n*${file.description}*\n\n\`\`\`${file.language}\n${file.content}\n\`\`\``).join('\n\n')}
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
${implementation.envVars && Object.keys(implementation.envVars).length > 0
|
|
203
|
+
? `## 🔐 Environment Variables\n\nAdd these to your \`.env\` file:\n\n\`\`\`bash\n${Object.entries(implementation.envVars)
|
|
204
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
205
|
+
.join('\n')}\n\`\`\`\n\n---\n\n`
|
|
206
|
+
: ''}
|
|
207
|
+
|
|
208
|
+
## 🚀 Next Steps
|
|
209
|
+
|
|
210
|
+
${implementation.nextSteps.map((step, i) => `${i + 1}. ${step}`).join('\n')}
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## 📖 Feature Documentation
|
|
215
|
+
|
|
216
|
+
Add this to your project's \`DEVELOPMENT.md\`:
|
|
217
|
+
|
|
218
|
+
\`\`\`markdown
|
|
219
|
+
${implementation.devGuideSection}
|
|
220
|
+
\`\`\`
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
🎉 **Your ${session.feature.name} feature is ready to use!**
|
|
225
|
+
|
|
226
|
+
<details>
|
|
227
|
+
<summary>💡 **Troubleshooting**</summary>
|
|
228
|
+
|
|
229
|
+
If you encounter issues:
|
|
230
|
+
1. Ensure all dependencies are installed: \`pnpm install\`
|
|
231
|
+
2. Check that environment variables are set correctly
|
|
232
|
+
3. Run \`pnpm generate\` to update Prisma schema
|
|
233
|
+
4. Run \`pnpm db:push\` to update database
|
|
234
|
+
|
|
235
|
+
For more help, see the docs at https://stack.opensaas.au/
|
|
236
|
+
|
|
237
|
+
</details>`,
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Create a new wizard session
|
|
244
|
+
*/
|
|
245
|
+
createSession(sessionId, feature) {
|
|
246
|
+
return {
|
|
247
|
+
id: sessionId,
|
|
248
|
+
featureId: feature.id,
|
|
249
|
+
feature,
|
|
250
|
+
currentQuestionIndex: 0,
|
|
251
|
+
answers: {},
|
|
252
|
+
followUpAnswers: {},
|
|
253
|
+
isComplete: false,
|
|
254
|
+
createdAt: new Date(),
|
|
255
|
+
updatedAt: new Date(),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Generate a unique session ID
|
|
260
|
+
*/
|
|
261
|
+
generateSessionId() {
|
|
262
|
+
return `session_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Render a question for the user
|
|
266
|
+
*/
|
|
267
|
+
renderQuestion(question, session, questionNum) {
|
|
268
|
+
let rendered = `**Question ${questionNum}**: ${question.text}\n\n`;
|
|
269
|
+
if (question.type === 'select' || question.type === 'multiselect') {
|
|
270
|
+
rendered += question.options.map((opt) => `- ${opt}`).join('\n');
|
|
271
|
+
if (question.type === 'multiselect') {
|
|
272
|
+
rendered += '\n\n*You can select multiple options (comma-separated)*';
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else if (question.type === 'boolean') {
|
|
276
|
+
rendered += '*Answer: yes or no*';
|
|
277
|
+
}
|
|
278
|
+
else if (question.type === 'textarea') {
|
|
279
|
+
rendered += '*Provide a detailed response*';
|
|
280
|
+
}
|
|
281
|
+
if (question.defaultValue !== undefined) {
|
|
282
|
+
rendered += `\n\n*Default: ${this.formatAnswer(question.defaultValue)}*`;
|
|
283
|
+
}
|
|
284
|
+
return rendered;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Validate an answer against question requirements
|
|
288
|
+
*/
|
|
289
|
+
validateAnswer(answer, question) {
|
|
290
|
+
if (question.required && !answer) {
|
|
291
|
+
return { valid: false, message: 'This question is required' };
|
|
292
|
+
}
|
|
293
|
+
if (question.type === 'boolean' && typeof answer !== 'boolean') {
|
|
294
|
+
return {
|
|
295
|
+
valid: false,
|
|
296
|
+
message: 'Please answer with yes/no or true/false',
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
if (question.type === 'select' &&
|
|
300
|
+
question.options &&
|
|
301
|
+
!question.options.includes(answer)) {
|
|
302
|
+
return {
|
|
303
|
+
valid: false,
|
|
304
|
+
message: `Please select one of: ${question.options.join(', ')}`,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
if (question.type === 'multiselect' && question.options) {
|
|
308
|
+
const answers = Array.isArray(answer) ? answer : [answer];
|
|
309
|
+
const invalid = answers.filter((a) => typeof a === 'string' && !question.options.includes(a));
|
|
310
|
+
if (invalid.length > 0) {
|
|
311
|
+
return {
|
|
312
|
+
valid: false,
|
|
313
|
+
message: `Invalid options: ${invalid.join(', ')}. Valid options: ${question.options.join(', ')}`,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return { valid: true };
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Render a progress bar
|
|
321
|
+
*/
|
|
322
|
+
renderProgressBar(current, total) {
|
|
323
|
+
const filled = Math.round((current / total) * 10);
|
|
324
|
+
const empty = 10 - filled;
|
|
325
|
+
return '▓'.repeat(filled) + '░'.repeat(empty);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Format an answer for display
|
|
329
|
+
*/
|
|
330
|
+
formatAnswer(answer) {
|
|
331
|
+
if (typeof answer === 'boolean') {
|
|
332
|
+
return answer ? 'Yes' : 'No';
|
|
333
|
+
}
|
|
334
|
+
if (Array.isArray(answer)) {
|
|
335
|
+
return answer.join(', ');
|
|
336
|
+
}
|
|
337
|
+
return answer;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Get session by ID (for debugging/testing)
|
|
341
|
+
*/
|
|
342
|
+
getSession(sessionId) {
|
|
343
|
+
return this.sessions[sessionId];
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Clear completed sessions (cleanup)
|
|
347
|
+
*/
|
|
348
|
+
clearCompletedSessions() {
|
|
349
|
+
Object.keys(this.sessions).forEach((id) => {
|
|
350
|
+
if (this.sessions[id].isComplete) {
|
|
351
|
+
delete this.sessions[id];
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
//# sourceMappingURL=wizard-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wizard-engine.js","sourceRoot":"","sources":["../../../../src/mcp/lib/wizards/wizard-engine.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C;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,SAAiB;QAC1B,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;IACjC,CAAC;IAED;;OAEG;IACH,sBAAsB;QACpB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YACxC,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC;gBACjC,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;YAC1B,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mcp/server/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAqIH;;GAEG;AACH,wBAAsB,cAAc,kBA6FnC"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenSaaS Stack MCP Server - Main entry point
|
|
3
|
+
*/
|
|
4
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
6
|
+
import { ListToolsRequestSchema, CallToolRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import { StackMCPServer } from './stack-mcp-server.js';
|
|
8
|
+
// Tool definitions
|
|
9
|
+
const TOOLS = [
|
|
10
|
+
{
|
|
11
|
+
name: 'opensaas_implement_feature',
|
|
12
|
+
description: 'Start an interactive wizard to implement a complete feature (authentication, blog, comments, file-upload, semantic-search, or custom). Returns step-by-step guidance.',
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
feature: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'Feature to implement: "authentication", "blog", "comments", "file-upload", "semantic-search", or "custom"',
|
|
19
|
+
enum: ['authentication', 'blog', 'comments', 'file-upload', 'semantic-search', 'custom'],
|
|
20
|
+
},
|
|
21
|
+
description: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'Required if feature is "custom" - describe what you want to build',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
required: ['feature'],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'opensaas_answer_feature',
|
|
31
|
+
description: 'Answer a question in the feature implementation wizard. Use this after opensaas_implement_feature to progress through the wizard.',
|
|
32
|
+
inputSchema: {
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {
|
|
35
|
+
sessionId: {
|
|
36
|
+
type: 'string',
|
|
37
|
+
description: 'Session ID from the wizard',
|
|
38
|
+
},
|
|
39
|
+
answer: {
|
|
40
|
+
description: 'Your answer to the current question',
|
|
41
|
+
oneOf: [
|
|
42
|
+
{ type: 'string' },
|
|
43
|
+
{ type: 'boolean' },
|
|
44
|
+
{ type: 'array', items: { type: 'string' } },
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
required: ['sessionId', 'answer'],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'opensaas_answer_followup',
|
|
53
|
+
description: 'Answer a follow-up question in the wizard flow',
|
|
54
|
+
inputSchema: {
|
|
55
|
+
type: 'object',
|
|
56
|
+
properties: {
|
|
57
|
+
sessionId: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
description: 'Session ID from the wizard',
|
|
60
|
+
},
|
|
61
|
+
answer: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
description: 'Your answer to the follow-up question',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
required: ['sessionId', 'answer'],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'opensaas_feature_docs',
|
|
71
|
+
description: 'Search OpenSaaS Stack documentation for a specific topic. Returns relevant docs with code examples.',
|
|
72
|
+
inputSchema: {
|
|
73
|
+
type: 'object',
|
|
74
|
+
properties: {
|
|
75
|
+
topic: {
|
|
76
|
+
type: 'string',
|
|
77
|
+
description: 'Topic to search for (e.g., "access control", "field types", "hooks", "authentication")',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
required: ['topic'],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'opensaas_list_features',
|
|
85
|
+
description: 'List all available features that can be implemented with the wizard',
|
|
86
|
+
inputSchema: {
|
|
87
|
+
type: 'object',
|
|
88
|
+
properties: {},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'opensaas_suggest_features',
|
|
93
|
+
description: 'Get feature suggestions based on what features are already implemented',
|
|
94
|
+
inputSchema: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
currentFeatures: {
|
|
98
|
+
type: 'array',
|
|
99
|
+
items: { type: 'string' },
|
|
100
|
+
description: 'List of features already implemented (e.g., ["authentication", "blog"])',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'opensaas_validate_feature',
|
|
107
|
+
description: 'Validate that a feature is properly implemented according to best practices',
|
|
108
|
+
inputSchema: {
|
|
109
|
+
type: 'object',
|
|
110
|
+
properties: {
|
|
111
|
+
feature: {
|
|
112
|
+
type: 'string',
|
|
113
|
+
description: 'Feature to validate (e.g., "authentication")',
|
|
114
|
+
},
|
|
115
|
+
configPath: {
|
|
116
|
+
type: 'string',
|
|
117
|
+
description: 'Path to opensaas.config.ts (optional)',
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
required: ['feature'],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
/**
|
|
125
|
+
* Create and start the MCP server
|
|
126
|
+
*/
|
|
127
|
+
export async function startMCPServer() {
|
|
128
|
+
const server = new Server({
|
|
129
|
+
name: 'opensaas-stack-mcp',
|
|
130
|
+
version: '0.1.0',
|
|
131
|
+
}, {
|
|
132
|
+
capabilities: {
|
|
133
|
+
tools: {},
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
const stackServer = new StackMCPServer();
|
|
137
|
+
// Register tool list handler
|
|
138
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
139
|
+
return { tools: TOOLS };
|
|
140
|
+
});
|
|
141
|
+
// Register tool call handler
|
|
142
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
143
|
+
const { name, arguments: args } = request.params;
|
|
144
|
+
try {
|
|
145
|
+
switch (name) {
|
|
146
|
+
case 'opensaas_implement_feature':
|
|
147
|
+
return await stackServer.implementFeature(args);
|
|
148
|
+
case 'opensaas_answer_feature':
|
|
149
|
+
return await stackServer.answerFeatureQuestion(args);
|
|
150
|
+
case 'opensaas_answer_followup':
|
|
151
|
+
return await stackServer.answerFollowUpQuestion(args);
|
|
152
|
+
case 'opensaas_feature_docs':
|
|
153
|
+
return await stackServer.searchFeatureDocs(args);
|
|
154
|
+
case 'opensaas_list_features':
|
|
155
|
+
return await stackServer.listFeatures();
|
|
156
|
+
case 'opensaas_suggest_features':
|
|
157
|
+
return await stackServer.suggestFeatures(args);
|
|
158
|
+
case 'opensaas_validate_feature':
|
|
159
|
+
return await stackServer.validateFeature(args);
|
|
160
|
+
default:
|
|
161
|
+
return {
|
|
162
|
+
content: [
|
|
163
|
+
{
|
|
164
|
+
type: 'text',
|
|
165
|
+
text: `Unknown tool: ${name}`,
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
isError: true,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
174
|
+
console.error(`Error executing tool ${name}:`, error);
|
|
175
|
+
return {
|
|
176
|
+
content: [
|
|
177
|
+
{
|
|
178
|
+
type: 'text',
|
|
179
|
+
text: `Error: ${errorMessage}`,
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
isError: true,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
// Periodic cleanup
|
|
187
|
+
setInterval(() => {
|
|
188
|
+
stackServer.cleanup();
|
|
189
|
+
}, 1000 * 60 * 15); // Every 15 minutes
|
|
190
|
+
// Start server
|
|
191
|
+
const transport = new StdioServerTransport();
|
|
192
|
+
await server.connect(transport);
|
|
193
|
+
console.error('OpenSaaS Stack MCP server running on stdio');
|
|
194
|
+
}
|
|
195
|
+
// Start if run directly
|
|
196
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
197
|
+
startMCPServer().catch((error) => {
|
|
198
|
+
console.error('Failed to start MCP server:', error);
|
|
199
|
+
process.exit(1);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp/server/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GAEtB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,mBAAmB;AACnB,MAAM,KAAK,GAAW;IACpB;QACE,IAAI,EAAE,4BAA4B;QAClC,WAAW,EACT,uKAAuK;QACzK,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,2GAA2G;oBAC7G,IAAI,EAAE,CAAC,gBAAgB,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