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);
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool generates a component following rules, but doesn't explain what 'follows all rules' entails, whether it creates files or modifies existing ones, what permissions are needed, or what the output looks like. For a creation tool with zero annotation coverage, this is a significant gap in transparency.

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

Conciseness4/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 ('generate a new component') and adds a brief instruction. There's no wasted verbiage, but it could be slightly more structured by separating the rule-following aspect from the template choice for clarity.

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 of a 6-parameter creation tool with no annotations and no output schema, the description is insufficient. It lacks details on behavioral traits, output format, error handling, or how 'follows all rules' is enforced. The high schema coverage helps, but for a generative tool, more context is needed to understand its full operation and implications.

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 already documents all 6 parameters thoroughly. The description adds minimal value beyond the schema, only implying that parameters relate to template selection or customization. It doesn't provide additional context like parameter interactions or examples, but the high schema coverage justifies a baseline score of 3.

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 action ('generate a new component') and the resource ('component'), specifying it must follow all rules. It distinguishes from siblings like 'grade_component' or 'get_template' by focusing on creation rather than evaluation or retrieval. However, it doesn't explicitly differentiate from all siblings, such as 'check_compliance' which might involve rule-following.

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?

The description provides minimal guidance: it mentions choosing a template type or customizing, but offers no explicit context on when to use this tool versus alternatives like 'get_template' or 'grade_component'. There's no mention of prerequisites, dependencies, or scenarios where this tool is preferred over others, leaving usage unclear.

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

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