get-video-categories
Retrieve YouTube video categories by region using the MCP server. Specify a region code to fetch relevant categories for targeted search or content organization.
Instructions
Retrieve available video categories for a specific region
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| regionCode | No |
Implementation Reference
- src/index.ts:525-558 (registration)Registration of the 'get-video-categories' tool, including input schema (regionCode optional string) and the complete handler function that uses the YouTube Data API v3 to list video categories for the specified region (default 'US'), formats them into id/title objects, and returns as JSON text content.server.tool( 'get-video-categories', 'Retrieve available video categories for a specific region', { regionCode: z.string().length(2).optional() }, async ({ regionCode = 'US' }) => { try { const response = await youtubeService.youtube.videoCategories.list({ part: ['snippet'], regionCode }); const categories = response.data.items?.map(category => ({ id: category.id, title: category.snippet?.title })); return { content: [{ type: 'text', text: JSON.stringify(categories, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error fetching video categories: ${error}` }], isError: true }; } }
- src/index.ts:531-557 (handler)The exact handler function implementing the tool logic: calls youtubeService.youtube.videoCategories.list with part 'snippet' and regionCode, maps items to {id, title}, returns JSON stringified in text content, handles errors.async ({ regionCode = 'US' }) => { try { const response = await youtubeService.youtube.videoCategories.list({ part: ['snippet'], regionCode }); const categories = response.data.items?.map(category => ({ id: category.id, title: category.snippet?.title })); return { content: [{ type: 'text', text: JSON.stringify(categories, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error fetching video categories: ${error}` }], isError: true }; }
- src/index.ts:528-530 (schema)Input schema using Zod: optional regionCode as 2-character string.{ regionCode: z.string().length(2).optional() },