get_video_details
Retrieve detailed YouTube video information including title, description, statistics, optional transcript, and comments for content analysis and research purposes.
Instructions
Get comprehensive information about a specific YouTube video
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commentsOrder | No | Sort order for comments | relevance |
| includeComments | No | Whether to include video comments | |
| includeTranscript | No | Whether to include video transcript | |
| maxComments | No | Maximum number of comments to retrieve | |
| videoId | Yes | YouTube video ID |
Implementation Reference
- src/tools/video-details.ts:23-80 (handler)Main execution handler for the get_video_details tool. Validates input with schema, checks cache and quota, fetches data via YouTubeClient, enhances with analysis (transcript processing, comment sentiment, engagement metrics), caches result, and handles errors with partial cache fallback.async execute(args: unknown): Promise<VideoDetailsResult> { // Validate input parameters const params = GetVideoDetailsSchema.parse(args); this.logger.info(`Getting video details for: ${params.videoId}`); // Generate cache key const cacheKey = this.cache.getVideoDetailsKey( params.videoId, params.includeTranscript, params.includeComments ); // Check cache first const cached = await this.cache.get<VideoDetailsResult>(cacheKey); if (cached) { this.logger.info(`Returning cached video details for: ${params.videoId}`); return cached; } // Check quota before making API call const operationCost = this.calculateOperationCost(params); if (!this.quotaManager.canPerformOperation(operationCost)) { throw new QuotaExceededError('Insufficient quota for video details operation'); } try { // Get video details from YouTube API const result = await this.youtubeClient.getVideoDetails(params); // Record quota usage await this.quotaManager.recordUsage(operationCost, 'video_details'); // Enhance the result with additional processing const enhancedResult = await this.enhanceVideoDetails(result, params); // Cache the result await this.cache.set(cacheKey, enhancedResult); this.logger.info(`Video details retrieved for: ${params.videoId}`); return enhancedResult; } catch (error) { this.logger.error(`Failed to get video details for ${params.videoId}:`, error); // Try to return partial cached data if quota exceeded if (error instanceof QuotaExceededError) { const partialCache = await this.getPartialCachedData(params.videoId); if (partialCache) { this.logger.warn('Returning partial cached data due to quota limits'); return partialCache; } } throw error; } }
- src/index.ts:260-295 (registration)Tool registration in MCP server's listTools response, defining the 'get_video_details' tool name, description, and input schema.name: 'get_video_details', description: 'Get comprehensive information about a specific YouTube video', inputSchema: { type: 'object', properties: { videoId: { type: 'string', description: 'YouTube video ID' }, includeTranscript: { type: 'boolean', default: true, description: 'Whether to include video transcript' }, includeComments: { type: 'boolean', default: true, description: 'Whether to include video comments' }, maxComments: { type: 'number', minimum: 1, maximum: 100, default: 50, description: 'Maximum number of comments to retrieve' }, commentsOrder: { type: 'string', enum: ['relevance', 'time'], default: 'relevance', description: 'Sort order for comments' } }, required: ['videoId'] } },
- src/index.ts:563-565 (registration)Dispatch registration in MCP server's callTool handler switch statement, routing calls to VideoDetailsTool.execute().case 'get_video_details': result = await this.videoDetailsTool.execute(args); break;
- src/types.ts:72-78 (schema)Zod schema GetVideoDetailsSchema defining input parameters and validation for the tool, used in handler for parsing args.export const GetVideoDetailsSchema = z.object({ videoId: z.string().describe('YouTube video ID'), includeTranscript: z.boolean().default(true).describe('Whether to include video transcript'), includeComments: z.boolean().default(true).describe('Whether to include video comments'), maxComments: z.number().min(1).max(100).default(50).describe('Maximum number of comments to retrieve'), commentsOrder: z.enum(['relevance', 'time']).default('relevance').describe('Sort order for comments'), });
- src/youtube-client.ts:107-146 (helper)Core helper method in YouTubeClient that performs the actual API calls to fetch video metadata, optional transcript, and comments, called by the main handler.async getVideoDetails(params: GetVideoDetailsParams): Promise<VideoDetailsResult> { try { const videos = await this.getVideosByIds([params.videoId]); const video = videos[0]; if (!video) { throw new YouTubeAPIError(`Video not found: ${params.videoId}`); } const result: VideoDetailsResult = { video }; // Get transcript if requested if (params.includeTranscript) { try { result.transcript = await this.getVideoTranscript(params.videoId); } catch (error) { this.logger.warn(`Failed to get transcript for ${params.videoId}:`, error); } } // Get comments if requested if (params.includeComments) { try { result.comments = await this.getVideoComments( params.videoId, params.maxComments, params.commentsOrder ); } catch (error) { this.logger.warn(`Failed to get comments for ${params.videoId}:`, error); } } return result; } catch (error) { this.handleError(error); throw error; } }