getVideoCategories
Retrieve YouTube video categories for any region. Get category IDs and titles to filter trending videos by category.
Instructions
Retrieves available video categories for a specific region. Returns a list of YouTube video categories with their IDs and titles that can be used for filtering trending videos or other category-specific operations. Different regions may have different available categories.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| regionCode | No | Two-letter country code (e.g., 'US', 'GB', 'JP'). Defaults to 'US' | US |
Implementation Reference
- The executeImpl method that implements the tool's logic: it calls youtubeService.getVideoCategories(regionCode) and formats the result.
protected async executeImpl( params: z.infer<typeof getVideoCategoriesSchema> ): Promise<CallToolResult> { const { regionCode } = params; const categories = await this.container.youtubeService.getVideoCategories(regionCode); return formatSuccess(categories); } - Zod schema defining the input: an optional regionCode (2-letter country code, defaults to 'US').
export const getVideoCategoriesSchema = z.object({ regionCode: regionCodeSchema .default("US") .describe( "Two-letter country code (e.g., 'US', 'GB', 'JP'). Defaults to 'US'" ), }); - src/tools/index.ts:15-37 (registration)Import of GetVideoCategoriesTool and its inclusion in the TOOL_CLASSES array for registration with the MCP server.
import { GetVideoCategoriesTool } from "./general/getVideoCategories.js"; import { FindConsistentOutlierChannelsTool } from "./general/findConsistentOutlierChannels.js"; interface ITool { readonly name: string; readonly description: string; readonly schema: z.ZodObject<z.ZodRawShape>; execute(args: z.infer<this["schema"]>): Promise<CallToolResult>; } type ToolConstructor = new (container: IServiceContainer) => ITool; // 1. Maintain a list of Constructors const TOOL_CLASSES = [ GetVideoDetailsTool, SearchVideosTool, GetTranscriptsTool, GetVideoCommentsTool, GetChannelStatisticsTool, GetChannelTopVideosTool, GetTrendingVideosTool, GetVideoCategoriesTool, ]; - The youtubeService.getVideoCategories method that makes the actual YouTube API call (videoCategories.list) and caches results with a static (1 year) TTL.
async getVideoCategories(regionCode: string = "US") { const cacheKey = this.cacheService.createOperationKey( "getVideoCategories", { regionCode, } ); const operation = async () => { try { const response = await this.trackCost( () => this.youtube.videoCategories.list({ part: ["snippet"], regionCode: regionCode, }), API_COSTS["videoCategories.list"] ); const categories = response.data.items?.map((category) => ({ id: category.id, title: category.snippet?.title, })); return categories || []; } catch (error) { if (error instanceof AppError) throw error; throw new YouTubeApiError( `YouTube API call for getVideoCategories failed for regionCode: ${regionCode}`, error ); } }; return this.cacheService.getOrSet( cacheKey, operation, CACHE_TTLS.STATIC, CACHE_COLLECTIONS.VIDEO_CATEGORIES, { regionCode } ); } - src/config/cache.config.ts:25-26 (helper)Cache TTL config: STATIC = ONE_YEAR, used for video categories since they rarely change.
// For truly static data that rarely or never changes, like video categories. STATIC: ONE_YEAR,