get_component_examples
Retrieve practical usage examples for specific PrimeNG components to implement Angular UI elements with proper code patterns.
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 that executes the get_component_examples tool: validates the component input, checks cache, scrapes examples if not cached, formats them into markdown, and falls back to hardcoded examples from CodeGeneratorService 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 tool schema for get_component_examples, including name, description, and input schema with required 'component' parameter enum-constrained to 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:177-193 (registration)Registers the tool schema in the listTools handler by including createGetComponentExamplesSchema in the returned tools array.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ // Component tools createGetComponentDocSchema(this.components), createSearchComponentsSchema(), createListAllComponentsSchema(), createGenerateComponentCodeSchema(this.components), createGetComponentExamplesSchema(this.components), // Guide tools createGetInstallationGuideSchema(), createGetThemingGuideSchema(), createGetIconsGuideSchema(), createGetTailwindGuideSchema(), ], }; });
- src/server/PrimeNGServer.ts:143-148 (registration)Instantiates the GetExamplesTool instance with required services and components list during server initialization.this.getExamplesTool = new GetExamplesTool( this.scraperService, this.cacheService, this.codeGeneratorService, this.components );
- src/server/PrimeNGServer.ts:217-219 (registration)Registers the tool handler in the CallToolRequestSchema switch statement, dispatching to the tool's run method.case "get_component_examples": return await this.getExamplesTool.run(args);
- Helper method providing fallback hardcoded examples for components, used when scraping fails; delegates to getCommonExamples for specific examples.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}`; }