Skip to main content
Glama

generate-custom

Generate fake data using custom patterns like regex, enums, formats, and ranges for testing, seeding, and development purposes.

Instructions

Generates fake data following custom patterns, including regex patterns, enums, formats, and ranges

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of records to generate
patternsYesMap of field names to pattern definitions
localeNoLocale for generated data (affects format-based patterns)en
seedNoOptional seed for reproducible generation

Implementation Reference

  • The main handler function for the 'generate-custom' tool. It parses and validates input parameters using the Zod schema, validates patterns, instantiates a CustomGenerator, generates the requested number of records following the specified patterns, and returns an MCP response containing the generated data as a JSON resource with metadata.
    export function handleGenerateCustom(args: unknown): Promise<{ content: unknown[] }> {
      const startTime = Date.now();
    
      try {
        // Validate and parse arguments
        const params = GenerateCustomSchema.parse(args);
    
        // Validate patterns
        validatePatterns(params.patterns);
    
        // Create generator
        const generator = new CustomGenerator({
          seed: params.seed,
          locale: params.locale,
        });
    
        // Generate data
        const data =
          params.count === 1
            ? [generator.generate({ patterns: params.patterns })]
            : generator.generateMany(params.count, { patterns: params.patterns });
    
        const generationTimeMs = Date.now() - startTime;
    
        // Build response
        const metadata = {
          count: data.length,
          patternCount: Object.keys(params.patterns).length,
          seed: generator.getSeed(),
          locale: generator.getLocale(),
          generationTimeMs,
        };
    
        const responseText = params.seed
          ? `Generated ${data.length} custom record${data.length > 1 ? 's' : ''} with seed ${params.seed}`
          : `Generated ${data.length} custom record${data.length > 1 ? 's' : ''}`;
    
        return Promise.resolve({
          content: [
            {
              type: 'text',
              text: responseText,
            },
            {
              type: 'resource',
              resource: {
                uri: 'faker://custom/generated',
                mimeType: 'application/json',
                text: JSON.stringify({ data, metadata }, null, 2),
              },
            },
          ],
        });
      } catch (error) {
        if (error instanceof z.ZodError) {
          throw new Error(
            `Invalid parameters: ${error.errors.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ')}`
          );
        }
        throw error;
      }
    }
  • Zod validation schema defining the input parameters for the 'generate-custom' tool, including count, patterns (record of field to pattern type/value), locale, and optional seed. Used for validation and JSON Schema generation.
    export const GenerateCustomSchema = z.object({
      count: z.number().min(1).max(10000).default(1).describe('Number of records to generate'),
      patterns: z
        .record(z.string(), CustomPatternSchema)
        .refine((patterns) => Object.keys(patterns).length > 0, {
          message: 'At least one pattern must be defined',
        })
        .describe('Map of field names to pattern definitions'),
      locale: z
        .nativeEnum(SupportedLocale)
        .default(SupportedLocale.EN)
        .describe('Locale for generated data (affects format-based patterns)'),
      seed: z.number().optional().describe('Optional seed for reproducible generation'),
    });
  • Tool definition object for 'generate-custom' containing the name, description, and inputSchema derived from the Zod schema using zodToJsonSchema. This is passed to the server registration.
    export const generateCustomTool: Tool = {
      name: 'generate-custom',
      description:
        'Generates fake data following custom patterns, including regex patterns, enums, formats, and ranges',
      inputSchema: zodToJsonSchema(GenerateCustomSchema) as Tool['inputSchema'],
    };
  • src/index.ts:31-31 (registration)
    Server registration of the 'generate-custom' tool, associating the tool definition with its handler function.
    server.registerTool(generateCustomTool, handleGenerateCustom);
  • Helper function to validate all custom patterns in the input, dispatching to type-specific validators for regex, enum, format, and range patterns. Called by the handler before generation.
    function validatePatterns(
      patterns: Record<string, { type: PatternType; value: string | string[] | RangePattern }>
    ): void {
      for (const [fieldName, pattern] of Object.entries(patterns)) {
        try {
          switch (pattern.type) {
            case PatternType.REGEX:
              validateRegexPattern(pattern.value as string);
              break;
            case PatternType.ENUM:
              validateEnumPattern(pattern.value as string[]);
              break;
            case PatternType.FORMAT:
              validateFormatPattern(pattern.value as string);
              break;
            case PatternType.RANGE:
              validateRangePattern(pattern.value as RangePattern);
              break;
            default:
              throw new Error(`Unsupported pattern type`);
          }
        } catch (error) {
          throw new Error(`Invalid pattern for field '${fieldName}': ${(error as Error).message}`);
        }
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It lacks details on output format, error handling, performance characteristics, or any behavioral traits like whether generation is deterministic with a seed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose and lists key capabilities without unnecessary words. Every part earns its place by specifying the action and pattern types.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (4 parameters with nested objects, no output schema, no annotations), the description is insufficient. It doesn't explain what the output looks like (e.g., array of objects), how patterns map to fields, or behavioral aspects like reproducibility with seed, leaving significant gaps for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds minimal value by listing pattern types (regex, enums, formats, ranges) which are already in the schema's enum, but doesn't provide additional context on parameter interactions or usage examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Generates fake data following custom patterns' with specific pattern types listed (regex, enums, formats, ranges). It distinguishes from siblings by focusing on custom patterns rather than predefined datasets (company, dataset, person), though it doesn't explicitly name the siblings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus the sibling tools (generate-company, generate-dataset, generate-person). The description implies usage for custom patterns but doesn't specify scenarios, prerequisites, or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/funsjanssen/faker-mcp'

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