Skip to main content
Glama

generate_component_code

Generate Angular UI code examples for PrimeNG components with specified properties to accelerate development.

Instructions

Genera código de ejemplo para un componente de PrimeNG con las propiedades especificadas

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
componentYesNombre del componente
propertiesNoPropiedades del componente (ej: {label: 'Click me', icon: 'pi pi-check'})

Implementation Reference

  • GenerateCodeTool class implementing the handler logic for the 'generate_component_code' tool. Sets tool name in constructor and executes code generation via CodeGeneratorService.
    export class GenerateCodeTool extends BaseTool {
      private codeGenerator: CodeGeneratorService;
    
      constructor(codeGenerator: CodeGeneratorService) {
        super('generate_component_code');
        this.codeGenerator = codeGenerator;
      }
    
      async execute(args: Record<string, any>): Promise<ToolResponse> {
        const component = args.component as string;
        const properties = (args.properties as Record<string, any>) || {};
    
        if (!component) {
          return this.createErrorResponse('Component name is required');
        }
    
        const code = this.codeGenerator.generateComponentCode(component, properties);
        return this.createResponse(code);
      }
    }
  • Core implementation of generateComponentCode method that creates Angular standalone component code with import, TS class, and HTML template using provided properties.
      generateComponentCode(component: string, properties: Record<string, any> = {}): string {
        try {
          logger.debug(`Generating code for ${component}`, { properties });
    
          const capitalizedComponent = capitalizeComponentName(component);
          const propsString = this.formatProperties(properties);
          const content = this.getComponentContent(component);
    
          const code = `
    <!-- Component Import -->
    import { ${capitalizedComponent}Module } from 'primeng/${component}';
    
    <!-- Component.ts -->
    @Component({
      selector: 'app-example',
      standalone: true,
      imports: [${capitalizedComponent}Module],
      templateUrl: './example.component.html'
    })
    export class ExampleComponent {
      // Tu lógica aquí
    }
    
    <!-- Component.html -->
    <p-${component} ${propsString}>
      ${content}
    </p-${component}>
          `.trim();
    
          return code;
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          logger.error(`Failed to generate code for ${component}`, { error: errorMessage });
          throw new CodeGenerationError(`Failed to generate code for ${component}`, error);
        }
      }
  • Input schema definition for the generate_component_code tool, specifying component name (from enum) and optional properties object.
    export function createGenerateComponentCodeSchema(components: string[]): Tool {
      return {
        name: "generate_component_code",
        description: "Genera código de ejemplo para un componente de PrimeNG con las propiedades especificadas",
        inputSchema: {
          type: "object",
          properties: {
            component: {
              type: "string",
              description: "Nombre del componente",
              enum: components,
            },
            properties: {
              type: "object",
              description: "Propiedades del componente (ej: {label: 'Click me', icon: 'pi pi-check'})",
            },
          },
          required: ["component"],
        },
      };
    }
  • Instantiation and initialization of the GenerateCodeTool instance in PrimeNGServer.
    this.generateCodeTool = new GenerateCodeTool(this.codeGeneratorService);
    this.getExamplesTool = new GetExamplesTool(
  • Registration in the tool dispatch switch case in CallToolRequestSchema handler, routing calls to generateCodeTool.run().
    case "generate_component_code":
      return await this.generateCodeTool.run(args);
  • Tool schema included in the tools list returned by ListToolsRequestSchema handler.
    createGenerateComponentCodeSchema(this.components),
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 code, implying a read-only or informational operation, but doesn't clarify if this involves mutations (e.g., creating files), authentication needs, rate limits, or output format. The description lacks details on what the generated code includes (e.g., HTML, TypeScript, styling) or any constraints, leaving significant behavioral gaps.

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 in Spanish that directly states the tool's function without unnecessary words. It's front-loaded with the core action ('Genera código de ejemplo') and specifies the target and inputs concisely. Every part of the sentence contributes to understanding the purpose, making it well-structured and appropriately sized.

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

Completeness3/5

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

Given the tool's complexity (2 parameters, one with an enum, no output schema), the description is adequate but incomplete. It clarifies the purpose and inputs but lacks output details (e.g., code format, language), behavioral context (e.g., whether it's a read operation), and differentiation from siblings. With no annotations and no output schema, the description should do more to compensate, but it meets a minimum viable threshold for a code-generation tool.

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%, with clear descriptions for both parameters: 'component' (nombre del componente) and 'properties' (propiedades del componente). The description adds minimal value beyond the schema, as it only reiterates that properties are specified without providing additional syntax, examples, or constraints. Given the high schema coverage, the baseline score of 3 is appropriate, as the description doesn't significantly enhance parameter understanding.

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: 'Genera código de ejemplo para un componente de PrimeNG con las propiedades especificadas' (Generates sample code for a PrimeNG component with the specified properties). It specifies the verb ('genera'), resource ('código de ejemplo'), and target ('componente de PrimeNG'), making the purpose clear. However, it doesn't explicitly differentiate from siblings like 'get_component_examples' or 'get_component_doc', which might also provide code-related information.

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 no guidance on when to use this tool versus alternatives. It doesn't mention siblings like 'get_component_examples' (which might retrieve existing examples) or 'list_all_components' (which might list available components), leaving the agent to infer usage context. There's no explicit when-to-use or when-not-to-use information, resulting in minimal guidance.

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/hnkatze/PrimeNG_MCP'

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