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
| Name | Required | Description | Default |
|---|---|---|---|
| template | Yes | Template name | |
| scale | No | Scale multiplier for record counts (default 1.0) | |
| locale | No | Default locale (en, de, fr, es, etc.) | |
| format | No | Output format | json |
| sql_dialect | No | SQL dialect (only when format=sql) | |
| seed | No | Seed for reproducible output |
Implementation Reference
- packages/mcp/src/tools.ts:300-353 (handler)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 }); } - packages/mcp/src/tools.ts:152-186 (registration)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"], }, }, ];