mcp-youtube

mcp-youtube

High-efficiency YouTube MCP server: Get token-optimized, structured data for your LLMs using the YouTube Data API v3.

Category
访问服务器

README

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>

<p align="left"> <a href="https://smithery.ai/server/@kirbah/mcp-youtube"> <img src="https://smithery.ai/badge/@kirbah/mcp-youtube" alt="View on Smithery" /> </a> </p> <!-- Badges End -->

High-efficiency YouTube MCP server: Get token-optimized, structured data for your LLMs using the YouTube Data API v3.

This Model Context Protocol (MCP) server empowers AI language models to seamlessly interact with YouTube. It's engineered to return lean, structured data, significantly reducing token consumption and making it ideal for cost-effective and performant LLM applications. Access a comprehensive suite of tools for video search, detail retrieval, transcript fetching, channel analysis, and trend discovery—all optimized for AI.

Quick Start: Adding to an MCP Client

The easiest way to use @kirbah/mcp-youtube is with an MCP-compatible client application (like Claude Desktop or a custom client).

  1. Ensure you have a YouTube Data API v3 Key.

  2. MongoDB Connection String (Optional): This server can use MongoDB to cache API responses and store analysis data, which significantly improves performance and reduces API quota usage. If you don't provide a connection string, the server will run without a database, but performance will be degraded, and you may hit API quota limits faster. You can get a free MongoDB Atlas cluster to obtain a connection string.

    Important: If you use MongoDB, the server is hardcoded to use the database name youtube_niche_analysis. Your connection string must point to this database, and your user must have read/write permissions for it.

  3. Configure your MCP client: Add the following JSON configuration to your client, replacing "YOUR_YOUTUBE_API_KEY_HERE" with your actual API key.

    {
      "mcpServers": {
        "youtube": {
          "command": "npx",
          "args": ["-y", "@kirbah/mcp-youtube"],
          "env": {
            "YOUTUBE_API_KEY": "YOUR_YOUTUBE_API_KEY_HERE",
            "MDB_MCP_CONNECTION_STRING": "mongodb+srv://user:pass@cluster0.abc.mongodb.net/youtube_niche_analysis"
          }
        }
      }
    }
    
    • Windows PowerShell Users: npx can sometimes cause issues directly. If you encounter problems, try modifying the command as follows:
        "command": "cmd",
        "args": ["/k", "npx", "-y", "@kirbah/mcp-youtube"],
      

That's it! Your MCP client should now be able to leverage the YouTube tools provided by this server.

Why @kirbah/mcp-youtube?

In the world of Large Language Models, every token counts. @kirbah/mcp-youtube is designed from the ground up with this principle in mind:

  • 🚀 Token Efficiency: Get just the data you need, precisely structured to minimize overhead for your LLM prompts and responses.
  • 🧠 LLM-Centric Design: Tools and data formats are tailored for easy integration and consumption by AI models.
  • 📊 Comprehensive YouTube Toolkit: Access a wide array of YouTube functionalities, from video details and transcripts to channel statistics and trending content.
  • 🛡️ Robust & Reliable: Built with strong input validation (Zod) and clear error handling.

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.

Available Tools

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

Tool Name Description Parameters (see details in tool schema)
getVideoDetails Retrieves detailed, lean information for multiple YouTube videos including metadata, statistics, engagement ratios, and content details. videoIds (array of strings)
searchVideos Searches 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.
getTranscripts Retrieves 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')
getChannelStatistics Retrieves lean statistics for multiple channels (subscriber count, view count, video count, creation date). channelIds (array of strings)
getChannelTopVideos Retrieves a list of a channel's top-performing videos with lean details and engagement ratios. channelId (string), maxResults (optional number)
getTrendingVideos Retrieves 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)
getVideoCategories Retrieves available YouTube video categories (ID and title) for a specific region, providing essential data only. regionCode (optional string)

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, costing only 1 unit per call. The exceptions are the search-based tools: searchVideos costs 100 units and getChannelTopVideos costs 101 units. The getTranscripts tool has 0 API cost.

Advanced Usage & Local Development

If you wish to contribute, modify the server, or run it locally outside of an MCP client's managed environment:

Prerequisites

  • Node.js (version specified in package.json engines field - currently >=20.0.0)
  • npm (usually comes with Node.js)
  • A YouTube Data API v3 Key (see YouTube API Setup)

Local Setup

  1. Clone the repository:

    git clone https://github.com/kirbah/mcp-youtube.git
    cd mcp-youtube
    
  2. Install dependencies:

    npm ci
    
  3. Configure Environment: Create a .env file in the root by copying .env.example:

    cp .env.example .env
    

    Then, edit .env to add your YOUTUBE_API_KEY:

    YOUTUBE_API_KEY=your_youtube_api_key_here
    MDB_MCP_CONNECTION_STRING=your_mongodb_connection_string_here
    

Development Scripts

# Run in development mode with live reloading
npm run dev

# Build for production
npm run build

# Run the production build (after npm run build)
npm start

# Lint files
npm run lint

# Run tests
npm run test
npm run test -- --coverage # To generate coverage reports

# Inspect MCP server using the Model Context Protocol Inspector
npm run inspector

Local Development with an MCP Client

To have an MCP client run your local development version (instead of the published NPM package):

  1. Ensure you have a script in package.json for a non-watching start, e.g.:

    "scripts": {
      "start:client": "tsx ./src/index.ts"
    }
    
  2. Configure your MCP client to spawn this local script:

    {
      "mcpServers": {
        "youtube_local_dev": {
          "command": "npm",
          "args": ["run", "start:client"],
          "working_directory": "/absolute/path/to/your/cloned/mcp-youtube",
          "env": {
            "YOUTUBE_API_KEY": "YOUR_LOCAL_DEV_API_KEY_HERE"
          }
        }
      }
    }
    

    Note on the env block above: Setting YOUTUBE_API_KEY directly in the env block for the client configuration is one way to provide the API key. Alternatively, if your server correctly loads its .env file based on the working_directory, you might not need to specify it in the client's env block, as long as your local .env file in the project root contains the YOUTUBE_API_KEY. The working_directory path must be absolute and correct for the server to find its .env file.

YouTube API Setup

  1. Go to the Google Cloud Console.
  2. Create a new project or select an existing one.
  3. In the navigation menu, go to "APIs & Services" > "Library".
  4. Search for "YouTube Data API v3" and Enable it for your project.
  5. Go to "APIs & Services" > "Credentials".
  6. Click "+ CREATE CREDENTIALS" and choose "API key".
  7. Copy the generated API key. This is your YOUTUBE_API_KEY.
  8. Important Security Step: Restrict your API key to prevent unauthorized use. Click on the API key name, and under "API restrictions," select "Restrict key" and choose "YouTube Data API v3." You can also add "Application restrictions" (e.g., IP addresses) if applicable.

How it Works (MCP stdio)

This server is an MCP server that communicates via Standard Input/Output (stdio). It does not listen on network ports. An MCP client application will typically spawn this server script as a child process and communicate by writing requests to its stdin and reading responses from its stdout.

System Requirements

  • Node.js: >=20.0.0 (as specified in package.json)
  • npm (for managing dependencies and running scripts)

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.

License

This project is licensed under the MIT License. See the LICENSE file for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选