内容
# YouTube MCP Server
<div align="center">
<img src="https://img.shields.io/badge/YouTube_API-v3-red" alt="YouTube API Version">
<img src="https://img.shields.io/badge/MCP-Model_Context_Protocol-green" alt="MCP">
<img src="https://img.shields.io/badge/Claude-compatible-blue" alt="Claude Compatible">
<img src="https://img.shields.io/badge/license-MIT-orange" alt="License">
</div>
这是一个 MCP (Model Context Protocol) 服务器,允许 Claude 和其他 AI 助手与 YouTube API 交互。该服务器提供用于搜索视频、获取特定视频的详细信息、搜索频道以及获取频道详细信息的工具。
## What is MCP?
Model Context Protocol (MCP) 是由 Anthropic(Claude 的创建者)开发的开放标准,用于将 AI 助手与外部数据源和工具连接起来。它允许像 Claude 这样的模型以标准化方式访问最新的信息并在外部系统中执行操作。
MCP 充当 AI 的“通用桥梁”,为模型提供了一种访问各种内容存储库、业务服务或应用程序的标准化方式。
## Requirements
- Node.js v16 或更高版本
- 一个 YouTube API 密钥(从 Google Developer Console 获取)
## Installation
1. 克隆此存储库:
```bash
git clone https://github.com/Nocodeboy/youtube-mcp-server.git
cd youtube-mcp-server
```
2. 安装依赖项:
```bash
npm install
```
3. 在项目根目录中创建一个 `.env` 文件,并添加您的 YouTube API 密钥:
```
YOUTUBE_API_KEY=your_api_key_here
```
## Execution
要启动服务器,请运行:
```bash
npm start
```
## Integration with Claude Desktop
要将此 MCP 服务器与 Claude Desktop 一起使用,请将以下配置添加到您的 `claude_desktop_config.json` 文件中(通常位于 Windows 上的 `%APPDATA%\Claude\` 或 macOS 上的 `~/Library/Application Support/Claude/` 中):
```json
{
"mcpServers": {
"youtube": {
"command": "node",
"args": ["path/to/youtube-mcp-server/index.js"],
"env": {
"YOUTUBE_API_KEY": "your_api_key_here"
}
}
}
}
```
将 `"path/to/youtube-mcp-server/index.js"` 替换为 `index.js` 文件的绝对路径,并将 `"your_api_key_here"` 替换为您的 YouTube API 密钥。
## Available Tools
### 1. Search Videos
在 YouTube 上搜索视频,基于查询。
```
search_videos
```
参数:
- `query` (string, required): 搜索词
- `maxResults` (number, optional): 最大结果数(介于 1 和 50 之间)
- `pageToken` (string, optional): 用于获取下一页结果的令牌
### 2. Get Video Details
获取关于特定视频的详细信息。
```
get_video_details
```
参数:
- `videoId` (string, required): YouTube 视频 ID
### 3. Get Channel Details
获取关于特定频道的详细信息。
```
get_channel_details
```
参数:
- `channelId` (string, required): YouTube 频道 ID
### 4. Search Channels
在 YouTube 上搜索频道,基于查询。
```
search_channels
```
参数:
- `query` (string, required): 搜索词
- `maxResults` (number, optional): 最大结果数(介于 1 和 50 之间)
- `pageToken` (string, optional): 用于获取下一页结果的令牌
## Available Resources
- `youtube://popular/videos`: YouTube 上当前热门视频列表
## Usage Examples
使用 Claude Desktop,您可以提出如下问题:
- "Search for Python programming videos"
- "Show me details of video with ID dQw4w9WgXcQ"
- "Search for cooking-related channels"
- "Give me information about the GoogleDevelopers channel"
- "What are the most popular videos right now?"
## Getting a YouTube API Key
要获取 YouTube API 密钥:
1. 转到 [Google Developer Console](https://console.developers.google.com/)
2. 创建一个新项目(或选择一个现有项目)
3. 在侧边栏中,选择 "API Library"
4. 搜索 "YouTube Data API v3" 并启用它
5. 在侧边栏中,选择 "Credentials"
6. 点击 "Create credentials" 并选择 "API key"
7. 复制生成的密钥,并在您的 `.env` 文件或 Claude Desktop 配置中使用它
## Troubleshooting
如果遇到错误,请检查:
1. 您是否已使用 `npm install` 安装所有依赖项
2. 您的 YouTube API 密钥是否有效
3. 您是否已在您的 Google 项目中启用 YouTube Data API v3
4. 您是否正在使用 Node.js 16 或更高版本
5. 如果您使用 Claude Desktop,请检查 `%APPDATA%\Claude\logs\` (Windows) 或 `~/Library/Logs/Claude/` (macOS) 中的日志
## Contributions
欢迎贡献。您可以通过以下几种方式进行协作:
1. 报告错误或问题
2. 建议新功能
3. 发送包含改进或修复的 pull requests
4. 改进文档
## Connect & Support
- 在 X (Twitter) 上关注我:[@Nocodeboy](https://x.com/Nocodeboy)
- 如果您觉得这个项目有用并想表达您的支持:
<a href="https://www.buymeacoffee.com/germanhuertas" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
## License
该项目根据 MIT License 获得许可。有关更多详细信息,请参见 LICENSE 文件。