Skip to main content
Glama

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
NameRequiredDescriptionDefault
templateYesTemplate name or path
destinationYesDestination directory
variablesNoTemplate variables
overwriteNoOverwrite existing files

Implementation Reference

  • 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}`,
              }),
            },
          ],
        };
      }
    }
  • 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);
      }
    );
  • 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>;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcp-tool-shop-org/mcp-file-forge'

If you have feedback or need assistance with the MCP directory API, please join our Discord server