返回市场
深度识别追踪-MCP

深度识别追踪-MCP

作者:DeepSRT48 星标更新:2025-07-14

项目介绍

DeepSRT MCP Server

一个通过集成DeepSRT的API和直接访问YouTube字幕来提供YouTube视频摘要和字幕提取功能的模型上下文协议(MCP)服务器。

TL;DR

{
  "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: 显示带时间戳的字幕

技术架构

核心组件

1. MCP 服务器层

  • 运行时支持:同时支持Node.js和Bun执行
  • 协议处理:模型上下文协议(MCP)请求/响应管理
  • 工具注册get_summaryget_transcript 工具
  • 错误处理:全面的错误管理,带有用户友好的消息

2. 视频处理管道

  • URL 解析器:支持多种YouTube URL格式和直接视频ID
  • InnerTube 集成:无需API密钥直接访问YouTube API
  • 字幕发现:自动检测可用字幕轨道
  • 质量选择:优先选择手动字幕而非自动生成的字幕

3. 字幕处理

  • XML 解析器:处理YouTube的<timedtext>格式
  • 实体解码器:将HTML实体转换为可读文本
  • 时间戳格式化器:将毫秒转换为[MM:SS]格式
  • 内容过滤器:移除音乐符号和空段落

4. 摘要生成

  • DeepSRT 集成:直接调用worker.deepsrt.com的API
  • 多语言支持:支持zh-tw, en, ja和其他语言
  • 模式选择:叙述和项目符号摘要格式
  • 标题翻译:自动将标题翻译为目标语言

关键特性

无需预缓存

  • 对任何带有字幕的YouTube视频立即生效
  • 实时字幕提取和处理
  • 不依赖外部缓存系统

智能字幕选择

  • 优先顺序:手动 > 自动生成 > 任何可用
  • 语言偏好:尊重用户的首选语言
  • 回退策略:优雅地降级到可用选项

强大的错误处理

  • 网络超时管理(30秒超时)
  • 将API错误翻译成用户友好的消息
  • 优雅地处理没有字幕的视频
  • 全面验证输入参数

多格式输出

  • Markdown 格式:带有标题和元数据的富文本
  • 结构化数据:视频信息、时长、作者详情
  • 带时间戳的字幕:精确的时间信息
  • 本地化摘要:用户首选语言的内容

性能特征

  • 快速启动:服务器初始化小于1秒
  • 高效处理:并行API调用进行摘要+标题翻译
  • 内存高效:流式XML解析,不进行大数据缓冲
  • 网络优化:每个视频单次请求获取元数据+字幕

最近更新

v0.1.9 (最新)

  • 修复关键测试逻辑缺陷:测试现在正确验证API响应,而不是检查不存在的success属性
  • 增强错误处理:改进对YouTube API速率限制(HTTP 429)的优雅处理
  • 健壮的测试套件:所有56个测试现在一致通过,并具有适当的错误恢复能力
  • 验证API集成:确认DeepSRT和YouTube API在未被限制时正常工作
  • 多语言支持:验证zh-tw, en, ja摘要生成
  • 生产就绪:测试套件专业处理实际API限制

v0.1

...(省略中间部分,继续翻译)

使用方法

摘要生成

  1. 直接YouTube集成

    • 使用InnerTube API直接从YouTube提取视频信息和字幕
    • 从YouTube的字幕系统中获取字幕内容
    • 将字幕数据发送给DeepSRT API进行摘要生成
  2. 实时处理

    • 无需预缓存 - 对任何带有字幕的视频立即生效
    • 自动选择最佳可用字幕(优先选择手动字幕)
    • 支持多种语言和摘要模式

字幕提取

  1. 直接YouTube访问

    • 使用InnerTube API直接从YouTube的字幕系统中提取字幕
    • 无需预缓存 - 对任何带有字幕的视频立即生效
  2. 字幕选择

    • 自动选择最佳可用字幕(优先选择手动字幕)
    • 支持语言偏好选择
    • 优雅地回退到可用替代选项
  3. 时间戳格式化

    • 提供干净、格式化的字幕,带有时间戳,格式为[MM:SS]
    • 处理手动和自动生成的字幕
    • 包括视频元数据和字幕信息
%%{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: 返回带有元数据的格式化字幕

CLI 使用

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

直接CLI命令(无需安装)

# 提取带时间戳的字幕
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

方案2:全局安装(频繁使用)

# 全局安装以便于访问
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

方案3:为Claude Desktop安装(推荐)

在Claude Desktop配置文件中添加此配置:

  • 在macOS上:~/Library/Application Support/Claude/claude_desktop_config.json
  • 在Windows上:%APPDATA%/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "deepsrt": {
      "type": "stdio",
      "command": "bunx",
      "args": [
        "@deepsrt/deepsrt-mcp@latest",
        "--server"
      ]
    }
  }
}

这种方法:

  • 无需本地安装
  • 始终使用最新版本
  • 自动更新 当你重启Claude时
  • 跨平台兼容性
  • 简单而干净的配置

方案4:为Cline安装

cline_mcp_settings.json中添加此配置:

{
  "mcpServers": {
    "deepsrt": {
      "type": "stdio", 
      "command": "bunx",
      "args": [
        "@deepsrt/deepsrt-mcp@latest",
        "--server"
      ]
    }
  }
}

或者只需在聊天中让Cline为你安装:

"嘿,帮我从https://github.com/DeepSRT/deepsrt-mcp安装这个MCP服务器"

方案5:使用bunx(直接执行)

你可以直接使用bunx运行服务器,无需安装:

# 从项目目录运行
bunx --bun src/index.ts

# 或使用npm脚本
npm run start:bun  # 使用Bun
npm run start:node # 使用Node.js
npm run dev        # 开发模式,使用Bun

使用

MCP 集成

服务器为MCP客户端提供了以下工具:

get_summary

获取YouTube视频的摘要。

参数:

  • videoId(必需):YouTube视频ID
  • lang(可选):语言代码(例如,zh-tw) - 默认为zh-tw
  • mode(可选):摘要模式("narrative"或"bullet") - 默认为narrative

get_transcript

获取带有时间戳的YouTube视频字幕。

参数:

  • videoId(必需):YouTube视频ID或完整的YouTube URL
  • lang(可选):字幕的首选语言代码(例如,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测试:

# 列出