Skip to main content
Glama

Subtitle Analyzer MCP

基于 yt-dlp 的字幕分析 MCP 服务器,支持 YouTube 和 Bilibili 平台。

功能特性

  • 🎬 字幕提取 - 从视频提取字幕(支持手动字幕和自动生成字幕)

  • 🔍 时间戳搜索 - 搜索关键词并定位到具体时间点

  • 📋 视频信息 - 获取视频标题、时长、描述等元信息

  • 🌍 多语言支持 - 支持中文、英文、日文等多种语言字幕

Related MCP server: youtube-mcp

安装

前置要求

  1. Python 3.10+

  2. yt-dlp(系统级安装)

# 安装 yt-dlp
pip install yt-dlp
# 或者使用 brew (macOS)
brew install yt-dlp

安装 MCP

# 克隆或下载项目
cd subtitle-analyzer-mcp

# 安装依赖
pip install -e .

配置

Claude Desktop

编辑配置文件:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "subtitle-analyzer": {
      "command": "python",
      "args": ["-m", "src.server"],
      "cwd": "/path/to/subtitle-analyzer-mcp"
    }
  }
}

或者使用 uv(推荐):

{
  "mcpServers": {
    "subtitle-analyzer": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/subtitle-analyzer-mcp", "python", "-m", "src.server"]
    }
  }
}

Claude Code

# 添加 MCP 服务器
claude mcp add subtitle-analyzer -- python -m src.server --cwd /path/to/subtitle-analyzer-mcp

认证配置

YouTube 和 Bilibili 的部分视频需要登录才能访问。由于 MCP 服务器运行在后台进程中,无法直接访问浏览器 cookies,因此需要预先导出 cookies 文件。

认证优先级

系统按以下优先级查找认证信息:

  1. cookies_file 参数 - 工具调用时直接指定

  2. YT_DLP_COOKIES 环境变量 - 推荐用于 MCP 环境

  3. 浏览器 cookies - 仅本地开发环境可用

导出 Cookies 文件

# 从 Chrome 导出 cookies(需要先登录 YouTube/Bilibili)
# 使用具体视频 URL 比首页更快(避免解析推荐列表)
yt-dlp --cookies-from-browser chrome --cookies ~/.yt-cookies.txt \
  --skip-download "https://www.youtube.com/watch?v=jNQXAC9IVRw"

# 设置文件权限(保护敏感信息)
chmod 600 ~/.yt-cookies.txt

⚠️ 注意: Cookies 会过期(通常 1-2 周),需要定期重新导出。

配置方式

方式 1: 环境变量(推荐)

# 在 shell 配置文件中添加 (~/.zshrc 或 ~/.bashrc)
export YT_DLP_COOKIES=~/.yt-cookies.txt

方式 2: Claude Desktop 配置

{
  "mcpServers": {
    "subtitle-analyzer": {
      "command": "python",
      "args": ["-m", "src.server"],
      "cwd": "/path/to/subtitle-analyzer-mcp",
      "env": {
        "YT_DLP_COOKIES": "/Users/yourname/.yt-cookies.txt"
      }
    }
  }
}

方式 3: Claude Code 配置

# 注册时通过 env 命令注入环境变量
claude mcp add subtitle-analyzer -- \
  env YT_DLP_COOKIES=/path/to/.yt-cookies.txt \
  python -m src.server --cwd /path/to/subtitle-analyzer-mcp

方式 4: 工具调用时指定

在调用工具时直接传入 cookies_file 参数:

{
  "url": "https://www.youtube.com/watch?v=xxxxx",
  "cookies_file": "/path/to/.yt-cookies.txt"
}

使用示例

1. 提取字幕

请提取这个视频的字幕:https://www.youtube.com/watch?v=xxxxx

2. 搜索时间戳

在这个视频中搜索"机器学习"出现的位置:https://www.bilibili.com/video/BVxxxxx

3. 获取视频信息

获取这个视频的基本信息:https://www.youtube.com/watch?v=xxxxx

4. 内容摘要(配合 Claude 使用)

提取这个视频的字幕并生成摘要:https://www.youtube.com/watch?v=xxxxx

工具列表

工具名称

功能

参数

extract_subtitles

提取字幕

url, lang?, format?, cookies_file?

search_timestamp

搜索关键词时间戳

url, keywords, context_lines?, cookies_file?

get_video_info

获取视频信息

url, cookies_file?

list_available_subtitles

列出可用字幕

url, cookies_file?

? 的参数为可选参数

常见问题

Q: MCP 环境下提示认证失败或无法访问?

A: MCP 服务器运行在后台进程,无法直接访问浏览器 cookies。解决方法:

  1. 导出 cookies 文件:

    yt-dlp --cookies-from-browser chrome --cookies ~/.yt-cookies.txt \
      --skip-download "https://www.youtube.com"
  2. 配置 YT_DLP_COOKIES 环境变量(见认证配置章节)

Q: Bilibili 视频无法提取字幕?

A: Bilibili 部分视频需要登录才能访问字幕。请参考认证配置章节设置 cookies。

Q: 提示"无法提取字幕"?

A: 可能原因:

  1. 视频本身没有字幕 - 使用 list_available_subtitles 工具检查

  2. 需要登录认证 - 配置 cookies 文件

  3. 网络连接问题

  4. Cookies 已过期 - 重新导出 cookies 文件

Q: 自动字幕质量不好?

A: 自动生成的字幕(ASR)质量取决于平台算法。建议:

  1. 优先使用手动上传的字幕

  2. 使用 list_available_subtitles 查看可用选项

Q: Cookies 多久需要更新一次?

A: 通常 1-2 周后 cookies 会过期,届时需要重新执行导出命令。如果突然出现认证失败,请先尝试重新导出 cookies。

开发

# 安装开发依赖
pip install -e ".[dev]"

# 运行测试
pytest

# 本地测试服务器
python -m src.server

License

MIT License

Available Tools

4 tools
extract_subtitlesA

从视频 URL 提取字幕。 支持平台:YouTube、Bilibili 返回:完整字幕文本,包含时间戳

认证配置(按优先级):

  1. cookies_file 参数

  2. YT_DLP_COOKIES 环境变量

  3. 浏览器 cookies(仅本地环境)

参数:

  • url: 视频链接 (必填)

  • lang: 首选字幕语言,如 'zh', 'en', 'ja' (可选,默认自动检测)

  • format: 输出格式 'text' (纯文本) 或 'srt' (带时间戳) (可选,默认 'srt')

  • cookies_file: cookies 文件路径,用于认证需要登录的视频 (可选)

ParametersJSON Schema
NameRequiredDescriptionDefault
urlYes视频 URL (YouTube 或 Bilibili)
langNo首选字幕语言代码,如 zh, en, jazh
formatNo输出格式:text (纯文本) 或 srt (带时间戳)srt
cookies_fileNocookies 文件路径,用于认证需要登录的视频

TDQS

A4.1/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It discloses supported platforms, return type (complete subtitle text with timestamps), and authentication fallback hierarchy. It does not mention error handling or rate limits, but sufficiently covers expected behavior for a read operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, platforms, return, authentication, parameters), front-loaded with the main action, and no extraneous information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description adequately explains return values and formatting. It covers input parameters, authentication, and supported platforms. Lacks edge-case handling but is complete for typical use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Despite 100% schema coverage, the description adds value by explicitly stating defaults (lang: auto-detect, format: 'srt') and providing authentication priority context for 'cookies_file'. This goes beyond the schema's parameter descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states '从视频 URL 提取字幕' (extract subtitles from video URL), specifying supported platforms (YouTube, Bilibili) and distinguishing this tool from siblings like 'list_available_subtitles' and 'search_timestamp' by focusing on actual extraction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides authentication configuration priorities, offering some usage context, but does not explicitly state when to use this tool versus siblings (e.g., when to use 'list_available_subtitles' instead). No direct comparison to alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_video_infoA

获取视频的基本信息,包括标题、时长、描述等。

认证配置(按优先级):

  1. cookies_file 参数

  2. YT_DLP_COOKIES 环境变量

  3. 浏览器 cookies(仅本地环境)

参数:

  • url: 视频链接 (必填)

  • cookies_file: cookies 文件路径,用于认证需要登录的视频 (可选)

ParametersJSON Schema
NameRequiredDescriptionDefault
urlYes视频 URL
cookies_fileNocookies 文件路径,用于认证需要登录的视频

TDQS

A3.9/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It discloses authentication behavior (priority order) but does not mention other traits like read-only nature, idempotency, or rate limits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with two paragraphs: purpose and auth priority. It is front-loaded but could be slightly more streamlined.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the description lists returned fields (title, duration, description). It covers both parameters and provides sibling context. Missing error handling details.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so baseline is 3. The description repeats parameter info and adds authentication priority context for cookies_file, but adds little beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool retrieves basic video information (title, duration, description). It distinguishes from sibling tools focused on subtitles and timestamp search.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides authentication configuration priority, guiding the agent on when to use each method. However, it lacks explicit when-not-to-use or comparisons with alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_available_subtitlesA

列出视频可用的所有字幕语言。 用于了解视频有哪些字幕可以提取。

认证配置(按优先级):

  1. cookies_file 参数

  2. YT_DLP_COOKIES 环境变量

  3. 浏览器 cookies(仅本地环境)

参数:

  • url: 视频链接 (必填)

  • cookies_file: cookies 文件路径,用于认证需要登录的视频 (可选)

ParametersJSON Schema
NameRequiredDescriptionDefault
urlYes视频 URL
cookies_fileNocookies 文件路径,用于认证需要登录的视频

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description discloses authentication behavior and required parameters. It does not mention other behavioral traits such as read-only nature, error handling, or rate limits. Adequate but not comprehensive.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and well-structured, with a clear purpose statement followed by authentication configurations and parameter details. No unnecessary information is present.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (2 parameters, no output schema), the description covers the essential aspects: purpose, authentication, and parameter details. It lacks a description of the return format, but the purpose implies a list of languages, which is sufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3. The description adds minimal value beyond the schema, essentially repeating the parameter names and brief descriptions. No additional constraints or formatting details are provided.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's function: listing available subtitle languages for a video. It explicitly distinguishes from sibling tools like extract_subtitles by indicating that this tool is for discovering which subtitles are available.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the primary use case (knowing which subtitles can be extracted) and provides authentication configuration guidance. However, it does not explicitly state when to use this tool versus alternatives like extract_subtitles or get_video_info.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_timestampA

在字幕中搜索关键词,返回匹配的时间戳位置。 用于快速定位视频中提到某个话题的时间点。

认证配置(按优先级):

  1. cookies_file 参数

  2. YT_DLP_COOKIES 环境变量

  3. 浏览器 cookies(仅本地环境)

参数:

  • url: 视频链接 (必填)

  • keywords: 要搜索的关键词列表 (必填)

  • context_lines: 返回匹配位置前后的上下文行数 (可选,默认 2)

  • cookies_file: cookies 文件路径,用于认证需要登录的视频 (可选)

ParametersJSON Schema
NameRequiredDescriptionDefault
urlYes视频 URL
keywordsYes要搜索的关键词列表
cookies_fileNocookies 文件路径,用于认证需要登录的视频
context_linesNo返回匹配位置前后的上下文行数

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must provide behavioral details. It covers authentication methods (cookies_file, env variable, browser cookies) but does not disclose potential errors (e.g., no subtitles found, unsupported video) or output format. This is adequate but not fully comprehensive.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise, with a clear two-line purpose, followed by structured sections for authentication and parameters. Every sentence adds value without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 4 parameters, no output schema, and no annotations, the description explains purpose, authentication, and parameters adequately. However, it omits the return format (e.g., timestamp list with context) and error handling, leaving some gaps for an LLM agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents parameters. The description's parameter list adds minimal extra value beyond restating purposes. The authentication section provides additional context, but baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool searches keywords in subtitles and returns timestamp positions, with a usage context of quickly locating topics in a video. This distinguishes it from sibling tools like extract_subtitles (extracts full subtitles) and list_available_subtitles (lists available subtitle tracks).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description includes a usage context ('用于快速定位视频中提到某个话题的时间点') but does not explicitly state when not to use this tool or mention alternatives. For example, it could clarify that subtitles must be available first (use list_available_subtitles) or that extract_subtitles is for obtaining full text.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 4 tool updatesv0.1.0
    • First observedextract_subtitles
    • First observedget_video_info
    • First observedlist_available_subtitles
    • First observedsearch_timestamp

TDQS

A4/5.0

Scored across 4 tools

Disambiguation2/5

The extract_subtitles tool has a 'get_video_info' parameter that overlaps with the separate get_video_info tool, causing ambiguity. Additionally, extract_subtitles and search_timestamp both involve subtitle content but with different purposes, though this is less problematic.

Naming Consistency5/5

All tool names use consistent snake_case and follow a verb_noun pattern (extract_subtitles, get_video_info, list_available_subtitles, search_timestamp), making them predictable.

Tool Count5/5

With 4 tools covering extraction, listing, info retrieval, and searching, the count is appropriate for the server's subtitle analysis purpose, neither too many nor too few.

Completeness4/5

The set covers core subtitle analysis operations, but missing features like subtitle translation or editing are minor gaps given the 'analyzer' focus. The inclusion of format options and search is good.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    An MCP server that enables users to retrieve YouTube transcripts and perform video or channel searches without requiring Google API keys. It supports transcript chunking and provides tools for detailed video content analysis and channel metadata extraction.
    5
    56 npm
    4
    MIT
  • A
    license
    A
    quality
    C
    maintenance
    An MCP server that enables the extraction of transcripts and detailed metadata from YouTube videos. It allows users to retrieve video information like titles and descriptions, as well as transcripts with optional timestamps and language selection.
    2
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A local MCP server for extracting YouTube video transcripts, metadata, and performing visual analysis using Gemini Vision or local Whisper models. It enables users to process video content through various tools for subtitle retrieval and frame analysis.
    13 npm
    MIT