一个通过集成DeepSRT的API和直接访问YouTube字幕来提供YouTube视频摘要和字幕提取功能的模型上下文协议(MCP)服务器。
{
"mcpServers": {
"deepsrt": {
"type": "stdio",
"command": "bunx",
"args": [
"@deepsrt/deepsrt-mcp@latest",
"--server"
]
}
}
}
graph TB
subgraph "MCP 客户端"
Client[Claude Desktop / Cline]
end
subgraph "DeepSRT MCP 服务器"
Server[MCP 服务器]
SummaryTool[get_summary]
TranscriptTool[get_transcript]
Server --> SummaryTool
Server --> TranscriptTool
end
subgraph "外部API"
YouTube[YouTube InnerTube API]
DeepSRT[DeepSRT Worker API]
Captions[YouTube 字幕 API]
end
Client --> Server
SummaryTool --> YouTube
SummaryTool --> DeepSRT
TranscriptTool --> YouTube
TranscriptTool --> Captions
sequenceDiagram
participant User
participant MCP as MCP 客户端
participant Server as DeepSRT MCP 服务器
participant YouTube as YouTube InnerTube API
participant DeepSRT as DeepSRT Worker API
participant Captions as YouTube 字幕 API
Note over User,Captions: 摘要生成流程
User->>MCP: 请求视频摘要
MCP->>Server: get_summary(videoId, lang, mode)
Server->>Server: 从URL中提取视频ID
Server->>YouTube: POST /youtubei/v1/player
Note right of YouTube: 获取视频元数据<br/>和字幕轨道
YouTube-->>Server: 视频详情 + 字幕轨道
Server->>Server: 选择最佳字幕轨道<br/>(手动 > 自动生成)
Server->>Server: 从字幕URL中提取字幕参数
par 摘要请求
Server->>DeepSRT: GET /transcript2?action=summarize
Note right of DeepSRT: X-Transcript-Arg 头部<br/>包含字幕URL参数
DeepSRT-->>Server: 生成的摘要
and 标题翻译
Server->>DeepSRT: GET /transcript2?action=translate
DeepSRT-->>Server: 翻译后的标题
end
Server->>Server: 格式化markdown响应<br/>包含元数据 + 摘要
Server-->>MCP: 格式化的摘要响应
MCP-->>User: 显示摘要
Note over User,Captions: 字幕提取流程
User->>MCP: 请求视频字幕
MCP->>Server: get_transcript(videoId, lang)
Server->>Server: 从URL中提取视频ID
Server->>YouTube: POST /youtubei/v1/player
YouTube-->>Server: 视频详情 + 字幕轨道
Server->>Server: 选择最佳字幕轨道<br/>用于首选语言
Server->>Captions: GET 从baseUrl获取字幕XML
Captions-->>Server: 原始XML字幕
Server->>Server: 解析XML字幕<br/>- 提取时间戳<br/>- 解码HTML实体<br/>- 格式化文本
Server->>Server: 生成带时间戳的markdown响应
Server-->>MCP: 格式化的字幕
MCP-->>User: 显示带时间戳的字幕
get_summary 和 get_transcript 工具<timedtext>格式[MM:SS]格式worker.deepsrt.com的APIsuccess属性...(省略中间部分,继续翻译)
直接YouTube集成
实时处理
直接YouTube访问
字幕选择
时间戳格式化
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#2496ED', 'secondaryColor': '#38B2AC', 'tertiaryColor': '#1F2937', 'mainBkg': '#111827', 'textColor': '#E5E7EB', 'lineColor': '#4B5563', 'noteTextColor': '#E5E7EB'}}}%%
sequenceDiagram
participant User
participant MCP as MCP 客户端
participant YouTube as YouTube API
participant DeepSRT as DeepSRT API
Note over User,DeepSRT: 摘要生成流程(直接处理)
User->>MCP: 请求视频摘要
MCP->>YouTube: 通过InnerTube API获取视频信息及字幕
YouTube-->>MCP: 返回视频详情及字幕轨道
MCP->>YouTube: 从字幕URL中获取原始字幕内容
YouTube-->>MCP: 返回原始字幕内容
MCP->>DeepSRT: 发送字幕+元数据进行摘要生成
DeepSRT-->>MCP: 返回生成的摘要
MCP-->>User: 返回格式化的摘要
Note over User,DeepSRT: 字幕提取流程(直接)
User->>MCP: 请求视频字幕
MCP->>YouTube: 通过InnerTube API获取视频信息及字幕
YouTube-->>MCP: 返回视频详情及字幕轨道
MCP->>YouTube: 从字幕URL中获取原始字幕内容
YouTube-->>MCP: 返回原始字幕内容
MCP->>MCP: 解析并格式化字幕,带有时间戳
MCP-->>User: 返回带有元数据的格式化字幕
DeepSRT MCP服务器提供了一个统一接口,处理MCP服务器模式和CLI命令。
# MCP 服务器模式(默认 - 适用于Claude Desktop/Cline)
bunx @deepsrt/deepsrt-mcp # 在stdio上启动MCP服务器
bunx @deepsrt/deepsrt-mcp --server # 显式的服务器模式
# CLI 命令(直接使用)
bunx @deepsrt/deepsrt-mcp get-transcript <video-url> [options]
bunx @deepsrt/deepsrt-mcp get-summary <video-url> [options]
# 帮助
bunx @deepsrt/deepsrt-mcp --help
# 提取带时间戳的字幕
bunx @deepsrt/deepsrt-mcp get-transcript https://www.youtube.com/watch?v=dQw4w9WgXcQ
bunx @deepsrt/deepsrt-mcp get-transcript dQw4w9WgXcQ --lang=en
# 生成视频摘要
bunx @deepsrt/deepsrt-mcp get-summary dQw4w9WgXcQ --lang=zh-tw --mode=bullet
bunx @deepsrt/deepsrt-m
...(省略中间部分,继续翻译)
## 安装
### 方案1:直接使用bunx(推荐 - 无需安装)
直接使用统一接口,无需任何安装:
```bash
# MCP 服务器模式(适用于Claude Desktop/Cline)
bunx @deepsrt/deepsrt-mcp # 默认:启动MCP服务器
bunx @deepsrt/deepsrt-mcp --server # 显式的服务器模式
# CLI 命令(直接使用)
bunx @deepsrt/deepsrt-mcp get-transcript https://www.youtube.com/watch?v=dQw4w9WgXcQ
bunx @deepsrt/deepsrt-mcp get-summary dQw4w9WgXcQ --lang=zh-tw --mode=bullet
# 自动使用最新版本
bunx @deepsrt/deepsrt-mcp@latest get-transcript dQw4w9WgXcQ --lang=en
# 全局安装以便于访问
npm install -g @deepsrt/deepsrt-mcp
# 然后使用更短的命令直接使用
deepsrt-mcp get-transcript https://www.youtube.com/watch?v=dQw4w9WgXcQ
deepsrt-mcp get-summary dQw4w9WgXcQ --lang zh-tw --mode bullet
在Claude Desktop配置文件中添加此配置:
~/Library/Application Support/Claude/claude_desktop_config.json{
"mcpServers": {
"deepsrt": {
"type": "stdio",
"command": "bunx",
"args": [
"@deepsrt/deepsrt-mcp@latest",
"--server"
]
}
}
}
这种方法:
在cline_mcp_settings.json中添加此配置:
{
"mcpServers": {
"deepsrt": {
"type": "stdio",
"command": "bunx",
"args": [
"@deepsrt/deepsrt-mcp@latest",
"--server"
]
}
}
}
或者只需在聊天中让Cline为你安装:
你可以直接使用bunx运行服务器,无需安装:
# 从项目目录运行
bunx --bun src/index.ts
# 或使用npm脚本
npm run start:bun # 使用Bun
npm run start:node # 使用Node.js
npm run dev # 开发模式,使用Bun
服务器为MCP客户端提供了以下工具:
获取YouTube视频的摘要。
参数:
videoId(必需):YouTube视频IDlang(可选):语言代码(例如,zh-tw) - 默认为zh-twmode(可选):摘要模式("narrative"或"bullet") - 默认为narrative获取带有时间戳的YouTube视频字幕。
参数:
videoId(必需):YouTube视频ID或完整的YouTube URLlang(可选):字幕的首选语言代码(例如,en, zh-tw) - 默认为en使用Claude Desktop:
// 获取视频摘要
const summaryResult = await mcp.use_tool("deepsrt", "get_summary", {
videoId: "dQw4w9WgXcQ",
lang: "zh-tw",
mode: "narrative"
});
// 获取视频字幕
const transcriptResult = await mcp.use_tool("deepsrt", "get_transcript", {
videoId: "dQw4w9WgXcQ",
lang: "en"
});
使用Cline:
// 获取视频摘要
const summaryResult = await mcp.use_tool("deepsrt", "get_summary", {
videoId: "dQw4w9WgXcQ",
lang: "zh-tw",
mode: "bullet"
});
// 获取视频字幕
const transcriptResult = await mcp.use_tool("deepsrt", "get_transcript", {
videoId: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
lang: "en"
});
安装依赖项:
npm install
# 运行单元测试(快速,无网络调用)
npm test
# 仅运行单元测试
npm run test:unit
# 运行网络测试(需要互联网,可能较慢)
npm run test:network
# 运行包括网络测试的所有测试
npm run test:all
# 在监视模式下运行测试
npm run test:watch
# 使用CI报告器运行测试(用于CI/CD)
npm run test:ci
测试类型:
src/index.test.ts, src/integration.test.ts) - 快速测试,使用模拟数据src/transcript.test.ts, src/e2e.test.ts) - 真实的YouTube API集成测试查看examples/目录中的参考实现:
examples/standalone-summarizer.ts - 展示直接API使用模式的独立脚本使用Bun(推荐用于开发 - 启动更快):
# 开发模式(直接运行TypeScript)
npm run dev
# 或
bun src/index.ts
# 使用npm脚本
npm run start:bun
使用Node.js(生产):
# 先构建
npm run build
# 然后运行
npm run start:node
# 或
node build/index.js
你可以使用MCP检查器测试服务器:
npm run inspector
或者手动使用JSON-RPC测试:
# 列出