get-trending-videos
Retrieve trending YouTube videos by region and category to analyze popular content trends. Supports up to 50 results for detailed insights into audience preferences.
Instructions
Retrieve trending videos by region and category. This helps analyze current popular content trends.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| categoryId | No | ||
| maxResults | No | ||
| regionCode | No |
Implementation Reference
- src/index.ts:487-521 (handler)The handler function that implements the core logic of the 'get-trending-videos' tool. It uses the YouTube Data API v3 to fetch trending videos by calling videos.list with chart='mostPopular', processes the response to extract relevant fields, and returns formatted JSON data.async ({ regionCode = 'US', categoryId, maxResults = 10 }) => { try { const response = await youtubeService.youtube.videos.list({ part: ['snippet', 'contentDetails', 'statistics'], chart: 'mostPopular', regionCode, videoCategoryId: categoryId, maxResults }); const trendingVideos = response.data.items?.map(video => ({ videoId: video.id, title: video.snippet?.title, channelTitle: video.snippet?.channelTitle, publishedAt: video.snippet?.publishedAt, viewCount: video.statistics?.viewCount, likeCount: video.statistics?.likeCount, commentCount: video.statistics?.commentCount })); return { content: [{ type: 'text', text: JSON.stringify(trendingVideos, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error fetching trending videos: ${error}` }], isError: true }; }
- src/index.ts:479-523 (registration)The registration of the 'get-trending-videos' tool in the MCP server using server.tool(). Includes the tool name, description, Zod input schema for parameters (regionCode, categoryId, maxResults), and the handler function.server.tool( 'get-trending-videos', 'Retrieve trending videos by region and category. This helps analyze current popular content trends.', { regionCode: z.string().length(2).optional(), categoryId: z.string().optional(), maxResults: z.number().min(1).max(50).optional() }, async ({ regionCode = 'US', categoryId, maxResults = 10 }) => { try { const response = await youtubeService.youtube.videos.list({ part: ['snippet', 'contentDetails', 'statistics'], chart: 'mostPopular', regionCode, videoCategoryId: categoryId, maxResults }); const trendingVideos = response.data.items?.map(video => ({ videoId: video.id, title: video.snippet?.title, channelTitle: video.snippet?.channelTitle, publishedAt: video.snippet?.publishedAt, viewCount: video.statistics?.viewCount, likeCount: video.statistics?.likeCount, commentCount: video.statistics?.commentCount })); return { content: [{ type: 'text', text: JSON.stringify(trendingVideos, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error fetching trending videos: ${error}` }], isError: true }; } } );
- src/index.ts:482-486 (schema)The Zod schema defining the input parameters for the 'get-trending-videos' tool: optional regionCode (2-letter ISO), categoryId, and maxResults (1-50).{ regionCode: z.string().length(2).optional(), categoryId: z.string().optional(), maxResults: z.number().min(1).max(50).optional() },