Skip to main content
Glama

get-channel-stats

Retrieve detailed YouTube channel statistics, including subscriber count, total views, and video count, by inputting the channel ID through the Model Context Protocol.

Instructions

Get statistical information for a specific YouTube channel (subscriber count, total views, video count, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channelIdYes

Implementation Reference

  • The main handler function for the 'get-channel-stats' tool. It fetches channel details via YouTubeService, handles errors, formats statistics (channelId, title, createdAt, subscriberCount, videoCount, viewCount, thumbnailUrl), and returns JSON.
    async ({ channelId }) => { try { const channelData = await youtubeService.getChannelDetails(channelId); const channel = channelData.items?.[0]; if (!channel) { return { content: [{ type: 'text', text: `Channel with ID ${channelId} not found.` }], isError: true }; } const stats = { channelId: channel.id, title: channel.snippet?.title, createdAt: channel.snippet?.publishedAt, subscriberCount: channel.statistics?.subscriberCount, videoCount: channel.statistics?.videoCount, viewCount: channel.statistics?.viewCount, thumbnailUrl: channel.snippet?.thumbnails?.default?.url }; return { content: [{ type: 'text', text: JSON.stringify(stats, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error fetching channel statistics: ${error}` }], isError: true }; } }
  • Input schema for the tool using Zod: requires a non-empty string channelId.
    { channelId: z.string().min(1) },
  • src/index.ts:386-433 (registration)
    Registration of the 'get-channel-stats' tool on the MCP server with name, description, input schema, and handler function.
    server.tool( 'get-channel-stats', 'Get statistical information for a specific YouTube channel (subscriber count, total views, video count, etc.)', { channelId: z.string().min(1) }, async ({ channelId }) => { try { const channelData = await youtubeService.getChannelDetails(channelId); const channel = channelData.items?.[0]; if (!channel) { return { content: [{ type: 'text', text: `Channel with ID ${channelId} not found.` }], isError: true }; } const stats = { channelId: channel.id, title: channel.snippet?.title, createdAt: channel.snippet?.publishedAt, subscriberCount: channel.statistics?.subscriberCount, videoCount: channel.statistics?.videoCount, viewCount: channel.statistics?.viewCount, thumbnailUrl: channel.snippet?.thumbnails?.default?.url }; return { content: [{ type: 'text', text: JSON.stringify(stats, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error fetching channel statistics: ${error}` }], isError: true }; } } );
  • Helper method in YouTubeService that performs the core API call to YouTube Data API v3 channels.list to retrieve channel snippet and statistics.
    async getChannelDetails(channelId: string): Promise<youtube_v3.Schema$ChannelListResponse> { try { const response = await this.youtube.channels.list({ part: ['snippet', 'statistics'], id: [channelId] }); return response.data; } catch (error) { console.error('Error getting channel details:', error); throw error; } }

Other Tools

Related Tools

Latest Blog Posts

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/coyaSONG/youtube-mcp-server'

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