Skip to main content
Glama

YouTube Data API MCP Server

by Happm3p

YouTube Data API v3 MCP Server

This is a FastAPI-based server designed to interact with the YouTube Data API v3. It provides endpoints to search for YouTube videos, retrieve video details, get channel information, and fetch video comments.

Features

  • Search YouTube videos by query, order, and channel.
  • Get detailed information for a specific YouTube video.
  • Get detailed information for a YouTube channel by ID or username.
  • Retrieve comments for a specific YouTube video.

Requirements

  • Python 3.9+
  • A Google Cloud Project with the YouTube Data API v3 enabled.
  • An API Key for the YouTube Data API v3.

Setup and Installation

  1. Clone the repository:
    git clone <repository_url> cd youtube-mcp-server
  2. Create a virtual environment (recommended):
    python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
  3. Install dependencies:
    pip install -r requirements.txt
  4. Configure Environment Variables: Create a .env file in the root directory of the project based on .env.example:
    YOUTUBE_API_KEY=your_youtube_api_key_here
    Replace your_youtube_api_key_here with your actual YouTube Data API v3 Key. Keep this key secure and do not commit it to version control.

Running the Server

Locally

To run the server locally using Uvicorn:

uvicorn main:app --host 0.0.0.0 --port 8000 --reload

The --reload flag is useful for development as it restarts the server on code changes.

The API will be accessible at http://localhost:8000. Access the interactive API documentation (Swagger UI) at http://localhost:8000/docs.

Using Docker

  1. Build the Docker image:
    docker build -t youtube-mcp-server .
  2. Run the Docker container: Make sure to pass your API key as an environment variable.
    docker run -d -p 8000:8000 --name youtube-server -e YOUTUBE_API_KEY="your_youtube_api_key_here" youtube-mcp-server
    Replace "your_youtube_api_key_here" with your actual API key.

API Endpoints

All endpoints are prefixed with /youtube/.

1. Health Check

  • GET /health
  • Description: Checks if the server is running.

2. Search YouTube Videos

  • GET /youtube/videos/search
  • Description: Searches YouTube videos based on a query.
  • Query Parameters:
    • query (string, required): The search query string.
    • max_results (integer, optional, default: 10, max: 50): Maximum number of results.
    • order (string, optional, default: "relevance"): Order of results (e.g., "date", "viewCount").
    • channel_id (string, optional): Restricts search to a specific channel.
  • Example: /youtube/videos/search?query=FastAPI tutorial&max_results=5

3. Get YouTube Video Details

  • GET /youtube/videos/{video_id}
  • Description: Retrieves detailed information for a specific YouTube video.
  • Path Parameters:
    • video_id (string, required): The ID of the YouTube video.
  • Example: /youtube/videos/dQw4w9WgXcQ

4. Get YouTube Channel Details

  • GET /youtube/channels
  • Description: Retrieves detailed information for a YouTube channel by ID or username.
  • Query Parameters:
    • channel_id (string, optional): The ID of the YouTube channel.
    • username (string, optional): The username of the YouTube channel (legacy).
    • Note: At least one of channel_id or username must be provided.
  • Example: /youtube/channels?channel_id=UC_x5XG1OV2P6wRIMAn-Ny3A (Google Developers channel)
  • Example: /youtube/channels?username=PewDiePie (Note: Username lookup is less reliable now)

5. Get YouTube Video Comments

  • GET /youtube/videos/{video_id}/comments
  • Description: Retrieves comments for a specified YouTube video.
  • Path Parameters:
    • video_id (string, required): The ID of the YouTube video.
  • Query Parameters:
    • max_results (integer, optional, default: 100, max: 100): Maximum number of comments to return.
  • Example: /youtube/videos/dQw4w9WgXcQ/comments

Error Handling

The API returns standard HTTP status codes for errors (e.g., 400 Bad Request, 404 Not Found, 500 Internal Server Error) with a JSON payload containing a detail message.

-
security - not tested
F
license - not found
-
quality - not tested

A FastAPI server that enables interaction with YouTube's data through search, video details, channel information, and comment retrieval endpoints.

  1. Features
    1. Requirements
      1. Setup and Installation
        1. Running the Server
          1. Locally
          2. Using Docker
        2. API Endpoints
          1. 1. Health Check
          2. 2. Search YouTube Videos
          3. 3. Get YouTube Video Details
          4. 4. Get YouTube Channel Details
          5. 5. Get YouTube Video Comments
        3. Error Handling

          Related MCP Servers

          • A
            security
            F
            license
            A
            quality
            This server allows AI language models to interact with YouTube content through a standardized interface, providing features such as video and channel information retrieval, transcript management, and playlist operations.
            Last updated -
            7
            211
            280
            TypeScript
            • Linux
            • Apple
          • -
            security
            F
            license
            -
            quality
            Enables AI language models to interact with YouTube content through a standardized interface, providing tools for retrieving video information, transcripts, channel analytics, and trend analysis.
            Last updated -
            4,423
            41
            JavaScript
          • A
            security
            F
            license
            A
            quality
            A server that enables interaction with YouTube data through the Model Context Protocol, allowing users to search videos, retrieve detailed information about videos/channels, and fetch comments.
            Last updated -
            12
            1
            4
            JavaScript
          • -
            security
            F
            license
            -
            quality
            A Model Context Protocol server that provides comprehensive YouTube search functionality, enabling users to search for videos, channels, and playlists with advanced filtering options using the YouTube Data API.
            Last updated -
            Python

          View all related MCP servers

          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/Happm3p/MCP'

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