YouTube数据MCP服务器
用于提取YouTube视频转录、评论和搜索结果的模型上下文协议(MCP)服务器。支持两者 工作室 和 流式HTTP 运输。
特性
getTranscript-提取带有可选时间戳的字幕/转录本getVideoInfo-获取视频元数据(标题、视图、评论数)getComments-通过分页和排序获取评论getCommentReplies-获取对特定评论的回复searchYoutube-搜索视频、频道和播放列表
v2.0中的新增功能
- 双重运输:Stdio(默认)+StreamableHTTP用于web集成
- 可靠的成绩单:已更换
youtube-transcript随着youtube-caption-extractor(机器人检测旁路,无服务器支持) - 时间戳支持:每个转录片段的可选开始时间和持续时间
- 模块化架构:关注点(配置、类型、服务、工具)的清晰分离
- MCP SDK v1.25.2:最新SDK,稳定性得到提升
需求
- Node.js 18+
- SerpAPI密钥(用于搜索、评论、视频信息)
安装
git clone https://github.com/diasm3/serpapi-youtube-mcp-server.git
cd serpapi-youtube-mcp-server
npm install配置
创建一个 .env 文件:
SERPAPI_KEY=your_serpapi_key_here
PORT=3000 # optional, for HTTP mode获取您的SerpAPI密钥 蛇网.
运行服务器
# Build
npm run build
# Stdio mode (default) - for Claude Desktop, Cursor, etc.
npm start
# HTTP mode - for web applications
npm start -- --http
# or
MCP_TRANSPORT=http npm startHTTP端点
在HTTP模式下运行时:
GET /health-健康检查POST /mcp-MCP请求处理程序
MCP客户端配置
克劳德桌面/光标
{
"mcpServers": {
"youtube-data": {
"command": "node",
"args": ["/path/to/serpapi-youtube-mcp-server/build/index.js"],
"env": {
"SERPAPI_KEY": "your_serpapi_key_here"
}
}
}
}使用npx
{
"mcpServers": {
"youtube-data": {
"command": "npx",
"args": ["-y", "youtube-data-mcp"],
"env": {
"SERPAPI_KEY": "your_serpapi_key_here"
}
}
}
}API工具
getTranscript
从YouTube视频中提取文字/字幕。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
url | string | 是 | YouTube URL或视频ID |
lang | string | 否 | 语言代码(默认值:'en') |
includeTimestamps | boolean | 否 | 包括每个分段的开始/持续时间 |
Get the Korean transcript for https://youtube.com/watch?v=xxxxx with timestamps获取视频信息
使用SerpAPI获取视频元数据。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
url | string | 是 | YouTube URL或视频ID |
返回:标题、视图、发布日期、频道、评论数、分页标记
获取评论
获取带分页的视频评论。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
url | string | 条件 | 首页必填 |
limit | number | No | 最大评论数(默认值:100) |
sort | string | 否 | “相关性”或“时间” |
pageToken | string | 否 | 用于分页 |
获取评论回复
获取对特定评论的回复。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
pageToken | string | 是 | repliesToken 来自评论 |
搜索YouTube
在YouTube上搜索视频、频道、播放列表。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
query | string | 是 | 搜索查询 |
limit | number | No | 最大结果数(默认值:10) |
gl | string | 否 | 国家代码(us、kr、jp) |
hl | string | 否 | 语言代码(en、ko、ja) |
sp | string | 否 | 筛选参数 |
pageToken | string | 否 | 用于分页 |
项目结构
src/
├── index.ts # Server entry (Stdio + HTTP)
├── config/ # Environment configuration
├── types/ # Zod schemas + TypeScript types
├── services/
│ ├── serpapi.ts # SerpAPI integration
│ └── youtube.ts # Transcript extraction
├── tools/ # MCP tool definitions
└── utils/ # Helper functions故障排除
成绩单不可用
- 某些视频未启用字幕
- 尝试不同的语言代码(en、ko、ja等)
- 自动生成的字幕可能并非适用于所有视频
SerpAPI错误
- 验证您的API密钥是否有效
- 检查您的SerpAPI配额/限制
- 确保视频可供公众访问
HTTP模式未启动
- 检查端口是否已在使用中
- 验证是否设置了环境变量
许可证
麻省理工学院
