YouTube MCP Server
A simple Model Context Protocol (MCP) server that provides YouTube video metadata and transcripts. Built with FastMCP for a cleaner, more Pythonic approach.
Features
- Get Video Metadata: Retrieve title, description, duration, view count, upload date, channel info, and thumbnail
- Get Video Transcript: Fetch video transcripts in multiple languages with automatic fallback
Installation
- Install Python dependencies:```bash
pip install -r requirements.txt
2. Make the server executable:```bash
chmod +x server.py
Usage
Running the Server
The server uses stdio for communication. Run it with:```bash
python server.py
### MCP Client Configuration
Add this server to your MCP client configuration (e.g., in Cursor or another MCP-compatible client):```json
{
"mcpServers": {
"youtube-mcp": {
"command": "python",
"args": ["/path/to/youtube-mcp/server.py"]
}
}
}
Tool: get_youtube_video_info
Parameters:
- video_url_or_id (required): YouTube video URL or video ID
- Examples:
- https://www.youtube.com/watch?v=dQw4w9WgXcQ
- https://youtu.be/dQw4w9WgXcQ
- dQw4w9WgXcQ
- language_codes (optional): Array of preferred language codes for transcript (default: ["en"])
- Example: ["en", "es", "fr"]
Returns:
- video_id: The extracted video ID
- metadata: Video metadata including title, description, duration, views, etc.
- transcript: Transcript data including full text, segments, language, and generation status
Example Response:json
{
"video_id": "dQw4w9WgXcQ",
"metadata": {
"title": "Video Title",
"description": "Video description...",
"duration": 212,
"view_count": 1000000,
"upload_date": "20231015",
"uploader": "Channel Name",
"channel": "Channel Name",
"thumbnail": "https://...",
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
},
"transcript": {
"transcript": "Full transcript text...",
"segments": [
{
"text": "Segment text",
"start": 0.0,
"duration": 5.0
}
],
"language": "en",
"is_generated": false
}
}
Dependencies
fastmcp: FastMCP framework - A Pythonic MCP framework with intuitive decorators (developed by Prefect)youtube-transcript-api: For fetching YouTube transcriptsyt-dlp: For fetching YouTube video metadatapydantic: For data validation
Why FastMCP?
FastMCP is a modern, Pythonic framework for building MCP servers that:
- Uses intuitive decorators (@mcp.tool()) instead of manual tool registration
- Simplifies server setup with mcp.run() instead of managing stdio streams
- Provides better type inference and validation
- Offers a cleaner, more maintainable codebase
- Is actively maintained by Prefect with excellent documentation
Notes
- The server automatically extracts video IDs from various YouTube URL formats
- Transcripts fall back to auto-generated versions if manually created transcripts aren't available
- If no transcript is available in the preferred language, it will attempt to find any available transcript