Skip to main content
Glama

mcp-youtube

by kirbah
getChannelStatistics.ts1.66 kB
import { z } from "zod"; import { YoutubeService } from "../../services/youtube.service.js"; import { formatError } from "../../utils/errorHandler.js"; import { formatSuccess } from "../../utils/responseFormatter.js"; import { channelIdSchema } from "../../utils/validation.js"; import type { ChannelStatisticsParams } from "../../types/tools.js"; import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; export const getChannelStatisticsSchema = z.object({ channelIds: z .array(channelIdSchema) .min(1, "Channel IDs array must contain at least 1 element(s)") .describe("Array of YouTube channel IDs to get statistics for"), }); export const getChannelStatisticsConfig = { name: "getChannelStatistics", description: "Retrieves statistics for multiple channels. Returns detailed metrics including subscriber count, view count, video count, and channel creation date for each channel. Use this when you need to analyze the performance and reach of multiple YouTube channels.", // The inputSchema is now the complete Zod object schema. inputSchema: getChannelStatisticsSchema, }; export const getChannelStatisticsHandler = async ( params: ChannelStatisticsParams, youtubeService: YoutubeService ): Promise<CallToolResult> => { try { const validatedParams = getChannelStatisticsSchema.parse(params); const statsPromises = validatedParams.channelIds.map((channelId) => youtubeService.getChannelStatistics(channelId) ); const statisticsResults = await Promise.all(statsPromises); return formatSuccess(statisticsResults); } catch (error: any) { return formatError(error); } };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kirbah/mcp-youtube'

If you have feedback or need assistance with the MCP directory API, please join our Discord server