Skip to main content
Glama

get_component_examples

Retrieve practical usage examples for PrimeNG components to implement Angular UI features with ready-to-use code snippets.

Instructions

Obtiene ejemplos de uso prácticos de un componente específico

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
componentYesNombre del componente

Implementation Reference

  • Main handler function in GetExamplesTool that validates input, checks cache, scrapes component documentation for examples, caches results, and falls back to hardcoded examples if scraping fails.
    async execute(args: Record<string, any>): Promise<ToolResponse> {
      const component = args.component as string;
    
      if (!component) {
        return this.createErrorResponse('Component name is required');
      }
    
      // Validate component exists
      if (!this.availableComponents.includes(component)) {
        return this.createErrorResponse(
          `Component "${component}" not found. Use list_all_components to see available components.`
        );
      }
    
      try {
        // Check cache first
        const cachedDoc = await this.cacheService.get(component);
    
        if (cachedDoc) {
          logger.info(`Returning cached examples for ${component}`);
          return this.createResponse(this.formatExamples(component, cachedDoc));
        }
    
        // Scrape documentation
        logger.info(`Scraping examples for ${component}`);
        const doc = await this.scraperService.scrapeComponentDoc(component);
    
        // Cache the result
        await this.cacheService.set(component, doc);
    
        return this.createResponse(this.formatExamples(component, doc));
      } catch (error) {
        // Fallback to hardcoded examples
        logger.warn(`Failed to scrape examples for ${component}, using fallback`, {
          error: error instanceof Error ? error.message : String(error)
        });
        const fallbackExamples = this.codeGenerator.getComponentExamples(component);
        return this.createResponse(fallbackExamples);
      }
    }
  • Defines the JSON schema for the tool's input, specifying the required 'component' parameter with enum validation against available components.
    export function createGetComponentExamplesSchema(components: string[]): Tool {
      return {
        name: "get_component_examples",
        description: "Obtiene ejemplos de uso prácticos de un componente específico",
        inputSchema: {
          type: "object",
          properties: {
            component: {
              type: "string",
              description: "Nombre del componente",
              enum: components,
            },
          },
          required: ["component"],
        },
      };
    }
  • Registers the tool handler by dispatching calls to get_component_examples to the GetExamplesTool.run method in the MCP server's request handler.
    case "get_component_examples":
      return await this.getExamplesTool.run(args);
  • Helper method providing fallback hardcoded or default examples for components when scraping fails.
    getComponentExamples(component: string): string {
      const examples = this.getCommonExamples(component);
      if (examples) {
        return examples;
      }
    
      return `# Ejemplos para ${component}\n\nConsulta la documentación oficial: https://primeng.org/${component}`;
    }
  • Instantiates the GetExamplesTool instance with required dependencies for use in the server.
    this.getExamplesTool = new GetExamplesTool(
      this.scraperService,
      this.cacheService,
      this.codeGeneratorService,
      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. While 'obtiene' (gets) implies a read-only operation, the description doesn't specify whether this requires authentication, has rate limits, returns structured data, or handles errors. For a tool with zero annotation coverage, this is a significant gap in behavioral context.

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 that directly states the tool's purpose without unnecessary words. It's appropriately sized for a simple tool with one parameter, and every part of the sentence contributes to understanding what the tool does.

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 low complexity (one parameter with full schema coverage) and lack of annotations or output schema, the description is minimally adequate. It covers the basic purpose but fails to provide guidance on usage versus siblings or behavioral details, leaving gaps that could hinder effective tool invocation in a broader context.

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?

The description adds minimal value beyond the input schema. It mentions 'un componente específico' (a specific component), which aligns with the 'component' parameter, but the schema already has 100% coverage with a clear description and enum list. Since schema_description_coverage is high, the baseline is 3, and the description doesn't provide additional syntax or format details to elevate the score.

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: 'Obtiene ejemplos de uso prácticos de un componente específico' (Gets practical usage examples of a specific component). It specifies the verb 'obtiene' (gets) and resource 'ejemplos de uso prácticos' (practical usage examples), making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'get_component_doc' or 'generate_component_code', which is why it doesn't reach a perfect score.

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. With siblings like 'get_component_doc' (documentation), 'generate_component_code' (code generation), and 'list_all_components' (listing), there's no indication of when this tool is preferred for examples versus other purposes. This leaves the agent without context for tool selection.

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