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
| Name | Required | Description | Default |
|---|---|---|---|
| component | Yes | Nombre del componente |
Implementation Reference
- src/tools/GetExamplesTool.ts:32-71 (handler)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); } }
- src/models/ToolSchemas.ts:90-106 (schema)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"], }, }; }
- src/server/PrimeNGServer.ts:217-218 (registration)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}`; }
- src/server/PrimeNGServer.ts:143-148 (registration)Instantiates the GetExamplesTool instance with required dependencies for use in the server.this.getExamplesTool = new GetExamplesTool( this.scraperService, this.cacheService, this.codeGeneratorService, this.components );