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;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states what the tool does but lacks behavioral details such as rate limits, authentication requirements, error handling, or the format of returned data. This is a significant gap for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the purpose with specific examples. There is no wasted text, and it directly communicates the core functionality without unnecessary details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a data retrieval tool with no annotations and no output schema, the description is incomplete. It doesn't cover behavioral aspects like response format, errors, or usage constraints, leaving gaps that could hinder an AI agent's ability to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It implies the parameter is for a 'specific YouTube channel' but doesn't explain the 'channelId' format or constraints. The description adds minimal value beyond the schema, resulting in a baseline score due to the single parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and the resource 'statistical information for a specific YouTube channel', with examples like subscriber count, total views, and video count. It distinguishes from siblings like 'get-video-stats' by focusing on channels rather than videos, though it doesn't explicitly name alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites, such as needing a valid channel ID, or compare it to other channel-related tools like 'analyze-channel-videos'. The context is implied but not explicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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