Integrates with Google Cloud to access the YouTube Data API v3, requiring a Google Cloud Project with the YouTube Data API enabled and an API key.
Provides tools for searching YouTube videos, retrieving video details, accessing channel information, and fetching video comments using the YouTube Data API v3.
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
- Clone the repository:
- Create a virtual environment (recommended):
- Install dependencies:
- Configure Environment Variables:
Create a
.env
file in the root directory of the project based on.env.example
:Replaceyour_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:
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
- Build the Docker image:
- Run the Docker container:
Make sure to pass your API key as an environment variable.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
orusername
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.
This server cannot be installed
A FastAPI server that enables interaction with YouTube's data through search, video details, channel information, and comment retrieval endpoints.
Related MCP Servers
- AsecurityFlicenseAqualityThis 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 -7211280TypeScript
- -securityFlicense-qualityA server for downloading, processing, and managing YouTube content with features like video quality selection, format conversion, and metadata extraction.Last updated -JavaScript
- -securityFlicense-qualityEnables 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,42341JavaScript
- AsecurityFlicenseAqualityA 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 -1214JavaScript