YouTube MCP Server
Enables AI models to interact with YouTube content through video search, channel information, transcripts, comments, trending videos, and content analysis tools including quiz and flashcard generation.
README
YouTube MCP Server
Model Contex Protocol (MCP) server that enables AI models to interact with YouTube content through a standardized interface. This server provides a set of tools for video search, content analysis, comment processing, and more.
🌟 Features
-
🔍 Video Search & Discovery
- Search YouTube videos
- Get trending videos
- Find related content
- Channel information
-
📊 Content Analysis
- Detailed video information
- Channel statistics
- Video transcripts
- Comprehensive summaries
-
💬 Social Features
- Comment retrieval
- Comment analysis
- User interaction data
🚀 Quick Start
Prerequisites
1. Installing Python
macOS:
# Using Homebrew (recommended)
brew install python@3.11
# Verify installation
python3 --version # Should show Python 3.11.x
Linux (Ubuntu/Debian):
# Update package list
sudo apt update
# Install Python
sudo apt install python3.11 python3.11-venv
# Verify installation
python3 --version # Should show Python 3.11.x
Windows:
- Download Python installer from python.org
- Run the installer
- Check "Add Python to PATH" during installation
- Open Command Prompt and verify:
python --version # Should show Python 3.11.x
2. Installing uv
macOS/Linux:
# Install uv using the official installer
curl -LsSf https://astral.sh/uv/install.sh | sh
# Verify installation
uv --version
Windows (PowerShell):
# Install uv using the official installer
(Invoke-WebRequest -Uri "https://astral.sh/uv/install.ps1" -UseBasicParsing).Content | pwsh -Command -
# Verify installation
uv --version
Alternative Installation Methods:
Using pip (if you prefer):
# Install uv using pip
pip install uv
# Verify installation
uv --version
3. Setting Up Google Cloud Credentials
-
Create a Google Cloud Project:
# Go to Google Cloud Console https://console.cloud.google.com # Click on "Select a Project" at the top # Click "New Project" # Name it (e.g., "youtube-mcp-server") # Click "Create" -
Enable YouTube Data API:
# In the Google Cloud Console: # 1. Go to "APIs & Services" > "Library" # 2. Search for "YouTube Data API v3" # 3. Click "Enable" -
Create OAuth 2.0 Credentials:
# In the Google Cloud Console: # 1. Go to "APIs & Services" > "Credentials" # 2. Click "Create Credentials" > "OAuth client ID" # 3. Select "Desktop app" as application type # 4. Name it (e.g., "YouTube MCP Client") # 5. Click "Create" -
Download and Store Credentials:
# 1. After creating credentials, click "Download JSON" # 2. Rename the downloaded file to 'credentials.json' # 3. Move it to your project root: mv ~/Downloads/client_secret_*.json ./credentials.json # Verify the file exists and has correct permissions ls -l credentials.json # Should show -rw------- (readable only by you) -
First-time Authentication:
# Run the server once to authenticate python mcp_videos.py # This will: # 1. Open your browser # 2. Ask you to sign in to Google # 3. Grant permissions to the application # 4. Create a token.pickle file (automatically ignored by git)
⚠️ Important Security Notes:
- Never commit
credentials.jsonortoken.pickleto git - Keep your credentials secure and don't share them
- If credentials are compromised:
- Go to Google Cloud Console
- Delete the compromised credentials
- Create new credentials
- Update your local
credentials.json
Installation
- Clone the repository:
git clone https://github.com/yourusername/youtube-mcp-server.git
cd youtube-mcp-server
- Create and activate a virtual environment:
# Create virtual environment
python -m venv .venv
# Activate virtual environment
# On macOS/Linux:
source .venv/bin/activate
# On Windows (Command Prompt):
.venv\Scripts\activate
# On Windows (PowerShell):
.venv\Scripts\Activate.ps1
- Install dependencies using uv:
# Install project in editable mode
uv pip install -e .
# If you encounter any SSL errors on macOS, you might need to:
export SSL_CERT_FILE=/etc/ssl/cert.pem
- Set up YouTube API credentials:
- Go to Google Cloud Console
- Create a new project
- Enable YouTube Data API v3
- Create credentials (OAuth 2.0 Client ID)
- Download the credentials and save as
client_secrets.json
Development Setup
For development, you might want to install additional tools:
# Install development dependencies
uv pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
Configuration
- Create a
.envfile in the project root:
# Required environment variables
YOUTUBE_API_KEY=your_api_key_here
# Optional configuration
YOUTUBE_API_QUOTA_LIMIT=10000 # Daily quota limit
YOUTUBE_API_REGION=US # Default region
- Verify your setup:
# Check if credentials are properly set up
ls -l credentials.json # Should exist and be readable
ls -l .env # Should exist and be readable
ls -l token.pickle # Should exist after first authentication
# Test the server
python mcp_videos.py
🛠️ Usage
Starting the Server
python mcp_videos.py
Available Tools
- Search Videos
@mcp.tool()
async def get_videos(search: str, max_results: int)
- Get Video Info
@mcp.tool()
async def get_video_info(video_id: str)
- Get Channel Details
@mcp.tool()
async def get_channel_details(channel_id: str)
- Get Video Comments
@mcp.tool()
async def get_video_comments_tool(video_id: str, max_results: int = 100)
- Get Trending Videos
@mcp.tool()
async def get_trending_videos_tool(region_code: str = "US", max_results: int = 50)
- Get Related Videos
@mcp.tool()
async def get_related_videos_tool(video_id: str, max_results: int = 25)
- Summarize Video
@mcp.tool()
async def summarize_video(video_id: str, include_comments: bool = True)
- Generate Video Flash Cards
@mcp.tool()
async def generate_video_flashcards(
video_id: str,
max_cards: int = 10,
categories: Optional[List[str]] = None,
difficulty: Optional[str] = None
)
This tool generates educational flash cards from video content:
- Creates different types of cards (Fill in the blank, Q&A, Definition)
- Includes timestamps for video reference
- Categorizes cards by type and difficulty
- Provides card statistics
Example usage:
# Generate 15 flash cards from a video
cards = generate_video_flashcards(
video_id="dQw4w9WgXcQ",
max_cards=15,
categories=["Q&A", "Definition"],
difficulty="Medium"
)
# Generate all types of cards
cards = generate_video_flashcards(
video_id="dQw4w9WgXcQ",
max_cards=20
)
Card Types:
- Fill in the blank: Tests recall of specific terms or concepts
- Q&A: Questions about key points in the video
- Definition: Explains important concepts
Difficulty Levels:
- Easy: Basic recall and understanding
- Medium: Application of concepts
- Hard: Complex concepts and relationships
- Generate Video Quiz
@mcp.tool()
async def generate_video_quiz(video_id: str) -> str
This tool generates a comprehensive quiz from video content:
- Creates multiple choice questions
- Generates true/false statements
- Includes fill-in-the-blank questions
- Uses video metadata, transcript, and description
- Provides answers and explanations
Example usage:
# Generate a quiz from a video
quiz = generate_video_quiz("dQw4w9WgXcQ")
Quiz Features:
-
Multiple Choice Questions
- Based on video content
- Includes video metadata
- Tests understanding of key concepts
-
True/False Questions
- Tests factual knowledge
- Based on video statistics
- Verifies understanding of claims
-
Fill in the Blank
- Tests recall of specific terms
- Uses transcript content
- Focuses on key concepts
Quiz Format:
=== Video Quiz ===
Title: [Video Title]
Channel: [Channel Name]
URL: [Video URL]
Question 1 (Multiple Choice):
[Question text]
1. [Option 1]
2. [Option 2]
3. [Option 3]
4. [Option 4]
Answer: [Correct answer]
------------------
Question 2 (True/False):
[Statement]
Answer: True/False
------------------
Question 3 (Fill in the blank):
[Question with blank]
Answer: [Correct answer]
------------------
The quiz tool:
- Generates exactly 10 questions
- Mixes different question types
- Includes video context
- Provides immediate feedback
- Uses video metadata for questions
- Incorporates transcript content
- Tests different levels of understanding
📊 Architecture
The project follows a modular architecture:
graph TD
A[LLM Client] --> B[MCP Client]
B --> C[MCP Server]
C --> D[YouTube API]
C --> E[Tool Registry]
C --> F[Data Formatter]
subgraph "Tools"
E --> E1[Video Tools]
E --> E2[Channel Tools]
E --> E3[Comment Tools]
E --> E4[Analysis Tools]
end
🔧 Development
Project Structure
youtube-mcp-server/
├── mcp_videos.py # Main server implementation
├── youtube_api.py # YouTube API client
├── yt_helper.py # Helper functions
├── requirements.txt # Project dependencies
├── .env # Environment variables
├── .gitignore # Git ignore rules
└── README.md # This file
Adding New Tools
- Create a new async function in
mcp_videos.py - Decorate it with
@mcp.tool() - Implement the tool logic
- Add appropriate error handling
- Update documentation
📝 API Documentation
Response Formats
- Video Format
{
"title": str,
"channel_title": str,
"duration": str,
"description": str,
"view_count": int,
"like_count": int,
"comment_count": int,
"url": str,
"published_at": str
}
- Channel Format
{
"title": str,
"subscriber_count": int,
"video_count": int,
"view_count": int,
"description": str,
"published_at": str
}
- Comment Format
{
"author": str,
"text": str,
"like_count": int,
"published_at": str
}
🤝 Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- FastMCP for the MCP framework
- YouTube Data API for the API
- All contributors and users of this project
📞 Support
For support, please:
- Check the documentation
- Open an issue
- Contact the maintainers
🔄 Updates
Stay updated with the project:
🔒 Security
Handling Sensitive Data
⚠️ IMPORTANT: Never commit sensitive files to the repository:
token.pickleclient_secrets.json.envfiles- Any other credential files
These files are automatically ignored by .gitignore, but if you accidentally commit them:
- Remove them from git tracking:
git rm --cached token.pickle
git rm --cached client_secrets.json
- Revoke and regenerate any exposed credentials
- Update your local
.envfile with new credentials - Never share or expose these files publicly
Best Practices
- Always use environment variables for sensitive data
- Keep credentials in
.envfile (already in.gitignore) - Regularly rotate API keys and tokens
- Use OAuth 2.0 for authentication
- Monitor GitHub's secret scanning alerts
🖥️ Claude Desktop Setup
1. Install Claude Desktop
-
Download Claude Desktop:
- Visit Claude Desktop
- Download the appropriate version for your OS:
- macOS:
.dmgfile - Windows:
.exeinstaller - Linux:
.AppImageor.debpackage
- macOS:
-
Install the Application:
# macOS # 1. Open the .dmg file # 2. Drag Claude to Applications folder # 3. Open from Applications # Windows # 1. Run the .exe installer # 2. Follow the installation wizard # 3. Launch from Start Menu # Linux (Ubuntu/Debian) sudo dpkg -i claude-desktop_*.deb # For .deb package # OR chmod +x Claude-*.AppImage # For AppImage ./Claude-*.AppImage
2. Configure MCP Client
-
Open Claude Desktop Settings:
- Click on the gear icon (⚙️) or
- Use keyboard shortcut:
- macOS:
Cmd + , - Windows/Linux:
Ctrl + ,
- macOS:
-
Add MCP Configuration:
- Navigate to "MCP Settings" or "Advanced Settings"
- Add the following configuration:
{ "mcpServers": { "youtube_videos": { "command": "uv", "args": [ "--directory", "<your base directory>/youtube-mcp-server", "run", "mcp_videos.py" ] } } } -
Replace Path:
-
Replace
<your base directory>with your actual project path -
Example for different OS:
// macOS/Linux "/Users/username/Documents/youtube-mcp-server" // Windows "C:\\Users\\username\\Documents\\youtube-mcp-server"
-
-
Verify Configuration:
# Test the MCP server path cd "<your base directory>/youtube-mcp-server" uv run mcp_videos.py
3. Using Claude with MCP
-
Start Claude Desktop
-
Connect to MCP Server:
- The server should start automatically
- You'll see a connection status indicator
- Available tools will be listed in the interface
-
Test the Connection:
# Try a simple command get_videos("python programming", max_results=5)
Troubleshooting MCP Connection
-
Server Won't Start:
# Check if the path is correct pwd # Should show your project directory # Verify Python environment which python # Should point to your virtual environment # Check uv installation uv --version -
Connection Issues:
- Verify the server is running
- Check the configuration path
- Ensure all dependencies are installed
- Check the logs in Claude Desktop
-
Common Errors:
# Path not found # Solution: Use absolute path in configuration # Permission denied # Solution: Check file permissions chmod +x mcp_videos.py # Module not found # Solution: Verify virtual environment source .venv/bin/activate # or appropriate activation command
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。