一个强大的模型上下文协议(MCP)服务器,使Claude AI能够完全访问YouTube内容——转录本、元数据、评论、屏幕截图和音频片段。
适用于Claude Desktop(本地)和Claude Web UI(使用OAuth远程)。
演示
为什么选择MCP?
| 功能 | 此MCP | 大多数其他 |
|---|---|---|
| 成绩单 | ✅ | ✅ |
| 时间戳 | ✅ | 一些 |
| 时间范围过滤 | ✅ | 稀有 |
| 成绩单搜索 | ✅ | 稀有 |
| 关键段(钩/支腿) | ✅ | ❌ |
| 元数据 | ✅ | ✅ |
| 播放列表 | ✅ | 一些 |
| 评论 | ✅ | 非常罕见 |
| 屏幕截图 | ✅ | 1-2其他 |
| 音频剪辑 | ✅ | ❌ |
| 所有URL格式 | ✅ | 部分 |
| OAuth 2.1+PKCE | ✅ | ❌ |
| 密码保护 | ✅ | ❌ |
| 速率限制 | ✅ | ❌ |
| Claude Web UI支持 | ✅ | 很少 |
特性
| 工具 | 说明 |
|---|---|
get_video | 使用搜索、时间戳和时间范围获取视频元数据和转录 |
get_playlist | 列出播放列表中的所有视频 |
get_comments | 获取包含点赞和回复数的热门评论 |
get_screenshot | 在任何时间戳捕获视频帧 |
get_audio | 提取音频片段(最多120秒)用于语音/音乐分析 |
快速开始
选项1:本地模式(克劳德桌面)
# Install
git clone https://github.com/Comzee/Youtube-Ultimate-Toolkit-MCP.git
cd Youtube-Ultimate-Toolkit-MCP
npm install
npm run build
# Run
node dist/index.js添加到Claude桌面配置(~/.config/claude/claude_desktop_config.json 在Linux上, ~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):
{
"mcpServers": {
"youtube": {
"command": "node",
"args": ["/path/to/Youtube-Ultimate-Toolkit-MCP/dist/index.js"]
}
}
}选项2:远程模式(Claude Web UI)
远程模式需要OAuth设置和公共URL。请参阅 远程模式设置 在......下面
先决条件
- Node.js 18+
- yt-dlp -YouTube内容提取器(必须保持更新)
- FFmpeg -用于截图和音频提取(可选)
- YouTube API密钥 -仅用于评论功能(可选)
安装先决条件
Ubuntu/Debian:
# Node.js 18+
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
# yt-dlp (keep updated - YouTube breaks old versions frequently)
pip3 install --upgrade yt-dlp
# ffmpeg (for screenshots and audio)
sudo apt install ffmpegmacOS:
brew install node yt-dlp ffmpeg窗户:
# Install Node.js from https://nodejs.org
# Install yt-dlp: pip install yt-dlp
# Install ffmpeg from https://ffmpeg.org/download.html保持yt-dlp更新
YouTube经常更改其API。如果成绩单停止工作,请更新yt-dlp:
pip3 install --upgrade yt-dlp
# or on systems that complain about externally-managed packages:
pip3 install --upgrade --break-system-packages yt-dlp安装
git clone https://github.com/Comzee/Youtube-Ultimate-Toolkit-MCP.git
cd Youtube-Ultimate-Toolkit-MCP
npm install
npm run build远程模式设置
远程模式允许您通过HTTPS和OAuth身份验证将此MCP与Claude Web UI(Claude.ai)一起使用。
1.配置环境
cp .env.example .env编辑 .env:
# OAuth credentials
OAUTH_CLIENT_ID=youtube-mcp-client
OAUTH_CLIENT_SECRET=your-secret-here # Generate: openssl rand -hex 32
# Password for the consent page (bcrypt hash)
# Generate: node -e "require('bcrypt').hash('your-password', 12).then(console.log)"
AUTH_PASSWORD_HASH=$2b$12$...your-hash-here...
# Optional: YouTube API key for get_comments tool
YOUTUBE_API_KEY=your-api-key-here2.启动服务器
# Development
npm run start:remote
# Production (with systemd)
sudo cp youtube-mcp.service /etc/systemd/system/
# Edit the service file to set your username and paths
sudo nano /etc/systemd/system/youtube-mcp.service
sudo systemctl daemon-reload
sudo systemctl enable youtube-mcp
sudo systemctl start youtube-mcp3.设置HTTPS(必填)
Claude Web UI需要HTTPS。使用nginx作为反向代理:
server {
listen 443 ssl;
server_name your-domain.com;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
location / {
proxy_pass http://localhost:3010;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Important for long-running requests
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
proxy_set_header X-Accel-Buffering no;
}
}4.连接Claude Web用户界面
- 首选 设置 → 连接器 → 添加自定义连接器
- 输入URL:
https://your-domain.com/mcp - 开始新的聊天并启用MCP
- 让Claude获取YouTube视频-将出现授权弹出窗口
- 在同意页面上输入密码,然后单击“授权”
工具参考
获取_视频
获取视频元数据和英文成绩单。
参数:
| 参数 | 必填 | 说明 |
|---|---|---|
url | 是 | YouTube URL(任何格式)或视频ID |
includeTimestamps | 否 | 添加 [M:SS] 每行的时间戳 |
startTime | 否 | 转录范围的开始时间(例如“60”、“1:00”) |
endTime | 否 | 成绩单范围的结束时间 |
searchTerm | 否 | 搜索成绩单并突出显示匹配项 |
keySegmentsOnly | 否 | 仅返回钩子(前40秒)和外旋(后30秒) |
支持的URL格式:
youtube.com/watch?v=VIDEO_IDyoutu.be/VIDEO_IDyoutube.com/shorts/VIDEO_IDyoutube.com/live/VIDEO_IDyoutube.com/embed/VIDEO_IDm.youtube.com/watch?v=VIDEO_IDmusic.youtube.com/watch?v=VIDEO_ID- 直接视频ID:
dQw4w9WgXcQ
get_playlist
在YouTube播放列表中列出视频。
参数:
| 参数 | 必填 | 说明 |
|---|---|---|
url | 是 | YouTube播放列表URL |
limit | 否 | 要返回的最大视频数(默认值:50,最大值:200) |
获取_注释
从视频中获取热门评论。 需要 YOUTUBE_API_KEY 在.env中。
参数:
| 参数 | 必填 | 说明 |
|---|---|---|
url | 是 | YouTube视频URL或ID |
maxResults | 否 | 评论数(默认值:25,最大值:100) |
order | 否 | 排序:“相关性”(默认)或“时间” |
get_creenshot
从视频中捕获一帧。 需要ffmpeg。
参数:
| 参数 | 必填 | 说明 |
|---|---|---|
url | 是 | YouTube视频URL |
timestamp | 无 | 捕获时间(默认值:“0”)。格式:“30”、“1:30”和“1:30:00” |
退货: Base64编码的JPEG图像
获取音频
提取音频片段进行分析。 需要ffmpeg。
参数:
| 参数 | 必填 | 说明 |
|---|---|---|
url | 是 | YouTube视频URL |
startTime | 否 | 开始时间(默认值:“0”) |
endTime | 否 | 结束时间(可选) |
maxDuration | 否 | 最大秒数(默认值:60,最大值:120) |
退货: Base64编码MP3音频(128kbps)
OAuth和安全
远程模式使用PKCE实现OAuth 2.1以进行安全身份验证。
运作原理
- 克劳德连接到
/mcp-发现/握手方法无需身份验证即可工作 - 当您使用工具时,Claude会收到一个401,其中包含OAuth发现信息
- Claude执行动态客户端注册
- 浏览器打开同意页面-您输入密码
- Claude将身份验证码交换为访问令牌
- 后续请求使用Bearer令牌
安全特性
| 功能 | 保护 |
|---|---|
| 密码保护的同意 | 只有您可以授权访问 |
| Bcrypt密码哈希 | 安全存储密码 |
| 速率限制 | 每个IP 5次尝试,然后锁定10分钟 |
| XSS保护 | 所有OAuth参数HTML转义 |
| 命令注入保护 | yt-dlp生成于 shell: false |
| PKCE(S256) | 防止授权码被拦截 |
故障排除
“没有可用的英语成绩单”
更新yt-dlp-YouTube经常更改:
pip3 install --upgrade yt-dlpMCP无法从Claude Web UI连接
- 确保HTTPS配置正确
- 检查服务状态:
sudo systemctl status youtube-mcp - 检查日志:
sudo journalctl -u youtube-mcp -f
OAuth流未启动
- 验证
.well-known/端点返回200(不是401) - 检查浏览器控制台是否存在CORS错误
- 确保
/register返回有效凭据
授权窗口未出现
- OAuth首先触发 工具使用,未连接
- 开始聊天,启用MCP,然后让Claude获取YouTube视频
克劳德使用了错误/旧的工具
在Claude设置中断开并重新连接MCP以刷新工具列表。
克劳德项目提示
在Claude项目中使用此提示自动利用MCP:
You have access to the YouTube MCP server. When I share a YouTube URL:
1. Automatically fetch the transcript with get_video
2. Provide a summary, key takeaways, and notable quotes
3. For long videos (10+ min), consider using keySegmentsOnly=true first
Available tools:
- get_video: Transcript and metadata (supports timestamps, time ranges, search)
- get_playlist: List videos in a playlist
- get_comments: Top comments (requires API key)
- get_screenshot: Capture frames at any timestamp
- get_audio: Extract audio clips for analysis (max 120s)建筑
- 运输: 可流式HTTP(MCP规范2025-03-26)
- 会议: 具有UUID标识符的状态(内存中)
- OAuth: 授权码+PKCE,动态客户端注册
- 代币: 内存存储(重启时丢失)
许可证
麻省理工学院-参见 许可证 了解详情。
贡献
欢迎投稿!请在GitHub上打开问题或PR。
