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
    );

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