analyze_comment_intents
Extract user intents and actionable insights from YouTube comments to understand audience engagement and feedback patterns.
Instructions
Analyze YouTube comments to extract user intents and actionable insights
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| videoId | Yes | YouTube video ID to analyze comments from | |
| maxComments | No | Maximum number of comments to analyze | |
| intentCategories | No | Custom intent categories to focus on (optional) |
Implementation Reference
- src/tools/comment-intent.ts:21-73 (handler)Entry point execute method of CommentIntentAnalyzer class that handles tool execution: parses args, checks cache, fetches comments, analyzes intents in batches using LLM, generates summary, caches result
async execute(args: unknown): Promise<CommentIntentAnalysis> { const params = AnalyzeCommentIntentsSchema.parse(args); this.logger.info(`Analyzing comment intents for video: ${params.videoId}`); // Generate cache key const cacheKey = `comment_intents:${params.videoId}:${params.maxComments}:${JSON.stringify(params.intentCategories || [])}`; // Check cache first const cached = await this.cache.get<CommentIntentAnalysis>(cacheKey); if (cached) { this.logger.info(`Returning cached comment intent analysis for: ${params.videoId}`); return cached; } try { // Step 1: Get video details with comments const videoDetails = await this.youtubeClient.getVideoDetails({ videoId: params.videoId, includeTranscript: false, includeComments: true, maxComments: params.maxComments }); if (!videoDetails.comments || videoDetails.comments.length === 0) { throw new Error(`No comments found for video ${params.videoId}`); } // Step 2: Analyze comments in batches using LLM const intents = await this.analyzeCommentsInBatches( videoDetails.comments, params.intentCategories ); // Step 3: Generate summary and trends const analysis = await this.generateAnalysisSummary( params.videoId, intents, videoDetails.comments ); // Cache the result await this.cache.set(cacheKey, analysis, 3600); // 1 hour cache this.logger.info(`Comment intent analysis completed for ${params.videoId}: ${intents.length} intents identified`); return analysis; } catch (error) { this.logger.error(`Failed to analyze comment intents for ${params.videoId}:`, error); throw error; } } - src/types.ts:248-253 (schema)Zod schema defining input parameters for the analyze_comment_intents tool
export const AnalyzeCommentIntentsSchema = z.object({ videoId: z.string().describe('YouTube video ID'), maxComments: z.number().min(10).max(500).default(100).describe('Maximum comments to analyze'), intentCategories: z.array(z.string()).optional().describe('Custom intent categories to detect'), includeReplies: z.boolean().default(false).describe('Whether to include comment replies'), }); - src/index.ts:415-441 (registration)Tool registration in listTools handler: name, description, and input schema
name: 'analyze_comment_intents', description: 'Analyze YouTube comments to extract user intents and actionable insights', inputSchema: { type: 'object', properties: { videoId: { type: 'string', description: 'YouTube video ID to analyze comments from' }, maxComments: { type: 'number', minimum: 10, maximum: 200, default: 100, description: 'Maximum number of comments to analyze' }, intentCategories: { type: 'array', items: { type: 'string' }, description: 'Custom intent categories to focus on (optional)' } }, required: ['videoId'] } }, - src/index.ts:584-586 (registration)Dispatch case in CallToolRequestSchema handler that routes to commentIntentTool.execute
case 'analyze_comment_intents': result = await this.commentIntentTool.execute(args); break; - src/index.ts:179-179 (registration)Instantiation of CommentIntentAnalyzer class for use as the tool handler
this.commentIntentTool = new CommentIntentAnalyzer(this.youtubeClient, this.cache, this.llmService, this.logger);