YouTube MCP 服务器
用于与 YouTube 视频交互的模型上下文协议 (MCP) 服务器。该服务器提供用于提取视频元数据和字幕的工具,并使用各种模板将其转换为 Markdown 格式。
特征
Related MCP server: YouTube Integration
先决条件
安装
克隆存储库:
git clone [repository-url]
cd youtube-mcp
安装依赖项:
构建项目:
配置
使用您的 YouTube 凭据在根目录中创建一个.env文件:
YOUTUBE_API_KEY=your_api_key
YOUTUBE_CLIENT_ID=your_client_id
YOUTUBE_CLIENT_SECRET=your_client_secret
YOUTUBE_REFRESH_TOKEN=your_refresh_token # Optional, for OAuth2
MCP 配置
将服务器添加到您的 MCP 设置文件(通常位于~/.config/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json ):
{
"mcpServers": {
"youtube": {
"command": "node",
"args": ["path/to/youtube-mcp/build/index.js"],
"env": {
"YOUTUBE_API_KEY": "your_api_key",
"YOUTUBE_CLIENT_ID": "your_client_id",
"YOUTUBE_CLIENT_SECRET": "your_client_secret"
},
"disabled": false,
"alwaysAllow": []
}
}
}
用法
该服务器提供以下工具:
1. 获取视频信息
use_mcp_tool youtube get_video_info {
"url": "https://www.youtube.com/watch?v=VIDEO_ID"
}
2. 获取字幕
use_mcp_tool youtube get_captions {
"url": "https://www.youtube.com/watch?v=VIDEO_ID",
"language": "en" // Optional, defaults to "en"
}
3. 转换为 Markdown
use_mcp_tool youtube convert_to_markdown {
"url": "https://www.youtube.com/watch?v=VIDEO_ID",
"template_name": "detailed", // Optional, "basic", "detailed", or "search"
"language": "en", // Optional
"options": { // Optional
"include_chapters": true,
"search_term": "keyword" // Only for search template
}
}
4. 列表模板
use_mcp_tool youtube list_templates
依赖项
{
"dependencies": {
"@modelcontextprotocol/sdk": "latest",
"googleapis": "^146.0.0",
"google-auth-library": "^9.0.0",
"youtube-captions-scraper": "^2.0.0",
"express": "^4.18.2",
"open": "^9.1.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"typescript": "^5.0.0",
"tsx": "^4.0.0"
}
}
OAuth2 设置
对于 OAuth2 身份验证(私人视频访问所需):
在Google Cloud Console中创建项目
启用 YouTube 数据 API v3
创建 OAuth2 凭据(Web 应用程序类型)
运行身份验证脚本:
按照浏览器提示授权应用程序
将刷新令牌复制到您的配置中
自定义模板
您可以通过修改src/index.ts中的DEFAULT_TEMPLATES数组来添加自定义模板。模板遵循以下结构:
interface MarkdownTemplate {
name: string;
description: string;
format: {
header?: string;
chapter_format?: string;
caption_block: string;
timestamp_format?: string;
search_result_format?: string;
}
}
执照
麻省理工学院
贡献
分叉存储库
创建你的功能分支( git checkout -b feature/amazing-feature )
提交您的更改( git commit -m 'Add some amazing feature' )
推送到分支( git push origin feature/amazing-feature )
打开拉取请求