YouTube 模型上下文协议 (MCP) 服务器可助力用户便捷地与 YouTube API 交互,实现视频、频道及播放列表的管理功能。
若想快速使用 YouTube 模型上下文协议 (MCP) 服务器,可按如下步骤操作:
使用以下命令,借助 Smithery 进行安装:
npx -y @smithery/cli install @ZubeidHendricks/youtube --client claude
git clone https://github.com/ZubeidHendricks/youtube-mcp-server.git
cd youtube-mcp-server
npm install
YOUTUBE_API_KEY
:此为访问 YouTube API 所需的密钥。YOUTUBE_TRANSCRIPT_LANG
(可选):用于设置默认字幕语言,当值为 "en" 时,使用英文。将以下内容添加到 VS Code 的用户设置 (JSON) 文件中:
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "apiKey",
"description": "YouTube API Key",
"password": true
}
],
"servers": {
"youtube": {
"command": "npx",
"args": ["-y", "zubeid-hendricks/youtube-mcp-server"],
"env": {
"YOUTUBE_API_KEY": "${input:apiKey}"
}
}
}
}
}
// 获取视频详情
const video = await youtube.videos.getVideo({
videoId: "video-id"
});
// 获取视频字幕
const transcript = await youtube.transcripts.getTranscript({
videoId: "video-id",
language: "en"
});
// 搜索视频
const searchResults = await youtube.videos.searchVideos({
query: "搜索词",
maxResults: 10
});
// 获取频道详情
const channel = await youtube.channels.getChannel({
channelId: "channel-id"
});
// 列出频道视频
const videos = await youtube.channels.listVideos({
channelId: "channel-id",
maxResults: 50
});
// 获取播放列表项
const playlistItems = await youtube.playlists.getPlaylistItems({
playlistId: "playlist-id",
maxResults: 50
});
// 获取播放列表详情
const playlist = await youtube.playlists.getPlaylist({
playlistId: "playlist-id"
});
# 安装依赖
npm install
# 运行测试
npm test
# 构建项目
npm run build
# 检查代码
npm run lint
若你想为该项目做出贡献,请参阅 CONTRIBUTING.md
了解具体方式。
本项目遵循 MIT 许可证,详细信息请查看 LICENSE
文件。