Skip to main content
Glama

component_create

Create UI components with best practices for React, Vue, Svelte, or Web Components, including props, styles, and accessibility features.

Instructions

Create a new UI component with best practices

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
typeYes
propsNo
stylesNo
accessibilityNo

Implementation Reference

  • The handler function that implements the core logic of the 'component_create' tool. It parses input arguments using the schema, generates component code based on the specified type (React, Vue, Svelte, or Web Component), creates accompanying tests, Storybook stories, and documentation, then returns the results.
    async create(args: any) {
      const params = ComponentCreateSchema.parse(args);
      
      try {
        let componentCode: string;
        
        switch (params.type) {
          case 'react':
            componentCode = this.generateReactComponent(params);
            break;
          case 'vue':
            componentCode = this.generateVueComponent(params);
            break;
          case 'svelte':
            componentCode = this.generateSvelteComponent(params);
            break;
          case 'web-component':
            componentCode = this.generateWebComponent(params);
            break;
          default:
            throw new Error(`Unsupported component type: ${params.type}`);
        }
    
        const tests = this.generateTests(params);
        const storybook = this.generateStorybookStory(params);
        const documentation = this.generateDocumentation(params);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                component: {
                  name: params.name,
                  type: params.type,
                  code: componentCode,
                  tests,
                  storybook,
                  documentation
                },
                files: {
                  component: `${params.name}.${this.getFileExtension(params.type)}`,
                  test: `${params.name}.test.${this.getFileExtension(params.type)}`,
                  story: `${params.name}.stories.${this.getFileExtension(params.type)}`,
                  docs: `${params.name}.md`
                }
              }, null, 2)
            }
          ]
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: 'text',
              text: `Error creating component: ${error.message}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the component_create tool, including name, type, props, styles, and accessibility attributes.
    const ComponentCreateSchema = z.object({
      name: z.string(),
      type: z.enum(['react', 'vue', 'svelte', 'web-component']),
      props: z.array(z.object({
        name: z.string(),
        type: z.string(),
        required: z.boolean().optional(),
        default: z.any().optional()
      })).optional(),
      styles: z.record(z.any()).optional(),
      accessibility: z.object({
        role: z.string().optional(),
        ariaLabel: z.string().optional(),
        ariaDescribedBy: z.string().optional(),
        tabIndex: z.number().optional()
      }).optional()
    });
  • src/index.ts:219-236 (registration)
    Tool registration in the listTools handler, defining the name, description, and input schema for component_create.
    {
      name: 'component_create',
      description: 'Create a new UI component with best practices',
      inputSchema: {
        type: 'object',
        properties: {
          name: { type: 'string' },
          type: { 
            type: 'string',
            enum: ['react', 'vue', 'svelte', 'web-component']
          },
          props: { type: 'array', items: { type: 'object' } },
          styles: { type: 'object' },
          accessibility: { type: 'object' }
        },
        required: ['name', 'type']
      }
    },
  • src/index.ts:326-327 (registration)
    Dispatch case in the CallToolRequestSchema handler that routes calls to the componentTools.create method.
    case 'component_create':
      return await this.componentTools.create(args);
  • The ComponentTools class containing the create handler and all supporting helper methods for generating components, tests, stories, and documentation.
    export class ComponentTools {
      constructor() {}
    
      async create(args: any) {
        const params = ComponentCreateSchema.parse(args);
        
        try {
          let componentCode: string;
          
          switch (params.type) {
            case 'react':
              componentCode = this.generateReactComponent(params);
              break;
            case 'vue':
              componentCode = this.generateVueComponent(params);
              break;
            case 'svelte':
              componentCode = this.generateSvelteComponent(params);
              break;
            case 'web-component':
              componentCode = this.generateWebComponent(params);
              break;
            default:
              throw new Error(`Unsupported component type: ${params.type}`);
          }
    
          const tests = this.generateTests(params);
          const storybook = this.generateStorybookStory(params);
          const documentation = this.generateDocumentation(params);
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  component: {
                    name: params.name,
                    type: params.type,
                    code: componentCode,
                    tests,
                    storybook,
                    documentation
                  },
                  files: {
                    component: `${params.name}.${this.getFileExtension(params.type)}`,
                    test: `${params.name}.test.${this.getFileExtension(params.type)}`,
                    story: `${params.name}.stories.${this.getFileExtension(params.type)}`,
                    docs: `${params.name}.md`
                  }
                }, null, 2)
              }
            ]
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: 'text',
                text: `Error creating component: ${error.message}`
              }
            ],
            isError: true
          };
        }
      }
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 it creates with 'best practices' without detailing what that entails (e.g., file structure, dependencies, permissions, or mutation effects). It lacks behavioral context like error handling, side effects, or output format, leaving significant gaps for a creation tool.

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 with no wasted words, front-loading the core purpose. It's appropriately sized for the tool's complexity, though it could benefit from more detail given the gaps in other dimensions.

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?

For a creation tool with 5 parameters (including nested objects), 0% schema coverage, no annotations, and no output schema, the description is incomplete. It doesn't address parameter usage, behavioral traits, or output expectations, making it inadequate for effective tool selection and invocation.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate but adds no parameter details. It doesn't explain what 'name', 'type', 'props', 'styles', or 'accessibility' mean or how they're used, failing to provide meaning beyond the bare schema with nested objects and enums.

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 ('Create') and resource ('new UI component'), specifying it's for UI components with best practices. It distinguishes from siblings like component_analyze (analysis) and workflow tools, but doesn't explicitly differentiate from other creation tools like animation_create_timeline.

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 on when to use this tool versus alternatives is provided. The description mentions 'best practices' but doesn't specify prerequisites, constraints, or when to choose this over other component-related tools like storybook_get_stories or workflow_build_design_system.

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/willem4130/ui-ux-mcp-server'

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