scaffold_project
Create projects from templates with customizable variables and destination paths using the MCP File Forge server's secure file operations.
Instructions
Create a project from a template
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| template | Yes | Template name or path | |
| destination | Yes | Destination directory | |
| variables | No | Template variables | |
| overwrite | No | Overwrite existing files |
Implementation Reference
- src/tools/scaffold.ts:201-307 (handler)The implementation of the scaffold_project tool logic.
async function scaffoldProjectImpl(input: ScaffoldProjectInput): Promise<ToolResult> { try { // Find the template const template = await findTemplate(input.template); if (!template) { return { isError: true, content: [ { type: 'text', text: JSON.stringify({ code: 'FILE_NOT_FOUND', message: `Template not found: ${input.template}`, details: { searched_paths: getTemplatePaths(), }, }), }, ], }; } // Check destination const destPath = path.resolve(input.destination); let destExists = false; try { await fs.access(destPath); destExists = true; } catch { // Destination doesn't exist } if (destExists && !input.overwrite) { // Check if directory is empty const entries = await fs.readdir(destPath); if (entries.length > 0) { return { isError: true, content: [ { type: 'text', text: JSON.stringify({ code: 'ALREADY_EXISTS', message: `Destination directory is not empty: ${input.destination}`, }), }, ], }; } } // Merge default variables with provided variables const variables: Record<string, string> = { PROJECT_NAME: path.basename(destPath), CURRENT_YEAR: new Date().getFullYear().toString(), CURRENT_DATE: new Date().toISOString().split('T')[0], ...input.variables, }; // Copy template to destination const result = await copyTemplateDir( template.path, destPath, variables, input.overwrite ); return { content: [ { type: 'text', text: JSON.stringify( { success: true, template: { name: template.metadata.name, path: template.path, }, destination: destPath, files_created: result.files.length, files_skipped: result.skipped.length, variables_used: variables, }, null, 2 ), }, ], }; } catch (error) { const err = error as Error; return { isError: true, content: [ { type: 'text', text: JSON.stringify({ code: 'UNKNOWN_ERROR', message: `Error scaffolding project: ${err.message}`, }), }, ], }; } } - src/tools/scaffold.ts:403-420 (registration)The registration of the scaffold_project tool with the MCP server.
// scaffold_project tool server.tool( 'scaffold_project', 'Create a project from a template', { template: z.string().describe('Template name or path'), destination: z.string().describe('Destination directory'), variables: z .record(z.string()) .optional() .describe('Template variables'), overwrite: z.boolean().optional().describe('Overwrite existing files'), }, async (args) => { const input = ScaffoldProjectInputSchema.parse(args); return await scaffoldProjectImpl(input); } ); - src/types.ts:258-265 (schema)Input schema and type definition for scaffold_project.
export const ScaffoldProjectInputSchema = z.object({ template: z.string().describe('Template name or path'), destination: z.string().describe('Destination directory'), variables: z.record(z.string()).optional().describe('Template variables'), overwrite: z.boolean().default(false).describe('Overwrite existing'), }); export type ScaffoldProjectInput = z.infer<typeof ScaffoldProjectInputSchema>;