使用说明
YouTube分析MCP服务器
用于YouTube分析和数据收集的模型上下文协议(MCP)服务器。该服务器提供全面的工具,用于分析YouTube视频、频道、评论、成绩单和下载内容。
特性
- 视频分析:搜索视频,获取详细的元数据,分析性能指标
- 渠道分析:获取频道信息,列出频道视频,跟踪统计信息
- 内容集合:提取评论、成绩单并下载视频/音频
- 数据导出:使用回退方法下载各种格式的视频
- 速率限制:YouTube API的内置配额管理和费率限制
- 缓存:高效的缓存系统,最大限度地减少API调用
快速开始
1.安装
# Clone the repository
git clone <repository-url>
cd youtube-mcp-server
# Install dependencies
pip install -r requirements.txt
2.配置
复制示例环境文件并配置API密钥:
cp .env.example .env
编辑 .env 并添加您的API密钥:
# Required: YouTube Data API key
GOOGLE_API_KEY=your_youtube_data_api_key_here
# Optional: OpenAI API key for AI analysis features
OPENAI_API_KEY=your_openai_api_key_here
3.测试服务器
# Test that everything is configured correctly
python test_server.py
4.运行服务器
# Start the MCP server
python scripts/run_server.py
# Or run with custom options
python scripts/run_server.py --log-level DEBUG --port 8001
可用工具
服务器提供11个MCP工具:
数据收集
search_youtube_videos-搜索具有高级过滤功能的视频get_video_details-获取详细的视频元数据和统计数据get_channel_info-获取频道信息和统计数据get_channel_videos-列出特定频道的视频
内容分析
get_video_comments-通过情感分析提取视频评论get_video_transcript-获取视频转录/字幕analyze_video_performance-计算参与度指标和绩效得分get_trending_videos-按地区/类别获取热门视频
媒体操作
download_video-下载具有多种质量/格式选项的视频get_download_formats-检查可用的下载格式cleanup_downloads-清理旧的下载文件
使用Claude Desktop
将此服务器添加到您的Claude Desktop配置中:
{
"mcpServers": {
"youtube-analytics": {
"command": "python",
"args": ["/path/to/youtube-mcp-server/scripts/run_server.py"],
"env": {
"GOOGLE_API_KEY": "your_api_key_here"
}
}
}
}
示例用法
连接到Claude Desktop或MCP Inspector后,您可以使用以下命令:
Search for Python tutorial videos uploaded in the last month
Get detailed analytics for video ID dQw4w9WgXcQ
Download the top trending video in 720p quality
Analyze engagement metrics for my channel's latest 10 videos
配置选项
中的关键配置选项 .env:
# API Configuration
GOOGLE_API_KEY=your_key_here
YOUTUBE_API_QUOTA_LIMIT=10000
YOUTUBE_API_RATE_LIMIT=1.0
# Cache Settings
CACHE_DIRECTORY=youtube_cache
CACHE_TTL_SECONDS=3600
# Download Settings
DOWNLOAD_DIRECTORY=downloads
MAX_CONCURRENT_DOWNLOADS=3
# Feature Flags
ENABLE_CACHING=true
ENABLE_RATE_LIMITING=true
ENABLE_ANALYTICS=true
ENABLE_DOWNLOADS=true
发展
项目结构
youtube-mcp-server/
├── src/youtube_mcp_server/
│ ├── core/ # Core configuration and exceptions
│ ├── tools/ # MCP tools and API clients
│ └── infrastructure/ # Caching, rate limiting, etc.
├── scripts/ # CLI scripts
├── test_server.py # Test script
└── .env.example # Configuration template
运行测试
# Test server initialization
python test_server.py
# Run specific tool tests (if available)
python -m pytest tests/
需求
- Python 3.9+
- YouTube数据API v3密钥
- 中列出的依赖关系
requirements.txt
故障排除
常见问题
- 导入错误:确保安装了所有依赖项
- 超过API配额:检查您的YouTube API配额使用情况
- 身份验证错误:验证API密钥是否正确
- 下载失败:某些视频可能受到限制或不可用
调试模式
运行调试日志以查看详细信息:
python scripts/run_server.py --log-level DEBUG
许可证
MIT许可证-有关详细信息,请参阅许可证文件。