Labsco
kirbah logo

YouTube Data MCP

β˜… 22

from kirbah

High-efficiency YouTube MCP server providing token-optimized, structured data for LLMs.

πŸ”₯πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredAdvanced setup

YouTube Data MCP Server (@kirbah/mcp-youtube)

<!-- Badges Start --> <p align="left"> <!-- GitHub Actions CI --> <a href="https://github.com/kirbah/mcp-youtube/actions/workflows/ci.yml"> <img src="https://github.com/kirbah/mcp-youtube/actions/workflows/ci.yml/badge.svg" alt="CI Status" /> </a> <!-- Codecov --> <a href="https://codecov.io/gh/kirbah/mcp-youtube"> <img src="https://codecov.io/gh/kirbah/mcp-youtube/branch/main/graph/badge.svg?token=Y6B2E0T82P" alt="Code Coverage"/> </a> <!-- NPM Version --> <a href="https://www.npmjs.com/package/@kirbah/mcp-youtube"> <img src="https://img.shields.io/npm/v/@kirbah/mcp-youtube.svg" alt="NPM Version" /> </a> <!-- NPM Downloads --> <a href="https://www.npmjs.com/package/@kirbah/mcp-youtube"> <img src="https://img.shields.io/npm/dt/@kirbah/mcp-youtube.svg" alt="NPM Downloads" /> </a> <!-- Node Version --> <a href="package.json"> <img src="https://img.shields.io/node/v/@kirbah/mcp-youtube.svg" alt="Node.js Version Support" /> </a> </p> <a href="https://glama.ai/mcp/servers/@kirbah/mcp-youtube"> <img width="380" height="200" src="https://glama.ai/mcp/servers/@kirbah/mcp-youtube/badge" /> </a> <!-- Badges End -->

A production-grade YouTube Data MCP server engineered specifically for AI agents.

Unlike standard API wrappers that flood your LLM with redundant data, this server strips away YouTube's heavy payload bloat. It is designed to save you massive amounts of context window tokens, protect your daily API quotas via caching, and run reliably without breaking your workflows.

Why Choose This Server?

Most MCP servers are weekend projects. @kirbah/mcp-youtube is built for reliable, daily, cost-effective agentic workflows.

πŸ“‰ 1. Save Up to 87% on Tokens (and Context Window)

The raw YouTube API returns massive JSON payloads filled with nested eTags, redundant thumbnails, and localization data that LLMs don't need. This server structures the data to give your LLM exactly what it needs to reason, and nothing else.

%%{init: { "theme": "base", "themeVariables": { "xyChart": { "plotColorPalette": "#ef4444, #22c55e" } } } }%%
xychart-beta
    title "Token Consumption (Lower is Better)"
    x-axis ["getVideoDetails", "searchVideos", "getChannelStats"]
    y-axis "Context Tokens" 0 --> 1200
    bar "Raw YouTube API" [854, 1115, 673]
    bar "MCP-YouTube (Optimized)" [209, 402, 86]
API MethodRaw YouTube TokensMCP-YouTube TokensToken SavingsData Size
getChannelStatistics67386~87% Less1.9 KB βž” 0.2 KB
getVideoDetails854209~75% Less2.9 KB βž” 0.6 KB
searchVideos1115402~64% Less3.4 KB βž” 1.2 KB

(Curious? You can compare the raw API responses vs optimized outputs in the examples folder).

πŸ›‘οΈ 2. Protect Your API Quotas (Smart Caching)

The YouTube Data API has strict daily limits (10,000 quota units). If your LLM gets stuck in a loop or re-asks a question, standard servers will drain your API limit in minutes. This server includes an optional MongoDB caching layer. If your agent requests a video details or searches the same trending videos twice, the server serves it from the cache - costing you 0 API quota points.

πŸ—οΈ 3. Production-Grade & Actively Maintained

Tired of MCP tools crashing your AI client? This server is built to be a rock-solid dependency:

  • 97% Test Coverage: Comprehensively unit-tested (check the Codecov badge).
  • Zero Lint Errors/Warnings: Enforces strict, clean code (npm run lint passes 100%).
  • Active Security: Automated Dependabot patching ensures underlying libraries are never left with known vulnerabilities.
  • Strict Type Safety: Built using Zod validation and the robust MCP TypeScript Starter architecture.

Key Features

  • Optimized Video Information: Search videos with advanced filters. Retrieve detailed metadata, statistics (views, likes, etc.), and content details, all structured for minimal token footprint.
  • Efficient Transcript Management: Fetch video captions/subtitles with multi-language support, perfect for content analysis by LLMs.
  • Insightful Channel Analysis: Get concise channel statistics (subscribers, views, video count) and discover a channel's top-performing videos without data bloat.
  • Lean Trend Discovery: Find trending videos by region and category, and get lists of available video categories, optimized for quick AI processing.
  • Structured for AI: All responses are designed to be easily parsable and immediately useful for language models.
  • Efficient Comment Retrieval: Fetch video comments with fine-grained control over the number of results and replies, optimized for sentiment analysis and feedback extraction.

Available Tools

The server provides the following MCP tools, each designed to return token-optimized data:

Tool NameDescriptionParameters (see details in tool schema)
getVideoDetailsRetrieves detailed, lean information for multiple YouTube videos including metadata, statistics, engagement ratios, and content details.videoIds (array of strings)
searchVideosSearches for videos or channels based on a query string with various filtering options, returning concise results.query (string), maxResults (optional number), order (optional), type (optional), channelId (optional), etc.
getTranscriptsRetrieves token-efficient transcripts (captions) for multiple videos, with options for full text or key segments (intro/outro).videoIds (array of strings), lang (optional string for language code), format (optional enum: 'full_text', 'key_segments' - default 'key_segments')
getChannelStatisticsRetrieves lean statistics for multiple channels (subscriber count, view count, video count, creation date).channelIds (array of strings)
getChannelTopVideosRetrieves a list of a channel's top-performing videos with lean details and engagement ratios.channelId (string), maxResults (optional number)
getTrendingVideosRetrieves a list of trending videos for a given region and optional category, with lean details and engagement ratios.regionCode (optional string), categoryId (optional string), maxResults (optional number)
getVideoCategoriesRetrieves available YouTube video categories (ID and title) for a specific region, providing essential data only.regionCode (optional string)
getVideoCommentsRetrieves comments for a YouTube video. Allows sorting, limiting results, and fetching a small number of replies per comment.videoId (string), maxResults (optional number), order (optional), maxReplies (optional number), commentDetail (optional string)
findConsistentOutlierChannelsIdentifies channels that consistently perform as outliers within a specific niche. Requires a MongoDB connection.niche (string), minVideos (optional number), maxChannels (optional number)

For detailed input parameters and their descriptions, please refer to the inputSchema within each tool's configuration file in the src/tools/ directory (e.g., src/tools/video/getVideoDetails.ts).

Note on API Quota Costs: Most tools are highly efficient. getVideoDetails, getChannelStatistics, and getTrendingVideos cost only 1 unit per call. The getTranscripts tool has 0 API cost. The new getVideoComments tool has a variable cost: the base call is 1 unit, but if you request replies (by setting maxReplies > 0), it costs an additional 1 unit for each top-level comment it fetches replies for. The search-based tools are the most expensive: searchVideos costs 100 units and getChannelTopVideos costs 101 units.

Deep Dive: findConsistentOutlierChannels Tool

The findConsistentOutlierChannels tool is designed to identify emerging or established YouTube channels that consistently outperform their size within a specific niche. This tool is particularly useful for content creators, marketers, and analysts looking for high-potential channels.

Important Note: This tool requires a MongoDB connection to store and analyze channel data. Without MDB_MCP_CONNECTION_STRING configured, this tool will not be available.

Internal Logic Overview

The tool operates through a multi-phase analysis process, leveraging both YouTube Data API and a MongoDB database:

  1. Candidate Search (Phase 1):

    • Uses the provided query to search for relevant videos and channels on YouTube.
    • Filters initial results based on videoCategoryId and regionCode if specified.
    • Collects a broad set of potential channels for deeper analysis.
  2. Channel Filtering (Phase 2):

    • Retrieves detailed statistics for candidate channels (subscribers, total views, video count).
    • Filters channels based on channelAge (e.g., 'NEW' for channels under 6 months, 'ESTABLISHED' for 6-24 months).
    • Ensures channels meet a minimum video count to be considered for consistency.
  3. Deep Analysis (Phase 3):

    • For each filtered channel, fetches their recent top-performing videos.
    • Calculates a "viral factor" for each video (e.g., views relative to subscriber count).
    • Assesses the consistencyLevel (e.g., 'MODERATE' for ~30% of videos showing outlier performance, 'HIGH' for ~50%).
    • Determines outlierMagnitude (e.g., 'STANDARD' for views > subscribers, 'STRONG' for views > 3x subscribers).
  4. Ranking & Formatting (Phase 4):

    • Ranks channels based on their consistency, outlier magnitude, and overall performance within the niche.
    • Formats the results into a token-optimized structure suitable for LLMs, including key channel metrics and examples of outlier videos.

Key Parameters Controlling the Flow

The behavior of this tool is primarily controlled by the following parameters:

  • query (string, required): The central topic or niche to analyze (e.g., "DIY home repair", "quantum computing explained").
  • channelAge (enum: "NEW", "ESTABLISHED", default: "NEW"): Focuses the search on emerging or more mature channels.
  • consistencyLevel (enum: "MODERATE", "HIGH", default: "MODERATE"): Sets the threshold for how consistently a channel's videos must perform as outliers.
  • outlierMagnitude (enum: "STANDARD", "STRONG", default: "STANDARD"): Defines how significantly a video's performance must exceed typical expectations (e.g., views vs. subscribers) to be considered an "outlier."
  • videoCategoryId (string, optional): Narrows the search to a specific YouTube category ID.
  • regionCode (string, optional): Targets channels relevant to a particular geographical region.
  • maxResults (number, default: 10): Limits the number of top outlier channels returned.

Security Considerations

  • API Key Security: Your YOUTUBE_API_KEY is sensitive. Never commit it directly to your repository. Use environment variables (e.g., via a .env file which should be listed in .gitignore).
  • API Quotas: The YouTube Data API has a daily usage quota (default is 10,000 units). All tool calls deduct from this quota. Monitor your usage in the Google Cloud Console and be mindful of the cost of each tool. For a detailed breakdown of costs per API method, see the official documentation.
  • Input Validation: The server uses Zod for robust input validation for all tool parameters, enhancing security and reliability.