Skip to main content
Glama

generate_component

Create UI components by selecting templates or customizing options to ensure compliance with component specifications.

Instructions

Generate a new component that follows all rules. Choose a template type or customize.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesComponent name (e.g., "Button", "Card", "Dialog")
templateYesTemplate type to use
elementNoHTML element to wrap (for basic template)
hasVariantsNoInclude CVA variants (for basic template)
variantsNoVariant names (e.g., ["default", "secondary", "destructive"])
sizesNoSize names (e.g., ["sm", "md", "lg"])

Implementation Reference

  • The handler function that implements the generate_component tool. It extracts parameters, selects and calls the appropriate generator function based on the template, grades the generated code for compliance, and formats the output with the code and report.
    function handleGenerateComponent(args: Record<string, unknown>): ToolResult { const name = args.name as string; const template = args.template as string; const element = (args.element as string) || 'div'; const hasVariants = args.hasVariants as boolean; const variants = args.variants as string[] | undefined; const sizes = args.sizes as string[] | undefined; let code: string; switch (template) { case 'button': code = generateButtonComponent(); break; case 'card': code = generateCardComponent(); break; case 'input': code = generateInputComponent(); break; case 'composable': code = generateComposableComponent({ name }); break; case 'basic': default: code = generateBasicComponent({ name, element, hasVariants, variants, sizes, }); break; } // Grade the generated component to prove it's compliant const grade = gradeComponent(code); const text = `# Generated Component: ${name} **Template:** ${template} **Compliance Score:** ${grade.score}/100 (${grade.grade}) \`\`\`tsx ${code} \`\`\` ## Compliance Report ${grade.passes.map((p) => `✅ ${p}`).join('\n')} `; return { content: [{ type: 'text', text }], }; }
  • The input schema defining the parameters for the generate_component tool, including required name and template, and optional properties.
    inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Component name (e.g., "Button", "Card", "Dialog")', }, template: { type: 'string', description: 'Template type to use', enum: ['basic', 'composable', 'button', 'card', 'input'], }, element: { type: 'string', description: 'HTML element to wrap (for basic template)', }, hasVariants: { type: 'boolean', description: 'Include CVA variants (for basic template)', }, variants: { type: 'array', items: { type: 'string' }, description: 'Variant names (e.g., ["default", "secondary", "destructive"])', }, sizes: { type: 'array', items: { type: 'string' }, description: 'Size names (e.g., ["sm", "md", "lg"])', }, }, required: ['name', 'template'], },
  • The tool registration entry in getToolDefinitions(), including name, description, and input schema for generate_component.
    { name: 'generate_component', description: 'Generate a new component that follows all rules. Choose a template type or customize.', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Component name (e.g., "Button", "Card", "Dialog")', }, template: { type: 'string', description: 'Template type to use', enum: ['basic', 'composable', 'button', 'card', 'input'], }, element: { type: 'string', description: 'HTML element to wrap (for basic template)', }, hasVariants: { type: 'boolean', description: 'Include CVA variants (for basic template)', }, variants: { type: 'array', items: { type: 'string' }, description: 'Variant names (e.g., ["default", "secondary", "destructive"])', }, sizes: { type: 'array', items: { type: 'string' }, description: 'Size names (e.g., ["sm", "md", "lg"])', }, }, required: ['name', 'template'], }, },
  • The dispatch case in executeTool() that routes calls to the generate_component handler.
    case 'generate_component': return handleGenerateComponent(args);

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/audreyui/components-build-mcp'

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