Skip to main content
Glama

generate_from_template

Generate realistic test data using pre-built schema templates for ecommerce, blog, SaaS, or social applications. Customize scale, locale, format, and seed to populate databases with relational integrity.

Instructions

Generate test data using a pre-built schema template.

Pick a template (ecommerce, blog, saas, social) and optionally adjust the scale, locale, format, and seed. The template handles all the table definitions, field types, and foreign key relationships for you.

Scale multiplier: 1.0 = default counts, 2.0 = double, 0.5 = half. Example: ecommerce template at scale 2.0 generates 100 users, 200 products, etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
templateYesTemplate name
scaleNoScale multiplier for record counts (default 1.0)
localeNoDefault locale (en, de, fr, es, etc.)
formatNoOutput formatjson
sql_dialectNoSQL dialect (only when format=sql)
seedNoSeed for reproducible output

Implementation Reference

  • The handler function for the 'generate_from_template' tool, responsible for parsing input, generating data, and formatting the response.
    async function handleGenerateFromTemplate(
      args: Record<string, unknown>
    ): Promise<ToolResult> {
      const { template, locale, scale, format, seed } = args as {
        template: string;
        locale?: string;
        scale?: number;
        format?: string;
        seed?: number;
      };
    
      if (!template) {
        return err("'template' is required. Available templates: ecommerce, blog, saas, social");
      }
    
      let request: GenerateRequest;
      try {
        request = generateFromTemplate({
          template,
          locale: locale as GenerateRequest["locale"],
          scale,
          format: format as GenerateRequest["format"],
          seed,
        });
      } catch (e) {
        return err(`Template error: ${e instanceof Error ? e.message : String(e)}`);
      }
    
      const result = await generate(request);
      if (!result.success) {
        if ("errors" in result) {
          return err(
            `Generation failed:\n${result.errors
              .map((e) => `  - ${e.field}: ${e.message}`)
              .join("\n")}`
          );
        }
        return err(`Generation failed: circular dependency between tables: ${result.cycle.join(" -> ")}`);
      }
    
      // Optionally format output
      if (format && format !== "json") {
        const sqlDialect = args.sql_dialect as string | undefined;
        const formatted = formatOutput(
          result.result,
          request.tables,
          format as "csv" | "sql",
          sqlDialect as "postgres" | "mysql" | "sqlite" | undefined
        );
        return ok(formatted.body);
      }
    
      return ok({ data: result.result.data, meta: result.result.meta });
    }
  • The registration definition for the 'generate_from_template' tool in the tool definitions array.
      {
        name: "generate_from_template",
        description:
          "Generate test data using a pre-built template. Available templates: ecommerce, blog, saas, social. Use 'scale' to multiply record counts.",
        inputSchema: {
          type: "object",
          properties: {
            template: {
              type: "string",
              description:
                "Template ID: ecommerce, blog, saas, or social",
            },
            locale: {
              type: "string",
              description: "Locale for generated data. Default: en",
            },
            scale: {
              type: "number",
              description:
                "Multiplier for all table record counts. E.g. scale=10 generates 10x the default rows.",
            },
            format: {
              type: "string",
              enum: ["json", "csv", "sql"],
              description: "Output format. Default: json",
            },
            seed: {
              type: "number",
              description: "PRNG seed for reproducible output.",
            },
          },
          required: ["template"],
        },
      },
    ];

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/dinosaur24/mockhero'

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