Skip to main content
Glama

generate_component

Create UI components following components.build specifications. Select from templates like button, card, or input, then customize with variants, sizes, and HTML elements.

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 handleGenerateComponent function that executes the tool's logic: parses args, generates component code using template-specific functions, grades for compliance, and returns formatted result.
    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 parameters for the generate_component tool, including required name and template, and optional properties.
    { 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'], }, },
  • Registration in the executeTool function's switch statement, which dispatches 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