@agiflowai/scaffold-mcp 0.5.0 → 1.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.
- package/README.md +11 -71
- package/dist/ScaffoldConfigLoader-CI0T6zdG.js +142 -0
- package/dist/{ScaffoldConfigLoader-DzcV5a_c.cjs → ScaffoldConfigLoader-DQMCLVGD.cjs} +1 -1
- package/dist/ScaffoldConfigLoader-DhthV6xq.js +3 -0
- package/dist/{ScaffoldService-BgFWAOLQ.cjs → ScaffoldService-B-L4gwHt.cjs} +6 -0
- package/dist/ScaffoldService-Cx4ZonaT.cjs +3 -0
- package/dist/ScaffoldService-DVsusUh5.js +3 -0
- package/dist/ScaffoldService-QgQKHMM-.js +290 -0
- package/dist/TemplateService-BZRt3NI8.cjs +3 -0
- package/dist/TemplateService-CiZJA06s.js +79 -0
- package/dist/TemplateService-DropYdp8.js +3 -0
- package/dist/VariableReplacementService-B3qARIC9.js +66 -0
- package/dist/{VariableReplacementService-YUpL5nAC.cjs → VariableReplacementService-BrJ1PdKm.cjs} +1 -1
- package/dist/VariableReplacementService-D8C-IsP-.js +3 -0
- package/dist/cli.cjs +1363 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1355 -0
- package/dist/index.cjs +32 -3144
- package/dist/index.d.cts +798 -0
- package/dist/index.d.ts +799 -0
- package/dist/index.js +7 -0
- package/dist/stdio-Cz5aRdvr.cjs +2210 -0
- package/dist/stdio-Dmpwju2k.js +2074 -0
- package/package.json +19 -4
- package/dist/ScaffoldService-BvD9WvRi.cjs +0 -3
- package/dist/TemplateService-B5EZjPB0.cjs +0 -3
- /package/dist/{ScaffoldConfigLoader-1Pcv9cxm.cjs → ScaffoldConfigLoader-BrmvENTo.cjs} +0 -0
- /package/dist/{TemplateService-_KpkoLfZ.cjs → TemplateService-DRubcvS9.cjs} +0 -0
- /package/dist/{VariableReplacementService-ClshNY_C.cjs → VariableReplacementService-BL84vnKk.cjs} +0 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1355 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { BoilerplateService, FileSystemService, GenerateBoilerplateFileTool, GenerateBoilerplateTool, GenerateFeatureScaffoldTool, HttpTransportHandler, ListBoilerplatesTool, ListScaffoldingMethodsTool, ScaffoldingMethodsService, SseTransportHandler, StdioTransportHandler, UseBoilerplateTool, UseScaffoldMethodTool, WriteToFileTool, cloneRepository, cloneSubdirectory, fetchGitHubDirectoryContents, findWorkspaceRoot, parseGitHubUrl } from "./stdio-Dmpwju2k.js";
|
|
3
|
+
import "./ScaffoldConfigLoader-CI0T6zdG.js";
|
|
4
|
+
import "./ScaffoldService-QgQKHMM-.js";
|
|
5
|
+
import "./TemplateService-CiZJA06s.js";
|
|
6
|
+
import "./VariableReplacementService-B3qARIC9.js";
|
|
7
|
+
import { Command } from "commander";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { ProjectConfigResolver, ProjectType, TemplatesManagerService, icons, messages, print, sections } from "@agiflowai/aicode-utils";
|
|
10
|
+
import * as fs$1 from "fs-extra";
|
|
11
|
+
import { execa } from "execa";
|
|
12
|
+
import { confirm, input, select } from "@inquirer/prompts";
|
|
13
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
14
|
+
import { CallToolRequestSchema, GetPromptRequestSchema, ListPromptsRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
15
|
+
|
|
16
|
+
//#region package.json
|
|
17
|
+
var name = "@agiflowai/scaffold-mcp";
|
|
18
|
+
var description = "MCP server for scaffolding applications with boilerplate templates";
|
|
19
|
+
var version = "0.6.0";
|
|
20
|
+
var license = "AGPL-3.0";
|
|
21
|
+
var author = "AgiflowIO";
|
|
22
|
+
var repository = {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/AgiFlow/aicode-toolkit.git",
|
|
25
|
+
"directory": "packages/scaffold-mcp"
|
|
26
|
+
};
|
|
27
|
+
var homepage = "https://github.com/AgiFlow/aicode-toolkit#readme";
|
|
28
|
+
var bugs = { "url": "https://github.com/AgiFlow/aicode-toolkit/issues" };
|
|
29
|
+
var keywords = [
|
|
30
|
+
"mcp",
|
|
31
|
+
"model-context-protocol",
|
|
32
|
+
"scaffold",
|
|
33
|
+
"boilerplate",
|
|
34
|
+
"template",
|
|
35
|
+
"code-generation",
|
|
36
|
+
"nextjs",
|
|
37
|
+
"react",
|
|
38
|
+
"vite"
|
|
39
|
+
];
|
|
40
|
+
var bin = { "scaffold-mcp": "./dist/cli.cjs" };
|
|
41
|
+
var main$1 = "./dist/index.cjs";
|
|
42
|
+
var types = "./dist/index.d.cts";
|
|
43
|
+
var module = "./dist/index.js";
|
|
44
|
+
var files = ["dist", "README.md"];
|
|
45
|
+
var scripts = {
|
|
46
|
+
"dev": "node --loader ts-node/esm src/cli.ts",
|
|
47
|
+
"build": "tsdown",
|
|
48
|
+
"test": "vitest --run",
|
|
49
|
+
"typecheck": "tsc --noEmit"
|
|
50
|
+
};
|
|
51
|
+
var dependencies = {
|
|
52
|
+
"@agiflowai/aicode-utils": "workspace:*",
|
|
53
|
+
"@composio/json-schema-to-zod": "0.1.15",
|
|
54
|
+
"@inquirer/prompts": "^7.8.6",
|
|
55
|
+
"@modelcontextprotocol/sdk": "1.19.1",
|
|
56
|
+
"chalk": "5.6.2",
|
|
57
|
+
"commander": "14.0.1",
|
|
58
|
+
"execa": "^9.5.2",
|
|
59
|
+
"express": "^4.21.2",
|
|
60
|
+
"fs-extra": "11.3.2",
|
|
61
|
+
"js-yaml": "4.1.0",
|
|
62
|
+
"liquidjs": "10.21.1",
|
|
63
|
+
"pino": "^10.0.0",
|
|
64
|
+
"pino-pretty": "^13.1.1",
|
|
65
|
+
"zod": "3.25.76"
|
|
66
|
+
};
|
|
67
|
+
var devDependencies = {
|
|
68
|
+
"@types/express": "^5.0.0",
|
|
69
|
+
"@types/fs-extra": "^11.0.4",
|
|
70
|
+
"@types/js-yaml": "^4.0.9",
|
|
71
|
+
"@types/node": "^22.0.0",
|
|
72
|
+
"tsdown": "^0.15.6",
|
|
73
|
+
"typescript": "5.9.3"
|
|
74
|
+
};
|
|
75
|
+
var publishConfig = { "access": "public" };
|
|
76
|
+
var type = "module";
|
|
77
|
+
var exports = {
|
|
78
|
+
".": {
|
|
79
|
+
"import": "./dist/index.js",
|
|
80
|
+
"require": "./dist/index.cjs"
|
|
81
|
+
},
|
|
82
|
+
"./cli": {
|
|
83
|
+
"import": "./dist/cli.js",
|
|
84
|
+
"require": "./dist/cli.cjs"
|
|
85
|
+
},
|
|
86
|
+
"./package.json": "./package.json"
|
|
87
|
+
};
|
|
88
|
+
var package_default = {
|
|
89
|
+
name,
|
|
90
|
+
description,
|
|
91
|
+
version,
|
|
92
|
+
license,
|
|
93
|
+
author,
|
|
94
|
+
repository,
|
|
95
|
+
homepage,
|
|
96
|
+
bugs,
|
|
97
|
+
keywords,
|
|
98
|
+
bin,
|
|
99
|
+
main: main$1,
|
|
100
|
+
types,
|
|
101
|
+
module,
|
|
102
|
+
files,
|
|
103
|
+
scripts,
|
|
104
|
+
dependencies,
|
|
105
|
+
devDependencies,
|
|
106
|
+
publishConfig,
|
|
107
|
+
type,
|
|
108
|
+
exports
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/commands/add.ts
|
|
113
|
+
/**
|
|
114
|
+
* Add command - add a template to templates folder
|
|
115
|
+
*/
|
|
116
|
+
const addCommand = new Command("add").description("Add a template to templates folder").requiredOption("--name <name>", "Template name").requiredOption("--url <url>", "URL of the template repository to download").option("--path <path>", "Override templates folder path (uses toolkit.yaml config by default)").option("--type <type>", "Template type: boilerplate or scaffold", "boilerplate").action(async (options) => {
|
|
117
|
+
try {
|
|
118
|
+
const templatesPath = options.path ? path.resolve(options.path) : await TemplatesManagerService.findTemplatesPath();
|
|
119
|
+
const templateType = options.type.toLowerCase();
|
|
120
|
+
const templateName = options.name;
|
|
121
|
+
const templateUrl = options.url;
|
|
122
|
+
if (templateType !== "boilerplate" && templateType !== "scaffold") {
|
|
123
|
+
messages.error("Invalid template type. Use: boilerplate or scaffold");
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
const targetFolder = path.join(templatesPath, `${templateType}s`, templateName);
|
|
127
|
+
if (await fs$1.pathExists(targetFolder)) {
|
|
128
|
+
messages.error(`Template '${templateName}' already exists at ${targetFolder}`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
print.info(`${icons.download} Downloading template '${templateName}' from ${templateUrl}...`);
|
|
132
|
+
await fs$1.ensureDir(path.dirname(targetFolder));
|
|
133
|
+
const parsedUrl = parseGitHubUrl(templateUrl);
|
|
134
|
+
try {
|
|
135
|
+
if (parsedUrl.isSubdirectory && parsedUrl.branch && parsedUrl.subdirectory) {
|
|
136
|
+
print.info(`${icons.folder} Detected subdirectory: ${parsedUrl.subdirectory} (branch: ${parsedUrl.branch})`);
|
|
137
|
+
await cloneSubdirectory(parsedUrl.repoUrl, parsedUrl.branch, parsedUrl.subdirectory, targetFolder);
|
|
138
|
+
} else await cloneRepository(parsedUrl.repoUrl, targetFolder);
|
|
139
|
+
messages.success(`Template '${templateName}' added successfully!`);
|
|
140
|
+
print.header(`\n${icons.folder} Template location:`);
|
|
141
|
+
print.indent(targetFolder);
|
|
142
|
+
const configFiles = [path.join(targetFolder, "boilerplate.yaml"), path.join(targetFolder, "scaffold.yaml")];
|
|
143
|
+
let hasConfig = false;
|
|
144
|
+
for (const configFile of configFiles) if (await fs$1.pathExists(configFile)) {
|
|
145
|
+
print.header(`\n${icons.config} Configuration file found:`);
|
|
146
|
+
print.indent(path.basename(configFile));
|
|
147
|
+
hasConfig = true;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
if (!hasConfig) {
|
|
151
|
+
messages.warning("Warning: No configuration file found (boilerplate.yaml or scaffold.yaml)");
|
|
152
|
+
print.indent("You may need to create one manually.");
|
|
153
|
+
}
|
|
154
|
+
sections.nextSteps([`Review the template in ${targetFolder}`, `Test it with: scaffold-mcp ${templateType} list`]);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error.message.includes("not found") || error.message.includes("command not found")) messages.error("git command not found. Please install git first.");
|
|
157
|
+
else if (error.message.includes("Authentication failed")) messages.error("Authentication failed. Make sure you have access to the repository.");
|
|
158
|
+
else if (error.message.includes("Repository not found")) messages.error("Repository not found. Check the URL and try again.");
|
|
159
|
+
else messages.error("Failed to clone repository:", error);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
messages.error("Error adding template:", error);
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/commands/boilerplate.ts
|
|
170
|
+
/**
|
|
171
|
+
* Boilerplate CLI command
|
|
172
|
+
*/
|
|
173
|
+
const boilerplateCommand = new Command("boilerplate").description("Manage boilerplate templates");
|
|
174
|
+
boilerplateCommand.command("list").description("List all available boilerplate templates").action(async () => {
|
|
175
|
+
try {
|
|
176
|
+
const { boilerplates } = await new BoilerplateService(await TemplatesManagerService.findTemplatesPath()).listBoilerplates();
|
|
177
|
+
if (boilerplates.length === 0) {
|
|
178
|
+
messages.warning("No boilerplate templates found.");
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
print.header(`\n${icons.package} Available Boilerplate Templates:\n`);
|
|
182
|
+
for (const bp of boilerplates) {
|
|
183
|
+
print.highlight(` ${bp.name}`);
|
|
184
|
+
print.debug(` ${bp.description}`);
|
|
185
|
+
print.debug(` Target: ${bp.target_folder}`);
|
|
186
|
+
const required = typeof bp.variables_schema === "object" && bp.variables_schema !== null && "required" in bp.variables_schema ? bp.variables_schema.required : [];
|
|
187
|
+
if (required && required.length > 0) print.debug(` Required: ${required.join(", ")}`);
|
|
188
|
+
print.newline();
|
|
189
|
+
}
|
|
190
|
+
} catch (error) {
|
|
191
|
+
messages.error("Error listing boilerplates:", error);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
boilerplateCommand.command("create <boilerplateName>").description("Create a new project from a boilerplate template").option("-v, --vars <json>", "JSON string containing variables for the boilerplate").option("-m, --monolith", "Create as monolith project at workspace root with toolkit.yaml (default: false, creates as monorepo with project.json)").option("-t, --target-folder <path>", "Override target folder (defaults to boilerplate targetFolder for monorepo, workspace root for monolith)").option("--verbose", "Enable verbose logging").action(async (boilerplateName, options) => {
|
|
196
|
+
try {
|
|
197
|
+
const boilerplateService = new BoilerplateService(await TemplatesManagerService.findTemplatesPath());
|
|
198
|
+
let variables = {};
|
|
199
|
+
if (options.vars) try {
|
|
200
|
+
variables = JSON.parse(options.vars);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
messages.error("Error parsing variables JSON:", error);
|
|
203
|
+
messages.hint("Example: --vars '{\"appName\": \"my-app\", \"description\": \"My application\"}'");
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
const boilerplate = await boilerplateService.getBoilerplate(boilerplateName);
|
|
207
|
+
if (!boilerplate) {
|
|
208
|
+
const { boilerplates } = await boilerplateService.listBoilerplates();
|
|
209
|
+
messages.error(`Boilerplate '${boilerplateName}' not found.`);
|
|
210
|
+
print.warning(`Available boilerplates: ${boilerplates.map((b) => b.name).join(", ")}`);
|
|
211
|
+
process.exit(1);
|
|
212
|
+
}
|
|
213
|
+
const required = typeof boilerplate.variables_schema === "object" && boilerplate.variables_schema !== null && "required" in boilerplate.variables_schema ? boilerplate.variables_schema.required : [];
|
|
214
|
+
const missing = required.filter((key) => !variables[key]);
|
|
215
|
+
if (missing.length > 0) {
|
|
216
|
+
messages.error(`Missing required variables: ${missing.join(", ")}`);
|
|
217
|
+
messages.hint(`Use --vars with a JSON object containing: ${missing.join(", ")}`);
|
|
218
|
+
const exampleVars = {};
|
|
219
|
+
for (const key of required) if (key === "appName" || key === "packageName") exampleVars[key] = "my-app";
|
|
220
|
+
else if (key === "description") exampleVars[key] = "My application description";
|
|
221
|
+
else exampleVars[key] = `<${key}>`;
|
|
222
|
+
print.debug(`Example: scaffold-mcp boilerplate create ${boilerplateName} --vars '${JSON.stringify(exampleVars)}'`);
|
|
223
|
+
process.exit(1);
|
|
224
|
+
}
|
|
225
|
+
if (options.verbose) {
|
|
226
|
+
print.info(`${icons.wrench} Boilerplate: ${boilerplateName}`);
|
|
227
|
+
print.info(`${icons.chart} Variables: ${JSON.stringify(variables, null, 2)}`);
|
|
228
|
+
}
|
|
229
|
+
messages.loading(`Creating project from boilerplate '${boilerplateName}'...`);
|
|
230
|
+
const result = await boilerplateService.useBoilerplate({
|
|
231
|
+
boilerplateName,
|
|
232
|
+
variables,
|
|
233
|
+
monolith: options.monolith,
|
|
234
|
+
targetFolderOverride: options.targetFolder
|
|
235
|
+
});
|
|
236
|
+
if (result.success) {
|
|
237
|
+
messages.success("Project created successfully!");
|
|
238
|
+
print.info(result.message);
|
|
239
|
+
if (result.createdFiles && result.createdFiles.length > 0) sections.createdFiles(result.createdFiles);
|
|
240
|
+
const projectName = variables.appName || variables.packageName;
|
|
241
|
+
if (projectName) {
|
|
242
|
+
const targetFolder = options.targetFolder || (options.monolith ? "." : boilerplate.target_folder);
|
|
243
|
+
const projectPath = options.monolith ? "." : `${targetFolder}/${projectName}`;
|
|
244
|
+
const steps = projectPath === "." ? ["pnpm install", "pnpm dev"] : [
|
|
245
|
+
`cd ${projectPath}`,
|
|
246
|
+
"pnpm install",
|
|
247
|
+
"pnpm dev"
|
|
248
|
+
];
|
|
249
|
+
sections.nextSteps(steps);
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
messages.error(`Failed to create project: ${result.message}`);
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
255
|
+
} catch (error) {
|
|
256
|
+
messages.error("Error creating project:", error);
|
|
257
|
+
if (options.verbose) console.error("Stack trace:", error.stack);
|
|
258
|
+
process.exit(1);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
boilerplateCommand.command("info <boilerplateName>").description("Show detailed information about a boilerplate template").action(async (boilerplateName) => {
|
|
262
|
+
try {
|
|
263
|
+
const bp = await new BoilerplateService(await TemplatesManagerService.findTemplatesPath()).getBoilerplate(boilerplateName);
|
|
264
|
+
if (!bp) {
|
|
265
|
+
messages.error(`Boilerplate '${boilerplateName}' not found.`);
|
|
266
|
+
process.exit(1);
|
|
267
|
+
}
|
|
268
|
+
print.header(`\n${icons.package} Boilerplate: ${bp.name}\n`);
|
|
269
|
+
print.debug(`Description: ${bp.description}`);
|
|
270
|
+
print.debug(`Template Path: ${bp.template_path}`);
|
|
271
|
+
print.debug(`Target Folder: ${bp.target_folder}`);
|
|
272
|
+
print.header(`\n${icons.config} Variables Schema:`);
|
|
273
|
+
console.log(JSON.stringify(bp.variables_schema, null, 2));
|
|
274
|
+
if (bp.includes && bp.includes.length > 0) sections.list(`${icons.folder} Included Files:`, bp.includes);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
messages.error("Error getting boilerplate info:", error);
|
|
277
|
+
process.exit(1);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/commands/init.ts
|
|
283
|
+
/**
|
|
284
|
+
* Execute git init safely using execa to prevent command injection
|
|
285
|
+
*/
|
|
286
|
+
async function gitInit(projectPath) {
|
|
287
|
+
try {
|
|
288
|
+
await execa("git", ["init", projectPath]);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
const execaError = error;
|
|
291
|
+
throw new Error(`Git init failed: ${execaError.stderr || execaError.message}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const DEFAULT_TEMPLATE_REPO = {
|
|
295
|
+
owner: "AgiFlow",
|
|
296
|
+
repo: "aicode-toolkit",
|
|
297
|
+
branch: "main",
|
|
298
|
+
path: "templates"
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Interactive setup for new projects
|
|
302
|
+
* Prompts user for project details when no .git folder is found
|
|
303
|
+
* @param providedName - Optional project name from CLI argument
|
|
304
|
+
* @param providedProjectType - Optional project type from CLI argument
|
|
305
|
+
*/
|
|
306
|
+
async function setupNewProject(providedName, providedProjectType) {
|
|
307
|
+
print.header(`\n${icons.rocket} New Project Setup`);
|
|
308
|
+
print.info("No Git repository detected. Let's set up a new project!\n");
|
|
309
|
+
let projectName;
|
|
310
|
+
const reservedNames = [
|
|
311
|
+
".",
|
|
312
|
+
"..",
|
|
313
|
+
"CON",
|
|
314
|
+
"PRN",
|
|
315
|
+
"AUX",
|
|
316
|
+
"NUL",
|
|
317
|
+
"COM1",
|
|
318
|
+
"COM2",
|
|
319
|
+
"COM3",
|
|
320
|
+
"COM4",
|
|
321
|
+
"COM5",
|
|
322
|
+
"COM6",
|
|
323
|
+
"COM7",
|
|
324
|
+
"COM8",
|
|
325
|
+
"COM9",
|
|
326
|
+
"LPT1",
|
|
327
|
+
"LPT2",
|
|
328
|
+
"LPT3",
|
|
329
|
+
"LPT4",
|
|
330
|
+
"LPT5",
|
|
331
|
+
"LPT6",
|
|
332
|
+
"LPT7",
|
|
333
|
+
"LPT8",
|
|
334
|
+
"LPT9"
|
|
335
|
+
];
|
|
336
|
+
const validateProjectName = (value) => {
|
|
337
|
+
const trimmed = value.trim();
|
|
338
|
+
if (!trimmed) return "Project name is required";
|
|
339
|
+
if (!/^[a-zA-Z0-9]/.test(trimmed)) return "Project name must start with a letter or number";
|
|
340
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(trimmed)) return "Project name can only contain letters, numbers, hyphens, and underscores";
|
|
341
|
+
if (reservedNames.includes(trimmed.toUpperCase())) return "Project name uses a reserved name";
|
|
342
|
+
return true;
|
|
343
|
+
};
|
|
344
|
+
if (providedName) {
|
|
345
|
+
const trimmedName = providedName.trim();
|
|
346
|
+
const validationResult = validateProjectName(trimmedName);
|
|
347
|
+
if (validationResult !== true) throw new Error(validationResult);
|
|
348
|
+
projectName = trimmedName;
|
|
349
|
+
print.info(`Project name: ${projectName}`);
|
|
350
|
+
} else projectName = await input({
|
|
351
|
+
message: "Enter your project name:",
|
|
352
|
+
validate: validateProjectName
|
|
353
|
+
});
|
|
354
|
+
let projectType;
|
|
355
|
+
if (providedProjectType) {
|
|
356
|
+
if (providedProjectType !== ProjectType.MONOLITH && providedProjectType !== ProjectType.MONOREPO) throw new Error(`Invalid project type '${providedProjectType}'. Must be '${ProjectType.MONOLITH}' or '${ProjectType.MONOREPO}'`);
|
|
357
|
+
projectType = providedProjectType;
|
|
358
|
+
print.info(`Project type: ${projectType}`);
|
|
359
|
+
} else projectType = await select({
|
|
360
|
+
message: "Select project type:",
|
|
361
|
+
choices: [{
|
|
362
|
+
name: "Monolith - Single application structure",
|
|
363
|
+
value: ProjectType.MONOLITH,
|
|
364
|
+
description: "Traditional single-application project structure"
|
|
365
|
+
}, {
|
|
366
|
+
name: "Monorepo - Multiple packages/apps in one repository",
|
|
367
|
+
value: ProjectType.MONOREPO,
|
|
368
|
+
description: "Multiple packages managed together (uses workspaces)"
|
|
369
|
+
}]
|
|
370
|
+
});
|
|
371
|
+
const hasExistingRepo = await confirm({
|
|
372
|
+
message: "Do you have an existing Git repository you want to use?",
|
|
373
|
+
default: false
|
|
374
|
+
});
|
|
375
|
+
const projectPath = path.join(process.cwd(), projectName.trim());
|
|
376
|
+
try {
|
|
377
|
+
await fs$1.mkdir(projectPath, { recursive: false });
|
|
378
|
+
print.success(`${icons.check} Created project directory: ${projectPath}`);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
if (error.code === "EEXIST") throw new Error(`Directory '${projectName}' already exists. Please choose a different name.`);
|
|
381
|
+
throw error;
|
|
382
|
+
}
|
|
383
|
+
if (hasExistingRepo) {
|
|
384
|
+
const repoUrl = await input({
|
|
385
|
+
message: "Enter Git repository URL:",
|
|
386
|
+
validate: (value) => {
|
|
387
|
+
if (!value.trim()) return "Repository URL is required";
|
|
388
|
+
if (!value.match(/^(https?:\/\/|git@)/)) return "Please enter a valid Git repository URL";
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
print.info(`${icons.download} Cloning repository...`);
|
|
393
|
+
try {
|
|
394
|
+
const parsed = parseGitHubUrl(repoUrl.trim());
|
|
395
|
+
if (parsed.isSubdirectory && parsed.branch && parsed.subdirectory) await cloneSubdirectory(parsed.repoUrl, parsed.branch, parsed.subdirectory, projectPath);
|
|
396
|
+
else await cloneRepository(parsed.repoUrl, projectPath);
|
|
397
|
+
print.success(`${icons.check} Repository cloned successfully`);
|
|
398
|
+
} catch (error) {
|
|
399
|
+
await fs$1.remove(projectPath);
|
|
400
|
+
throw new Error(`Failed to clone repository: ${error.message}`);
|
|
401
|
+
}
|
|
402
|
+
} else if (await confirm({
|
|
403
|
+
message: "Initialize a new Git repository?",
|
|
404
|
+
default: true
|
|
405
|
+
})) {
|
|
406
|
+
print.info(`${icons.rocket} Initializing Git repository...`);
|
|
407
|
+
try {
|
|
408
|
+
await gitInit(projectPath);
|
|
409
|
+
print.success(`${icons.check} Git repository initialized`);
|
|
410
|
+
} catch (error) {
|
|
411
|
+
messages.warning(`Failed to initialize Git: ${error.message}`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return {
|
|
415
|
+
projectPath,
|
|
416
|
+
projectType
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Download templates from GitHub repository
|
|
421
|
+
*/
|
|
422
|
+
async function downloadTemplates(templatesPath) {
|
|
423
|
+
try {
|
|
424
|
+
print.info(`${icons.download} Fetching templates from ${DEFAULT_TEMPLATE_REPO.owner}/${DEFAULT_TEMPLATE_REPO.repo}...`);
|
|
425
|
+
const templateDirs = (await fetchGitHubDirectoryContents(DEFAULT_TEMPLATE_REPO.owner, DEFAULT_TEMPLATE_REPO.repo, DEFAULT_TEMPLATE_REPO.path, DEFAULT_TEMPLATE_REPO.branch)).filter((item) => item.type === "dir");
|
|
426
|
+
if (templateDirs.length === 0) {
|
|
427
|
+
messages.warning("No templates found in repository");
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
print.info(`${icons.folder} Found ${templateDirs.length} template(s)`);
|
|
431
|
+
for (const template of templateDirs) {
|
|
432
|
+
const targetFolder = path.join(templatesPath, template.name);
|
|
433
|
+
if (await fs$1.pathExists(targetFolder)) {
|
|
434
|
+
print.info(`${icons.skip} Skipping ${template.name} (already exists)`);
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
print.info(`${icons.download} Downloading ${template.name}...`);
|
|
438
|
+
await cloneSubdirectory(`https://github.com/${DEFAULT_TEMPLATE_REPO.owner}/${DEFAULT_TEMPLATE_REPO.repo}.git`, DEFAULT_TEMPLATE_REPO.branch, template.path, targetFolder);
|
|
439
|
+
print.success(`${icons.check} Downloaded ${template.name}`);
|
|
440
|
+
}
|
|
441
|
+
print.success(`\n${icons.check} All templates downloaded successfully!`);
|
|
442
|
+
} catch (error) {
|
|
443
|
+
throw new Error(`Failed to download templates: ${error.message}`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Init command - initialize templates folder
|
|
448
|
+
*/
|
|
449
|
+
const initCommand = new Command("init").description("Initialize templates folder structure at workspace root or create new project").option("--no-download", "Skip downloading templates from repository").option("--path <path>", "Custom path for templates folder (relative to workspace root)").option("--name <name>", "Project name (for new projects)").option("--project-type <type>", "Project type: monolith or monorepo (for new projects)").action(async (options) => {
|
|
450
|
+
try {
|
|
451
|
+
let workspaceRoot = await findWorkspaceRoot();
|
|
452
|
+
let projectType;
|
|
453
|
+
if (!workspaceRoot) {
|
|
454
|
+
const projectSetup = await setupNewProject(options.name, options.projectType);
|
|
455
|
+
workspaceRoot = projectSetup.projectPath;
|
|
456
|
+
projectType = projectSetup.projectType;
|
|
457
|
+
print.info(`\n${icons.folder} Project type: ${projectType}`);
|
|
458
|
+
}
|
|
459
|
+
let templatesPath = options.path ? path.join(workspaceRoot, options.path) : path.join(workspaceRoot, "templates");
|
|
460
|
+
if (await fs$1.pathExists(templatesPath)) {
|
|
461
|
+
messages.warning(`\n⚠️ Templates folder already exists at: ${templatesPath}`);
|
|
462
|
+
if (await confirm({
|
|
463
|
+
message: "Do you want to use a different folder for templates?",
|
|
464
|
+
default: false
|
|
465
|
+
})) {
|
|
466
|
+
const alternateFolder = await input({
|
|
467
|
+
message: "Enter alternate folder name for templates:",
|
|
468
|
+
default: "my-templates",
|
|
469
|
+
validate: (value) => {
|
|
470
|
+
if (!value.trim()) return "Folder name is required";
|
|
471
|
+
if (!/^[a-zA-Z0-9_\-/]+$/.test(value)) return "Folder name can only contain letters, numbers, hyphens, underscores, and slashes";
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
templatesPath = path.join(workspaceRoot, alternateFolder.trim());
|
|
476
|
+
const toolkitConfig = {
|
|
477
|
+
templatesPath: alternateFolder.trim(),
|
|
478
|
+
projectType
|
|
479
|
+
};
|
|
480
|
+
print.info(`\n${icons.config} Creating toolkit.yaml with custom templates path...`);
|
|
481
|
+
await TemplatesManagerService.writeToolkitConfig(toolkitConfig, workspaceRoot);
|
|
482
|
+
print.success(`${icons.check} toolkit.yaml created`);
|
|
483
|
+
} else print.info(`\n${icons.info} Using existing templates folder`);
|
|
484
|
+
}
|
|
485
|
+
print.info(`\n${icons.rocket} Initializing templates folder at: ${templatesPath}`);
|
|
486
|
+
await fs$1.ensureDir(templatesPath);
|
|
487
|
+
await fs$1.writeFile(path.join(templatesPath, "README.md"), `# Templates
|
|
488
|
+
|
|
489
|
+
This folder contains boilerplate templates and scaffolding methods for your projects.
|
|
490
|
+
|
|
491
|
+
## Templates
|
|
492
|
+
|
|
493
|
+
Templates are organized by framework/technology and include configuration files (\`scaffold.yaml\`) that define:
|
|
494
|
+
- Boilerplates: Full project starter templates
|
|
495
|
+
- Features: Code scaffolding methods for adding new features to existing projects
|
|
496
|
+
|
|
497
|
+
## Adding More Templates
|
|
498
|
+
|
|
499
|
+
Use the \`aicode-toolkit\` CLI to add templates from remote repositories:
|
|
500
|
+
|
|
501
|
+
\`\`\`bash
|
|
502
|
+
npx @agiflowai/aicode-toolkit add --name my-template --url https://github.com/user/template
|
|
503
|
+
\`\`\`
|
|
504
|
+
|
|
505
|
+
Or add templates from subdirectories:
|
|
506
|
+
|
|
507
|
+
\`\`\`bash
|
|
508
|
+
npx @agiflowai/aicode-toolkit add --name nextjs-template --url https://github.com/user/repo/tree/main/templates/nextjs
|
|
509
|
+
\`\`\`
|
|
510
|
+
|
|
511
|
+
## Creating Custom Templates
|
|
512
|
+
|
|
513
|
+
Each template should have a \`scaffold.yaml\` configuration file defining:
|
|
514
|
+
- \`boilerplate\`: Array of boilerplate configurations
|
|
515
|
+
- \`features\`: Array of feature scaffold configurations
|
|
516
|
+
|
|
517
|
+
Template files use Liquid syntax for variable placeholders: \`{{ variableName }}\`
|
|
518
|
+
|
|
519
|
+
See existing templates for examples and documentation for more details.
|
|
520
|
+
`);
|
|
521
|
+
print.success(`${icons.check} Templates folder created!`);
|
|
522
|
+
if (options.download !== false) await downloadTemplates(templatesPath);
|
|
523
|
+
else print.info(`${icons.skip} Skipping template download (use --download to enable)`);
|
|
524
|
+
print.header(`\n${icons.folder} Templates location:`);
|
|
525
|
+
print.indent(templatesPath);
|
|
526
|
+
const nextSteps = [];
|
|
527
|
+
if (options.download === false) nextSteps.push(`Add templates: npx @agiflowai/aicode-toolkit add --name <name> --url <url>`);
|
|
528
|
+
else {
|
|
529
|
+
nextSteps.push(`List available boilerplates: scaffold-mcp boilerplate list`);
|
|
530
|
+
nextSteps.push(`Add more templates: npx @agiflowai/aicode-toolkit add --name <name> --url <url>`);
|
|
531
|
+
}
|
|
532
|
+
sections.nextSteps(nextSteps);
|
|
533
|
+
} catch (error) {
|
|
534
|
+
messages.error(`Error initializing templates folder: ${error.message}`);
|
|
535
|
+
process.exit(1);
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/prompts/GenerateBoilerplatePrompt.ts
|
|
541
|
+
/**
|
|
542
|
+
* Prompt for generating boilerplates
|
|
543
|
+
*/
|
|
544
|
+
var GenerateBoilerplatePrompt = class GenerateBoilerplatePrompt {
|
|
545
|
+
static PROMPT_NAME = "generate-boilerplate";
|
|
546
|
+
/**
|
|
547
|
+
* Get the prompt definition for MCP
|
|
548
|
+
*/
|
|
549
|
+
getDefinition() {
|
|
550
|
+
return {
|
|
551
|
+
name: GenerateBoilerplatePrompt.PROMPT_NAME,
|
|
552
|
+
description: "Generate a new boilerplate template configuration",
|
|
553
|
+
arguments: [{
|
|
554
|
+
name: "request",
|
|
555
|
+
description: "Describe the boilerplate template you want to create",
|
|
556
|
+
required: false
|
|
557
|
+
}]
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Get the prompt messages
|
|
562
|
+
*/
|
|
563
|
+
getMessages(args) {
|
|
564
|
+
const userRequest = args?.request || "";
|
|
565
|
+
return [{
|
|
566
|
+
role: "user",
|
|
567
|
+
content: {
|
|
568
|
+
type: "text",
|
|
569
|
+
text: `You are helping create a new boilerplate template configuration using the scaffold-mcp MCP tools.
|
|
570
|
+
|
|
571
|
+
${userRequest ? `User request: ${userRequest}\n` : ""}
|
|
572
|
+
Your task:
|
|
573
|
+
|
|
574
|
+
1. **Gather Information**: Ask for any missing details:
|
|
575
|
+
- Framework/technology (e.g., "React Vite", "Express API", "Next.js 15")
|
|
576
|
+
- Template name (kebab-case, e.g., "react-vite", "nextjs-15")
|
|
577
|
+
- Boilerplate name (prefixed with "scaffold-", e.g., "scaffold-vite-app")
|
|
578
|
+
- Target folder (e.g., "apps", "packages")
|
|
579
|
+
- Project type (app, library, service, etc.)
|
|
580
|
+
- Required variables (at minimum: appName or packageName)
|
|
581
|
+
- Files to include in the template
|
|
582
|
+
|
|
583
|
+
2. **Use MCP Tools** in order:
|
|
584
|
+
- \`generate-boilerplate\` - Creates the boilerplate configuration
|
|
585
|
+
- \`generate-boilerplate-file\` - Creates each template file
|
|
586
|
+
- \`list-boilerplates\` - Verify it appears
|
|
587
|
+
- \`use-boilerplate\` - Test the boilerplate
|
|
588
|
+
|
|
589
|
+
Important:
|
|
590
|
+
- Template naming: Use kebab-case (e.g., "react-vite", "express-api")
|
|
591
|
+
- Boilerplate naming: Prefix with "scaffold-" (e.g., "scaffold-vite-app")
|
|
592
|
+
- Target folder: "apps" for applications, "packages" for libraries
|
|
593
|
+
- Include files explicitly - avoid wildcards
|
|
594
|
+
- Template syntax: use {{ variableName }}
|
|
595
|
+
|
|
596
|
+
**Description Field Guidelines (CRITICAL)**:
|
|
597
|
+
The description should be a comprehensive multi-paragraph overview (3-5 sentences):
|
|
598
|
+
- Paragraph 1: Core technology stack and primary value proposition
|
|
599
|
+
- Paragraph 2: Target use cases and ideal project types
|
|
600
|
+
- Paragraph 3: Key integrations or special features (if applicable)
|
|
601
|
+
|
|
602
|
+
Example:
|
|
603
|
+
"A modern React SPA template powered by Vite for lightning-fast HMR, featuring TanStack Router for type-safe routing and TanStack Query for server state management.
|
|
604
|
+
Perfect for building data-driven dashboards, admin panels, and interactive web applications requiring client-side routing and real-time data synchronization.
|
|
605
|
+
|
|
606
|
+
Includes Agiflow Config Management System integration with systematic environment variable naming (VITE_{CATEGORY}_{SUBCATEGORY}_{PROPERTY}) and auto-generated configuration templates for cloud deployment."
|
|
607
|
+
|
|
608
|
+
**Instruction Field Guidelines (CRITICAL)**:
|
|
609
|
+
The instruction should be a detailed multi-section guide that helps AI understand the codebase:
|
|
610
|
+
|
|
611
|
+
1. **File purposes** section: List each major file/directory with its purpose
|
|
612
|
+
Format: "- path/to/file: Description of what this file does"
|
|
613
|
+
|
|
614
|
+
2. **How to use the scaffolded code** section: Step-by-step workflows
|
|
615
|
+
Format: Numbered list with specific examples
|
|
616
|
+
- How to add routes/pages
|
|
617
|
+
- How to fetch data
|
|
618
|
+
- How to handle authentication
|
|
619
|
+
- How to configure environment variables
|
|
620
|
+
|
|
621
|
+
3. **Design patterns to follow** section: Key architectural decisions
|
|
622
|
+
Format: "- Pattern Name: Explanation and when to use it"
|
|
623
|
+
- Routing patterns
|
|
624
|
+
- State management patterns
|
|
625
|
+
- Data fetching patterns
|
|
626
|
+
- Error handling patterns
|
|
627
|
+
- Performance optimization patterns
|
|
628
|
+
|
|
629
|
+
Example structure:
|
|
630
|
+
"[Framework] application template with [key technologies].
|
|
631
|
+
|
|
632
|
+
File purposes:
|
|
633
|
+
- package.json: NPM package configuration with [framework] and dependencies
|
|
634
|
+
- src/main.tsx: Application entry point with [setup details]
|
|
635
|
+
- src/routes/: Route definitions following [pattern]
|
|
636
|
+
[... list all major files ...]
|
|
637
|
+
|
|
638
|
+
How to use the scaffolded code:
|
|
639
|
+
1. Routes: Create new routes by [specific instructions with example]
|
|
640
|
+
2. Data Fetching: Use [specific pattern] for [use case]
|
|
641
|
+
3. Authentication: Use [specific components/modules] for user management
|
|
642
|
+
[... numbered steps for common tasks ...]
|
|
643
|
+
|
|
644
|
+
Design patterns to follow:
|
|
645
|
+
- File-based Routing: Use directory structure in src/routes/ to define URL paths
|
|
646
|
+
- Type-safe Routes: Leverage [framework] type inference for params
|
|
647
|
+
- State Management: Use [library] for server state, [library] for client state
|
|
648
|
+
[... list key patterns with explanations ...]"
|
|
649
|
+
|
|
650
|
+
Template File Content Guidelines:
|
|
651
|
+
- Keep content MINIMAL and business-agnostic
|
|
652
|
+
- Focus on structure and patterns, not business logic
|
|
653
|
+
- Use placeholder/generic examples only
|
|
654
|
+
- Include essential boilerplate code only
|
|
655
|
+
- Let AI fill in specific logic later
|
|
656
|
+
- Add clear headers with design patterns and coding standards`
|
|
657
|
+
}
|
|
658
|
+
}];
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/prompts/GenerateFeatureScaffoldPrompt.ts
|
|
664
|
+
/**
|
|
665
|
+
* Prompt for generating feature scaffolds
|
|
666
|
+
*/
|
|
667
|
+
var GenerateFeatureScaffoldPrompt = class GenerateFeatureScaffoldPrompt {
|
|
668
|
+
static PROMPT_NAME = "generate-feature-scaffold";
|
|
669
|
+
/**
|
|
670
|
+
* Get the prompt definition for MCP
|
|
671
|
+
*/
|
|
672
|
+
getDefinition() {
|
|
673
|
+
return {
|
|
674
|
+
name: GenerateFeatureScaffoldPrompt.PROMPT_NAME,
|
|
675
|
+
description: "Generate a new feature scaffold configuration",
|
|
676
|
+
arguments: [{
|
|
677
|
+
name: "request",
|
|
678
|
+
description: "Describe the feature scaffold you want to create",
|
|
679
|
+
required: false
|
|
680
|
+
}]
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Get the prompt messages
|
|
685
|
+
*/
|
|
686
|
+
getMessages(args) {
|
|
687
|
+
const userRequest = args?.request || "";
|
|
688
|
+
return [{
|
|
689
|
+
role: "user",
|
|
690
|
+
content: {
|
|
691
|
+
type: "text",
|
|
692
|
+
text: `You are helping create a new feature scaffold configuration using the scaffold-mcp MCP tools.
|
|
693
|
+
|
|
694
|
+
${userRequest ? `User request: ${userRequest}\n` : ""}
|
|
695
|
+
Your task:
|
|
696
|
+
|
|
697
|
+
1. **Gather Information**: Ask for any missing details:
|
|
698
|
+
- Template name (e.g., "nextjs-15", "react-vite")
|
|
699
|
+
- Feature name (prefixed with "scaffold-", e.g., "scaffold-nextjs-page")
|
|
700
|
+
- Feature type (page, component, service, etc.)
|
|
701
|
+
- Variables needed
|
|
702
|
+
- Files to include
|
|
703
|
+
|
|
704
|
+
2. **Use MCP Tools** in order:
|
|
705
|
+
- \`generate-feature-scaffold\` - Creates the feature configuration
|
|
706
|
+
- \`generate-boilerplate-file\` - Creates each template file
|
|
707
|
+
- \`list-scaffolding-methods\` - Verify it appears
|
|
708
|
+
- \`use-scaffold-method\` - Test the feature
|
|
709
|
+
|
|
710
|
+
Important:
|
|
711
|
+
- Feature names: prefix with "scaffold-"
|
|
712
|
+
- Conditional includes: use "file.tsx?withLayout=true"
|
|
713
|
+
- Template syntax: use {{ variableName }}
|
|
714
|
+
|
|
715
|
+
**Description Field Guidelines (CRITICAL)**:
|
|
716
|
+
The description should explain what the feature scaffold generates (2-3 sentences):
|
|
717
|
+
- Sentence 1: What type of code it generates (component, page, service, etc.)
|
|
718
|
+
- Sentence 2: Key features or capabilities included
|
|
719
|
+
- Sentence 3: Primary use cases or when to use it
|
|
720
|
+
|
|
721
|
+
Example:
|
|
722
|
+
"Generate a new service class for TypeScript libraries following best practices. Creates a service class with interface, implementation, and unit tests. Perfect for creating reusable service modules with dependency injection patterns."
|
|
723
|
+
|
|
724
|
+
**Instruction Field Guidelines (CRITICAL)**:
|
|
725
|
+
The instruction should provide specific guidance for using the generated feature:
|
|
726
|
+
|
|
727
|
+
1. **Pattern explanation**: Describe the architectural pattern used
|
|
728
|
+
2. **File organization**: Where files should be placed
|
|
729
|
+
3. **Naming conventions**: How to name things (PascalCase, camelCase, etc.)
|
|
730
|
+
4. **Usage guidelines**: How to use the generated code
|
|
731
|
+
5. **Testing approach**: How to test the feature
|
|
732
|
+
|
|
733
|
+
Example structure:
|
|
734
|
+
"[Feature type] follow a [pattern name] pattern with [key characteristics].
|
|
735
|
+
[Explanation of how it works and integrates with the project].
|
|
736
|
+
Place [files] in [directory].
|
|
737
|
+
For [features with X], define [Y] in [Z] for better separation of concerns.
|
|
738
|
+
[Feature names] should be [case style] and [suffix/prefix rules].
|
|
739
|
+
Write comprehensive [tests/docs] for all [public methods/exports]."
|
|
740
|
+
|
|
741
|
+
Keep it concise but informative - focus on the patterns and conventions that AI needs to understand to work with the generated code effectively.
|
|
742
|
+
|
|
743
|
+
Template File Content Guidelines:
|
|
744
|
+
- Keep content MINIMAL and business-agnostic
|
|
745
|
+
- Focus on structure and patterns, not business logic
|
|
746
|
+
- Use placeholder/generic examples only
|
|
747
|
+
- Include essential boilerplate code only
|
|
748
|
+
- Let AI fill in specific logic later
|
|
749
|
+
- Add clear headers with design patterns and coding standards`
|
|
750
|
+
}
|
|
751
|
+
}];
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
//#endregion
|
|
756
|
+
//#region src/prompts/ScaffoldApplicationPrompt.ts
|
|
757
|
+
/**
|
|
758
|
+
* Prompt for scaffolding a new application using boilerplate templates
|
|
759
|
+
*/
|
|
760
|
+
var ScaffoldApplicationPrompt = class ScaffoldApplicationPrompt {
|
|
761
|
+
static PROMPT_NAME = "scaffold-application";
|
|
762
|
+
/**
|
|
763
|
+
* Get the prompt definition for MCP
|
|
764
|
+
*/
|
|
765
|
+
getDefinition() {
|
|
766
|
+
return {
|
|
767
|
+
name: ScaffoldApplicationPrompt.PROMPT_NAME,
|
|
768
|
+
description: "Scaffold a new application from a boilerplate template",
|
|
769
|
+
arguments: [{
|
|
770
|
+
name: "request",
|
|
771
|
+
description: "Describe the application you want to create (optional)",
|
|
772
|
+
required: false
|
|
773
|
+
}]
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Get the prompt messages
|
|
778
|
+
*/
|
|
779
|
+
getMessages(args) {
|
|
780
|
+
const userRequest = args?.request || "";
|
|
781
|
+
return [{
|
|
782
|
+
role: "user",
|
|
783
|
+
content: {
|
|
784
|
+
type: "text",
|
|
785
|
+
text: `You are helping create a new application using the scaffold-mcp MCP tools.
|
|
786
|
+
|
|
787
|
+
${userRequest ? `User request: ${userRequest}\n` : ""}
|
|
788
|
+
Your task is to scaffold a new application by following this workflow:
|
|
789
|
+
|
|
790
|
+
## Step 1: List Available Boilerplates
|
|
791
|
+
Use the \`list-boilerplates\` tool to see all available project templates.
|
|
792
|
+
|
|
793
|
+
**What to look for:**
|
|
794
|
+
- Boilerplate name (e.g., "scaffold-nextjs-app", "scaffold-vite-app")
|
|
795
|
+
- Description of what the boilerplate creates
|
|
796
|
+
- Target folder where projects will be created (e.g., "apps", "packages")
|
|
797
|
+
- Required and optional variables in the variables_schema
|
|
798
|
+
|
|
799
|
+
## Step 2: Gather Required Information
|
|
800
|
+
Based on the selected boilerplate's variables_schema, collect:
|
|
801
|
+
- **Project name**: Must be kebab-case (e.g., "my-new-app", not "MyNewApp")
|
|
802
|
+
- **Required variables**: All variables marked as required: true
|
|
803
|
+
- **Optional variables**: Variables with required: false (ask user if needed)
|
|
804
|
+
|
|
805
|
+
Common variables:
|
|
806
|
+
- \`appName\` or \`packageName\`: The project name (kebab-case)
|
|
807
|
+
- \`description\`: Brief description of what the project does
|
|
808
|
+
- \`author\`: Author name
|
|
809
|
+
|
|
810
|
+
## Step 3: Execute the Boilerplate
|
|
811
|
+
Use the \`use-boilerplate\` tool with:
|
|
812
|
+
- \`boilerplateName\`: Exact name from list-boilerplates response
|
|
813
|
+
- \`variables\`: Object matching the variables_schema exactly
|
|
814
|
+
|
|
815
|
+
**Example:**
|
|
816
|
+
\`\`\`json
|
|
817
|
+
{
|
|
818
|
+
"boilerplateName": "scaffold-nextjs-app",
|
|
819
|
+
"variables": {
|
|
820
|
+
"appName": "my-dashboard",
|
|
821
|
+
"description": "Admin dashboard for managing users",
|
|
822
|
+
"author": "John Doe"
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
\`\`\`
|
|
826
|
+
|
|
827
|
+
## Important Guidelines:
|
|
828
|
+
- **Always call \`list-boilerplates\` first** to see available options and their schemas
|
|
829
|
+
- **Use exact variable names** from the schema (case-sensitive)
|
|
830
|
+
- **Provide all required variables** - the tool will fail if any are missing
|
|
831
|
+
- **Use kebab-case for project names** (e.g., "user-dashboard", not "UserDashboard")
|
|
832
|
+
- The tool will create the project in the appropriate directory automatically
|
|
833
|
+
- After creation, inform the user where the project was created
|
|
834
|
+
|
|
835
|
+
## Step 4: Review and Add Features (If Needed)
|
|
836
|
+
After the boilerplate is created, **consider if additional features are needed**:
|
|
837
|
+
1. **READ** the generated project structure to understand what was created
|
|
838
|
+
2. **REVIEW** the user's request to see if they asked for specific features (e.g., "with tool for X", "with prompt for Y")
|
|
839
|
+
3. **If features are needed**:
|
|
840
|
+
- Use \`list-scaffolding-methods\` with the new project path
|
|
841
|
+
- Use \`use-scaffold-method\` to add tools, services, prompts, etc.
|
|
842
|
+
- **IMPLEMENT** the actual logic in the scaffolded feature files
|
|
843
|
+
- **REGISTER** the features in \`src/server/index.ts\`
|
|
844
|
+
4. **Install dependencies**: Remind user to run \`pnpm install\`
|
|
845
|
+
5. **Report** the complete setup including any features added
|
|
846
|
+
|
|
847
|
+
## Example Workflow:
|
|
848
|
+
1. Call \`list-boilerplates\` → See available templates
|
|
849
|
+
2. Ask user which template to use (or infer from request)
|
|
850
|
+
3. Collect required variables based on schema
|
|
851
|
+
4. Call \`use-boilerplate\` with boilerplateName and variables
|
|
852
|
+
5. **Review if user requested specific features (tools, prompts, etc.)**
|
|
853
|
+
6. **If features needed**: Add them using \`list-scaffolding-methods\` and \`use-scaffold-method\`
|
|
854
|
+
7. **READ and IMPLEMENT** the scaffolded feature files with actual logic
|
|
855
|
+
8. Report success and next steps to the user`
|
|
856
|
+
}
|
|
857
|
+
}];
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/prompts/ScaffoldFeaturePrompt.ts
|
|
863
|
+
/**
|
|
864
|
+
* Prompt for scaffolding a new feature in an existing project
|
|
865
|
+
*/
|
|
866
|
+
var ScaffoldFeaturePrompt = class ScaffoldFeaturePrompt {
|
|
867
|
+
static PROMPT_NAME = "scaffold-feature";
|
|
868
|
+
/**
|
|
869
|
+
* Get the prompt definition for MCP
|
|
870
|
+
*/
|
|
871
|
+
getDefinition() {
|
|
872
|
+
return {
|
|
873
|
+
name: ScaffoldFeaturePrompt.PROMPT_NAME,
|
|
874
|
+
description: "Scaffold a new feature (page, component, service, etc.) in an existing project",
|
|
875
|
+
arguments: [{
|
|
876
|
+
name: "request",
|
|
877
|
+
description: "Describe the feature you want to add (optional)",
|
|
878
|
+
required: false
|
|
879
|
+
}, {
|
|
880
|
+
name: "projectPath",
|
|
881
|
+
description: "Path to the project (e.g., \"apps/my-app\") - optional if can be inferred",
|
|
882
|
+
required: false
|
|
883
|
+
}]
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Get the prompt messages
|
|
888
|
+
*/
|
|
889
|
+
getMessages(args) {
|
|
890
|
+
const userRequest = args?.request || "";
|
|
891
|
+
const projectPath = args?.projectPath || "";
|
|
892
|
+
return [{
|
|
893
|
+
role: "user",
|
|
894
|
+
content: {
|
|
895
|
+
type: "text",
|
|
896
|
+
text: `You are helping add a new feature to an existing project using the scaffold-mcp MCP tools.
|
|
897
|
+
|
|
898
|
+
${userRequest ? `User request: ${userRequest}\n` : ""}${projectPath ? `Project path: ${projectPath}\n` : ""}
|
|
899
|
+
Your task is to scaffold a new feature by following this workflow:
|
|
900
|
+
|
|
901
|
+
## Step 1: Identify the Project
|
|
902
|
+
Determine the project path where the feature will be added:
|
|
903
|
+
- If projectPath is provided, use it
|
|
904
|
+
- Otherwise, ask the user or infer from context (e.g., "apps/my-app", "packages/my-lib")
|
|
905
|
+
- The path should point to a directory containing a \`project.json\` file
|
|
906
|
+
|
|
907
|
+
## Step 2: List Available Scaffolding Methods
|
|
908
|
+
Use the \`list-scaffolding-methods\` tool with the projectPath.
|
|
909
|
+
|
|
910
|
+
**What to look for:**
|
|
911
|
+
- Feature name (e.g., "scaffold-nextjs-page", "scaffold-react-component")
|
|
912
|
+
- Description of what files/code it generates
|
|
913
|
+
- Required and optional variables in the variables_schema
|
|
914
|
+
- The template type (derived from project's sourceTemplate)
|
|
915
|
+
|
|
916
|
+
**Example:**
|
|
917
|
+
\`\`\`json
|
|
918
|
+
{
|
|
919
|
+
"projectPath": "apps/my-dashboard"
|
|
920
|
+
}
|
|
921
|
+
\`\`\`
|
|
922
|
+
|
|
923
|
+
## Step 3: Gather Required Information
|
|
924
|
+
Based on the selected scaffolding method's variables_schema, collect:
|
|
925
|
+
- **Feature-specific variables**: Name, path, type, etc.
|
|
926
|
+
- **Required variables**: All variables marked as required: true
|
|
927
|
+
- **Optional variables**: Variables with required: false (ask user if needed)
|
|
928
|
+
|
|
929
|
+
Common variables:
|
|
930
|
+
- \`componentName\` / \`pageName\` / \`serviceName\`: Name in PascalCase
|
|
931
|
+
- \`componentPath\` / \`pagePath\`: Where to place the file (may use kebab-case)
|
|
932
|
+
- Boolean flags: \`withTests\`, \`withLayout\`, \`withStyles\`, etc.
|
|
933
|
+
|
|
934
|
+
## Step 4: Execute the Scaffolding Method
|
|
935
|
+
Use the \`use-scaffold-method\` tool with:
|
|
936
|
+
- \`projectPath\`: Same path from step 1
|
|
937
|
+
- \`scaffold_feature_name\`: Exact name from list-scaffolding-methods response
|
|
938
|
+
- \`variables\`: Object matching the variables_schema exactly
|
|
939
|
+
|
|
940
|
+
**Example:**
|
|
941
|
+
\`\`\`json
|
|
942
|
+
{
|
|
943
|
+
"projectPath": "apps/my-dashboard",
|
|
944
|
+
"scaffold_feature_name": "scaffold-nextjs-page",
|
|
945
|
+
"variables": {
|
|
946
|
+
"pageName": "UserProfile",
|
|
947
|
+
"pagePath": "user/profile",
|
|
948
|
+
"withLayout": true,
|
|
949
|
+
"withTests": false
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
\`\`\`
|
|
953
|
+
|
|
954
|
+
## Important Guidelines:
|
|
955
|
+
- **Always call \`list-scaffolding-methods\` first** with the projectPath
|
|
956
|
+
- **Use exact variable names** from the schema (case-sensitive)
|
|
957
|
+
- **Provide all required variables** - the tool will fail if any are missing
|
|
958
|
+
- **Follow naming conventions**:
|
|
959
|
+
- Component/Page/Service names: PascalCase (e.g., "UserProfile")
|
|
960
|
+
- File paths: kebab-case or as specified in schema (e.g., "user/profile")
|
|
961
|
+
- **Conditional files**: Files with \`?condition=true\` are only included when the variable is true
|
|
962
|
+
- The tool will create files in the appropriate locations automatically
|
|
963
|
+
- After creation, inform the user what files were created
|
|
964
|
+
|
|
965
|
+
## Step 5: Review and Implement Generated Files
|
|
966
|
+
After scaffolding completes, **you MUST**:
|
|
967
|
+
1. **READ** all generated files to understand their structure
|
|
968
|
+
2. **IMPLEMENT** the actual business logic:
|
|
969
|
+
- Replace TODO comments with real code
|
|
970
|
+
- Replace template placeholders with actual implementation
|
|
971
|
+
- Add the specific functionality described in the user's request
|
|
972
|
+
3. **REGISTER** the feature in appropriate files:
|
|
973
|
+
- Import and register tools in \`src/server/index.ts\`
|
|
974
|
+
- Export new modules from \`index.ts\` files
|
|
975
|
+
- Update any necessary configuration files
|
|
976
|
+
4. **TEST** to ensure the implementation works correctly
|
|
977
|
+
5. **DO NOT SKIP** this step - scaffolded files are templates that need actual code
|
|
978
|
+
|
|
979
|
+
## Example Workflow:
|
|
980
|
+
1. Identify project path (provided or ask user)
|
|
981
|
+
2. Call \`list-scaffolding-methods\` → See available features for this project
|
|
982
|
+
3. Ask user which feature to add (or infer from request)
|
|
983
|
+
4. Collect required variables based on schema
|
|
984
|
+
5. Call \`use-scaffold-method\` with projectPath, scaffold_feature_name, and variables
|
|
985
|
+
6. **READ the generated files and IMPLEMENT the actual logic**
|
|
986
|
+
7. **REGISTER the feature in server/index.ts and other config files**
|
|
987
|
+
8. Report success and list created files with implementation details`
|
|
988
|
+
}
|
|
989
|
+
}];
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
//#endregion
|
|
994
|
+
//#region src/server/index.ts
|
|
995
|
+
function createServer(options = {}) {
|
|
996
|
+
const { adminEnabled = false } = options;
|
|
997
|
+
const templatesPath = TemplatesManagerService.findTemplatesPathSync();
|
|
998
|
+
const listBoilerplatesTool = new ListBoilerplatesTool(templatesPath);
|
|
999
|
+
const useBoilerplateTool = new UseBoilerplateTool(templatesPath);
|
|
1000
|
+
const listScaffoldingMethodsTool = new ListScaffoldingMethodsTool(templatesPath);
|
|
1001
|
+
const useScaffoldMethodTool = new UseScaffoldMethodTool(templatesPath);
|
|
1002
|
+
const writeToFileTool = new WriteToFileTool();
|
|
1003
|
+
const generateBoilerplateTool = adminEnabled ? new GenerateBoilerplateTool(templatesPath) : null;
|
|
1004
|
+
const generateBoilerplateFileTool = adminEnabled ? new GenerateBoilerplateFileTool(templatesPath) : null;
|
|
1005
|
+
const generateFeatureScaffoldTool = adminEnabled ? new GenerateFeatureScaffoldTool(templatesPath) : null;
|
|
1006
|
+
const generateBoilerplatePrompt = adminEnabled ? new GenerateBoilerplatePrompt() : null;
|
|
1007
|
+
const generateFeatureScaffoldPrompt = adminEnabled ? new GenerateFeatureScaffoldPrompt() : null;
|
|
1008
|
+
const scaffoldApplicationPrompt = new ScaffoldApplicationPrompt();
|
|
1009
|
+
const scaffoldFeaturePrompt = new ScaffoldFeaturePrompt();
|
|
1010
|
+
const server = new Server({
|
|
1011
|
+
name: "scaffold-mcp",
|
|
1012
|
+
version: "0.4.0"
|
|
1013
|
+
}, {
|
|
1014
|
+
instructions: `Use this MCP server to create new project and adding a new feature (pages, component, services, etc...).
|
|
1015
|
+
|
|
1016
|
+
## Workflow:
|
|
1017
|
+
|
|
1018
|
+
1. **Creating New Project**: Use \`list-boilerplates\` → \`use-boilerplate\`
|
|
1019
|
+
2. **Adding Features**: Use \`list-scaffolding-methods\` → \`use-scaffold-method\`
|
|
1020
|
+
|
|
1021
|
+
## AI Usage Guidelines:
|
|
1022
|
+
|
|
1023
|
+
- Always call \`list-boilerplates\` first when creating new projects to see available options
|
|
1024
|
+
- Always call \`list-scaffolding-methods\` first when adding features to understand what's available
|
|
1025
|
+
- Follow the exact variable schema provided - validation will fail if required fields are missing
|
|
1026
|
+
- Use kebab-case for project names (e.g., "my-new-app")
|
|
1027
|
+
- The tools automatically handle file placement, imports, and code generation
|
|
1028
|
+
- Check the returned JSON schemas to understand required vs optional variables` + (adminEnabled ? `
|
|
1029
|
+
|
|
1030
|
+
## Admin Mode (Template Generation):
|
|
1031
|
+
|
|
1032
|
+
When creating custom boilerplate templates for frameworks not yet supported:
|
|
1033
|
+
|
|
1034
|
+
1. **Create Boilerplate Configuration**: Use \`generate-boilerplate\` to add a new boilerplate entry to a template's scaffold.yaml
|
|
1035
|
+
- Specify template name, boilerplate name, description, target folder, and variable schema
|
|
1036
|
+
- This creates the scaffold.yaml structure following the nextjs-15 pattern
|
|
1037
|
+
- Optional: Add detailed instruction about file purposes and design patterns
|
|
1038
|
+
|
|
1039
|
+
2. **Create Feature Configuration**: Use \`generate-feature-scaffold\` to add a new feature entry to a template's scaffold.yaml
|
|
1040
|
+
- Specify template name, feature name, generator, description, and variable schema
|
|
1041
|
+
- This creates the scaffold.yaml structure for feature scaffolds (pages, components, etc.)
|
|
1042
|
+
- Optional: Add detailed instruction about file purposes and design patterns
|
|
1043
|
+
- Optional: Specify patterns to match existing files this feature works with
|
|
1044
|
+
|
|
1045
|
+
3. **Create Template Files**: Use \`generate-boilerplate-file\` to create the actual template files
|
|
1046
|
+
- Create files referenced in the boilerplate's or feature's includes array
|
|
1047
|
+
- Use {{ variableName }} syntax for Liquid variable placeholders
|
|
1048
|
+
- Can copy from existing source files or provide content directly
|
|
1049
|
+
- Files automatically get .liquid extension
|
|
1050
|
+
|
|
1051
|
+
4. **Test the Template**: Use \`list-boilerplates\`/\`list-scaffolding-methods\` and \`use-boilerplate\`/\`use-scaffold-method\` to verify your template works
|
|
1052
|
+
|
|
1053
|
+
Example workflow for boilerplate:
|
|
1054
|
+
\`\`\`
|
|
1055
|
+
1. generate-boilerplate { templateName: "react-vite", boilerplateName: "scaffold-vite-app", ... }
|
|
1056
|
+
2. generate-boilerplate-file { templateName: "react-vite", filePath: "package.json", content: "..." }
|
|
1057
|
+
3. generate-boilerplate-file { templateName: "react-vite", filePath: "src/App.tsx", content: "..." }
|
|
1058
|
+
4. list-boilerplates (verify it appears)
|
|
1059
|
+
5. use-boilerplate { boilerplateName: "scaffold-vite-app", variables: {...} }
|
|
1060
|
+
\`\`\`
|
|
1061
|
+
|
|
1062
|
+
Example workflow for feature:
|
|
1063
|
+
\`\`\`
|
|
1064
|
+
1. generate-feature-scaffold { templateName: "nextjs-15", featureName: "scaffold-nextjs-component", generator: "componentGenerator.ts", ... }
|
|
1065
|
+
2. generate-boilerplate-file { templateName: "nextjs-15", filePath: "src/components/Component.tsx", content: "..." }
|
|
1066
|
+
3. list-scaffolding-methods (verify it appears)
|
|
1067
|
+
4. use-scaffold-method { scaffoldName: "scaffold-nextjs-component", variables: {...} }
|
|
1068
|
+
\`\`\`` : ""),
|
|
1069
|
+
capabilities: {
|
|
1070
|
+
tools: {},
|
|
1071
|
+
prompts: {}
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
1075
|
+
const tools = [
|
|
1076
|
+
listBoilerplatesTool.getDefinition(),
|
|
1077
|
+
useBoilerplateTool.getDefinition(),
|
|
1078
|
+
listScaffoldingMethodsTool.getDefinition(),
|
|
1079
|
+
useScaffoldMethodTool.getDefinition(),
|
|
1080
|
+
writeToFileTool.getDefinition()
|
|
1081
|
+
];
|
|
1082
|
+
if (adminEnabled) {
|
|
1083
|
+
if (generateBoilerplateTool) tools.push(generateBoilerplateTool.getDefinition());
|
|
1084
|
+
if (generateBoilerplateFileTool) tools.push(generateBoilerplateFileTool.getDefinition());
|
|
1085
|
+
if (generateFeatureScaffoldTool) tools.push(generateFeatureScaffoldTool.getDefinition());
|
|
1086
|
+
}
|
|
1087
|
+
return { tools };
|
|
1088
|
+
});
|
|
1089
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
1090
|
+
const { name: name$1, arguments: args } = request.params;
|
|
1091
|
+
if (name$1 === ListBoilerplatesTool.TOOL_NAME) return await listBoilerplatesTool.execute(args || {});
|
|
1092
|
+
if (name$1 === UseBoilerplateTool.TOOL_NAME) return await useBoilerplateTool.execute(args || {});
|
|
1093
|
+
if (name$1 === ListScaffoldingMethodsTool.TOOL_NAME) return await listScaffoldingMethodsTool.execute(args || {});
|
|
1094
|
+
if (name$1 === UseScaffoldMethodTool.TOOL_NAME) return await useScaffoldMethodTool.execute(args || {});
|
|
1095
|
+
if (name$1 === WriteToFileTool.TOOL_NAME) return await writeToFileTool.execute(args || {});
|
|
1096
|
+
if (name$1 === GenerateBoilerplateTool.TOOL_NAME) {
|
|
1097
|
+
if (!adminEnabled || !generateBoilerplateTool) throw new Error("Admin tools are not enabled. Use --admin-enable flag to enable.");
|
|
1098
|
+
return await generateBoilerplateTool.execute(args);
|
|
1099
|
+
}
|
|
1100
|
+
if (name$1 === GenerateBoilerplateFileTool.TOOL_NAME) {
|
|
1101
|
+
if (!adminEnabled || !generateBoilerplateFileTool) throw new Error("Admin tools are not enabled. Use --admin-enable flag to enable.");
|
|
1102
|
+
return await generateBoilerplateFileTool.execute(args);
|
|
1103
|
+
}
|
|
1104
|
+
if (name$1 === GenerateFeatureScaffoldTool.TOOL_NAME) {
|
|
1105
|
+
if (!adminEnabled || !generateFeatureScaffoldTool) throw new Error("Admin tools are not enabled. Use --admin-enable flag to enable.");
|
|
1106
|
+
return await generateFeatureScaffoldTool.execute(args);
|
|
1107
|
+
}
|
|
1108
|
+
throw new Error(`Unknown tool: ${name$1}`);
|
|
1109
|
+
});
|
|
1110
|
+
server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
1111
|
+
const prompts = [];
|
|
1112
|
+
prompts.push(scaffoldApplicationPrompt.getDefinition());
|
|
1113
|
+
prompts.push(scaffoldFeaturePrompt.getDefinition());
|
|
1114
|
+
if (adminEnabled) {
|
|
1115
|
+
if (generateBoilerplatePrompt) prompts.push(generateBoilerplatePrompt.getDefinition());
|
|
1116
|
+
if (generateFeatureScaffoldPrompt) prompts.push(generateFeatureScaffoldPrompt.getDefinition());
|
|
1117
|
+
}
|
|
1118
|
+
return { prompts };
|
|
1119
|
+
});
|
|
1120
|
+
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
1121
|
+
const { name: name$1, arguments: args } = request.params;
|
|
1122
|
+
if (name$1 === ScaffoldApplicationPrompt.PROMPT_NAME) return { messages: scaffoldApplicationPrompt.getMessages(args) };
|
|
1123
|
+
if (name$1 === ScaffoldFeaturePrompt.PROMPT_NAME) return { messages: scaffoldFeaturePrompt.getMessages(args) };
|
|
1124
|
+
if (name$1 === GenerateBoilerplatePrompt.PROMPT_NAME) {
|
|
1125
|
+
if (!generateBoilerplatePrompt) throw new Error("Prompt not available");
|
|
1126
|
+
return { messages: generateBoilerplatePrompt.getMessages(args) };
|
|
1127
|
+
}
|
|
1128
|
+
if (name$1 === GenerateFeatureScaffoldPrompt.PROMPT_NAME) {
|
|
1129
|
+
if (!generateFeatureScaffoldPrompt) throw new Error("Prompt not available");
|
|
1130
|
+
return { messages: generateFeatureScaffoldPrompt.getMessages(args) };
|
|
1131
|
+
}
|
|
1132
|
+
throw new Error(`Unknown prompt: ${name$1}`);
|
|
1133
|
+
});
|
|
1134
|
+
return server;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
//#endregion
|
|
1138
|
+
//#region src/transports/types.ts
|
|
1139
|
+
/**
|
|
1140
|
+
* Transport mode types
|
|
1141
|
+
*/
|
|
1142
|
+
let TransportMode = /* @__PURE__ */ function(TransportMode$1) {
|
|
1143
|
+
TransportMode$1["STDIO"] = "stdio";
|
|
1144
|
+
TransportMode$1["HTTP"] = "http";
|
|
1145
|
+
TransportMode$1["SSE"] = "sse";
|
|
1146
|
+
TransportMode$1["CLI"] = "cli";
|
|
1147
|
+
return TransportMode$1;
|
|
1148
|
+
}({});
|
|
1149
|
+
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region src/commands/mcp-serve.ts
|
|
1152
|
+
/**
|
|
1153
|
+
* Start MCP server with given transport handler
|
|
1154
|
+
*/
|
|
1155
|
+
async function startServer(handler) {
|
|
1156
|
+
await handler.start();
|
|
1157
|
+
const shutdown = async (signal) => {
|
|
1158
|
+
console.error(`\nReceived ${signal}, shutting down gracefully...`);
|
|
1159
|
+
try {
|
|
1160
|
+
await handler.stop();
|
|
1161
|
+
process.exit(0);
|
|
1162
|
+
} catch (error) {
|
|
1163
|
+
console.error("Error during shutdown:", error);
|
|
1164
|
+
process.exit(1);
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
1168
|
+
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* MCP Serve command
|
|
1172
|
+
*/
|
|
1173
|
+
const mcpServeCommand = new Command("mcp-serve").description("Start MCP server with specified transport").option("-t, --type <type>", "Transport type: stdio, http, or sse", "stdio").option("-p, --port <port>", "Port to listen on (http/sse only)", (val) => parseInt(val, 10), 3e3).option("--host <host>", "Host to bind to (http/sse only)", "localhost").option("--admin-enable", "Enable admin tools (generate-boilerplate)", false).action(async (options) => {
|
|
1174
|
+
try {
|
|
1175
|
+
const transportType = options.type.toLowerCase();
|
|
1176
|
+
const serverOptions = { adminEnabled: options.adminEnable };
|
|
1177
|
+
if (transportType === "stdio") await startServer(new StdioTransportHandler(createServer(serverOptions)));
|
|
1178
|
+
else if (transportType === "http") await startServer(new HttpTransportHandler(() => createServer(serverOptions), {
|
|
1179
|
+
mode: TransportMode.HTTP,
|
|
1180
|
+
port: options.port || Number(process.env.MCP_PORT) || 3e3,
|
|
1181
|
+
host: options.host || process.env.MCP_HOST || "localhost"
|
|
1182
|
+
}));
|
|
1183
|
+
else if (transportType === "sse") await startServer(new SseTransportHandler(() => createServer(serverOptions), {
|
|
1184
|
+
mode: TransportMode.SSE,
|
|
1185
|
+
port: options.port || Number(process.env.MCP_PORT) || 3e3,
|
|
1186
|
+
host: options.host || process.env.MCP_HOST || "localhost"
|
|
1187
|
+
}));
|
|
1188
|
+
else {
|
|
1189
|
+
console.error(`Unknown transport type: ${transportType}. Use: stdio, http, or sse`);
|
|
1190
|
+
process.exit(1);
|
|
1191
|
+
}
|
|
1192
|
+
} catch (error) {
|
|
1193
|
+
console.error("Failed to start MCP server:", error);
|
|
1194
|
+
process.exit(1);
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
|
|
1198
|
+
//#endregion
|
|
1199
|
+
//#region src/commands/scaffold.ts
|
|
1200
|
+
/**
|
|
1201
|
+
* Scaffold CLI command
|
|
1202
|
+
*/
|
|
1203
|
+
const scaffoldCommand = new Command("scaffold").description("Add features to existing projects");
|
|
1204
|
+
scaffoldCommand.command("list <projectPath>").description("List available scaffolding methods for a project").action(async (projectPath) => {
|
|
1205
|
+
try {
|
|
1206
|
+
const absolutePath = path.resolve(projectPath);
|
|
1207
|
+
if (!await ProjectConfigResolver.hasConfiguration(absolutePath)) {
|
|
1208
|
+
messages.error(`No project configuration found in ${absolutePath}`);
|
|
1209
|
+
messages.hint("For monorepo: ensure project.json exists with sourceTemplate field\nFor monolith: ensure toolkit.yaml exists at workspace root");
|
|
1210
|
+
process.exit(1);
|
|
1211
|
+
}
|
|
1212
|
+
const templatesDir = await TemplatesManagerService.findTemplatesPath();
|
|
1213
|
+
const methods = (await new ScaffoldingMethodsService(new FileSystemService(), templatesDir).listScaffoldingMethods(absolutePath)).methods;
|
|
1214
|
+
if (methods.length === 0) {
|
|
1215
|
+
messages.warning("No scaffolding methods available for this project.");
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
print.header(`\n${icons.wrench} Available Scaffolding Methods for ${projectPath}:\n`);
|
|
1219
|
+
for (const method of methods) {
|
|
1220
|
+
print.highlight(` ${method.name}`);
|
|
1221
|
+
print.debug(` ${method.instruction || method.description || "No description available"}`);
|
|
1222
|
+
if (method.variables_schema.required && method.variables_schema.required.length > 0) print.debug(` Required: ${method.variables_schema.required.join(", ")}`);
|
|
1223
|
+
print.newline();
|
|
1224
|
+
}
|
|
1225
|
+
} catch (error) {
|
|
1226
|
+
messages.error("Error listing scaffolding methods:", error);
|
|
1227
|
+
process.exit(1);
|
|
1228
|
+
}
|
|
1229
|
+
});
|
|
1230
|
+
scaffoldCommand.command("add <featureName>").description("Add a feature to an existing project").option("-p, --project <path>", "Project path", process.cwd()).option("-v, --vars <json>", "JSON string containing variables for the feature").option("--verbose", "Enable verbose logging").action(async (featureName, options) => {
|
|
1231
|
+
try {
|
|
1232
|
+
const projectPath = path.resolve(options.project);
|
|
1233
|
+
if (!await ProjectConfigResolver.hasConfiguration(projectPath)) {
|
|
1234
|
+
messages.error(`No project configuration found in ${projectPath}`);
|
|
1235
|
+
messages.hint("For monorepo: ensure project.json exists with sourceTemplate field\nFor monolith: ensure toolkit.yaml exists at workspace root");
|
|
1236
|
+
process.exit(1);
|
|
1237
|
+
}
|
|
1238
|
+
let variables = {};
|
|
1239
|
+
if (options.vars) try {
|
|
1240
|
+
variables = JSON.parse(options.vars);
|
|
1241
|
+
} catch (error) {
|
|
1242
|
+
messages.error("Error parsing variables JSON:", error);
|
|
1243
|
+
messages.hint("Example: --vars '{\"componentName\": \"UserProfile\", \"description\": \"User profile component\"}'");
|
|
1244
|
+
process.exit(1);
|
|
1245
|
+
}
|
|
1246
|
+
const templatesDir = await TemplatesManagerService.findTemplatesPath();
|
|
1247
|
+
const scaffoldingMethodsService = new ScaffoldingMethodsService(new FileSystemService(), templatesDir);
|
|
1248
|
+
const methods = (await scaffoldingMethodsService.listScaffoldingMethods(projectPath)).methods;
|
|
1249
|
+
const method = methods.find((m) => m.name === featureName);
|
|
1250
|
+
if (!method) {
|
|
1251
|
+
messages.error(`Scaffold method '${featureName}' not found.`);
|
|
1252
|
+
print.warning(`Available methods: ${methods.map((m) => m.name).join(", ")}`);
|
|
1253
|
+
print.debug(`Run 'scaffold-mcp scaffold list ${options.project}' to see all available methods`);
|
|
1254
|
+
process.exit(1);
|
|
1255
|
+
}
|
|
1256
|
+
const required = typeof method.variables_schema === "object" && method.variables_schema !== null && "required" in method.variables_schema ? method.variables_schema.required : [];
|
|
1257
|
+
const missing = required.filter((key) => !variables[key]);
|
|
1258
|
+
if (missing.length > 0) {
|
|
1259
|
+
messages.error(`❌ Missing required variables: ${missing.join(", ")}`);
|
|
1260
|
+
messages.hint(`💡 Use --vars with a JSON object containing: ${missing.join(", ")}`);
|
|
1261
|
+
const exampleVars = {};
|
|
1262
|
+
for (const key of required) if (key.includes("Name")) exampleVars[key] = "MyFeature";
|
|
1263
|
+
else if (key === "description") exampleVars[key] = "Feature description";
|
|
1264
|
+
else exampleVars[key] = `<${key}>`;
|
|
1265
|
+
print.debug(`Example: scaffold-mcp scaffold add ${featureName} --project ${options.project} --vars '${JSON.stringify(exampleVars)}'`);
|
|
1266
|
+
process.exit(1);
|
|
1267
|
+
}
|
|
1268
|
+
if (options.verbose) {
|
|
1269
|
+
print.info(`🔧 Feature: ${featureName}`);
|
|
1270
|
+
print.info(`📊 Variables: ${JSON.stringify(variables, null, 2)}`);
|
|
1271
|
+
print.info(`📁 Project Path: ${projectPath}`);
|
|
1272
|
+
}
|
|
1273
|
+
print.info(`🚀 Adding '${featureName}' to project...`);
|
|
1274
|
+
const result = await scaffoldingMethodsService.useScaffoldMethod({
|
|
1275
|
+
projectPath,
|
|
1276
|
+
scaffold_feature_name: featureName,
|
|
1277
|
+
variables
|
|
1278
|
+
});
|
|
1279
|
+
if (result.success) {
|
|
1280
|
+
messages.success("✅ Feature added successfully!");
|
|
1281
|
+
console.log(result.message);
|
|
1282
|
+
if (result.createdFiles && result.createdFiles.length > 0) {
|
|
1283
|
+
print.header("\n📁 Created files:");
|
|
1284
|
+
result.createdFiles.forEach((file) => print.debug(` - ${file}`));
|
|
1285
|
+
}
|
|
1286
|
+
if (result.warnings && result.warnings.length > 0) {
|
|
1287
|
+
messages.warning("\n⚠️ Warnings:");
|
|
1288
|
+
result.warnings.forEach((warning) => print.debug(` - ${warning}`));
|
|
1289
|
+
}
|
|
1290
|
+
print.header("\n📋 Next steps:");
|
|
1291
|
+
print.debug(" - Review the generated files");
|
|
1292
|
+
print.debug(" - Update imports if necessary");
|
|
1293
|
+
print.debug(" - Run tests to ensure everything works");
|
|
1294
|
+
} else {
|
|
1295
|
+
messages.error(`❌ Failed to add feature: ${result.message}`);
|
|
1296
|
+
process.exit(1);
|
|
1297
|
+
}
|
|
1298
|
+
} catch (error) {
|
|
1299
|
+
messages.error(`❌ Error adding feature: ${error.message}`);
|
|
1300
|
+
if (options.verbose) console.error("Stack trace:", error.stack);
|
|
1301
|
+
process.exit(1);
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
scaffoldCommand.command("info <featureName>").description("Show detailed information about a scaffold method").option("-p, --project <path>", "Project path", process.cwd()).action(async (featureName, options) => {
|
|
1305
|
+
try {
|
|
1306
|
+
const projectPath = path.resolve(options.project);
|
|
1307
|
+
if (!await ProjectConfigResolver.hasConfiguration(projectPath)) {
|
|
1308
|
+
messages.error(`No project configuration found in ${projectPath}`);
|
|
1309
|
+
messages.hint("For monorepo: ensure project.json exists with sourceTemplate field\nFor monolith: ensure toolkit.yaml exists at workspace root");
|
|
1310
|
+
process.exit(1);
|
|
1311
|
+
}
|
|
1312
|
+
const templatesDir = await TemplatesManagerService.findTemplatesPath();
|
|
1313
|
+
const method = (await new ScaffoldingMethodsService(new FileSystemService(), templatesDir).listScaffoldingMethods(projectPath)).methods.find((m) => m.name === featureName);
|
|
1314
|
+
if (!method) {
|
|
1315
|
+
messages.error(`❌ Scaffold method '${featureName}' not found.`);
|
|
1316
|
+
process.exit(1);
|
|
1317
|
+
}
|
|
1318
|
+
print.header(`\n🔧 Scaffold Method: ${method.name}\n`);
|
|
1319
|
+
print.debug(`Description: ${method.description}`);
|
|
1320
|
+
print.header("\n📝 Variables Schema:");
|
|
1321
|
+
console.log(JSON.stringify(method.variables_schema, null, 2));
|
|
1322
|
+
const includes = "includes" in method ? method.includes : [];
|
|
1323
|
+
if (includes && includes.length > 0) {
|
|
1324
|
+
print.header("\n📁 Files to be created:");
|
|
1325
|
+
includes.forEach((include) => {
|
|
1326
|
+
const parts = include.split(">>");
|
|
1327
|
+
if (parts.length === 2) print.debug(` - ${parts[1].trim()}`);
|
|
1328
|
+
else print.debug(` - ${include}`);
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
} catch (error) {
|
|
1332
|
+
messages.error(`❌ Error getting scaffold info: ${error.message}`);
|
|
1333
|
+
process.exit(1);
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
|
|
1337
|
+
//#endregion
|
|
1338
|
+
//#region src/cli.ts
|
|
1339
|
+
/**
|
|
1340
|
+
* Main entry point
|
|
1341
|
+
*/
|
|
1342
|
+
async function main() {
|
|
1343
|
+
const program = new Command();
|
|
1344
|
+
program.name("scaffold-mcp").description("MCP server for scaffolding applications with boilerplate templates").version(package_default.version);
|
|
1345
|
+
program.addCommand(mcpServeCommand);
|
|
1346
|
+
program.addCommand(boilerplateCommand);
|
|
1347
|
+
program.addCommand(scaffoldCommand);
|
|
1348
|
+
program.addCommand(initCommand);
|
|
1349
|
+
program.addCommand(addCommand);
|
|
1350
|
+
await program.parseAsync(process.argv);
|
|
1351
|
+
}
|
|
1352
|
+
main();
|
|
1353
|
+
|
|
1354
|
+
//#endregion
|
|
1355
|
+
export { };
|