Skip to main content
Glama

yt-mcp

一个完全本地化的 MCP(模型上下文协议)服务器,为 AI 助手提供对 YouTube 视频的深度多模态感知能力。无需 API 密钥。 所有处理均通过 yt-dlp、OpenAI Whisper、FFmpeg、PySceneDetect 和 librosa 在本地运行。

注意: 本仓库还包含一个使用 Gemini API 的实验性 TypeScript 服务器 (src/)。该服务器目前未处于活跃开发状态 —— Python 本地服务器 (server/) 是主要的实现版本。


目录


Related MCP server: YT-NINJA

工作原理

YouTube URL
    │
    ▼
yt-dlp ──────────────── download video.mp4
    │                   extract audio.wav (16 kHz mono)
    ▼
Whisper ─────────────── timestamped transcript (word-level)
    │
    ▼
PySceneDetect ────────── detect scene-cut timestamps
    │
    ▼
FFmpeg ──────────────── extract keyframe JPEGs at scene cuts
    │
    ▼
OpenCV ──────────────── pixel-diff animation detection
    │
    ▼
librosa ─────────────── energy · tempo · music vs speech
    │
    ▼
timeline.py ─────────── unified JSON timeline (all signals, time-aligned)

所有结果都缓存于 /tmp/yt-analysis-cache/<video_id>/ 中。再次调用相同的 URL 将实现即时响应。


先决条件

# macOS
brew install ffmpeg

# Ubuntu / Debian
sudo apt install ffmpeg

# Verify
ffmpeg -version
python3 --version   # must be 3.10+

安装

git clone https://github.com/yourusername/yt-mcp.git
cd yt-mcp

# Create and activate a virtual environment (recommended)
python3 -m venv .venv
source .venv/bin/activate        # macOS / Linux
# .venv\Scripts\activate         # Windows

pip install -r requirements.txt

Whisper 模型权重会在首次转录调用时自动下载(base 模型约 75 MB,large 模型约 1.5 GB)。


MCP 集成

MCP 客户端将服务器作为子进程启动 —— 它们不会自动激活您的 shell 或 venv。您必须使用绝对路径直接指向 venv 的 Python 解释器。

激活 venv 后查找您的解释器路径:

source .venv/bin/activate
which python   # e.g. /Users/you/repos/yt-mcp/.venv/bin/python

Claude Code:

claude mcp add -s user yt-mcp -- /path/to/yt-mcp/.venv/bin/python /path/to/yt-mcp/server/main.py

Claude Desktop — 添加到 ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "yt-mcp": {
      "command": "/path/to/yt-mcp/.venv/bin/python",
      "args": ["/path/to/yt-mcp/server/main.py"]
    }
  }
}

/path/to/yt-mcp 替换为您克隆仓库的绝对路径。 在 Windows 上,解释器位于 .venv\Scripts\python.exe


工具

get_video_transcript

使用 OpenAI Whisper 转录 YouTube 视频(完全在本地运行)。

参数

类型

默认值

描述

youtube_url

string

完整的 YouTube URL

model_size

string

base

tiny · base · small · medium · large

响应:

{
  "title": "Video Title",
  "duration": 847,
  "language": "en",
  "full_text": "Welcome to this video...",
  "segments": [
    {
      "t_start": 0.0,
      "t_end": 4.5,
      "text": "Welcome to this video.",
      "words": [{ "word": "Welcome", "start": 0.0, "end": 0.6 }]
    }
  ]
}

get_video_frames

提取关键帧作为 base64 编码的 JPEG。使用 PySceneDetect 进行场景检测,使用 FFmpeg 进行提取。

参数

类型

默认值

描述

youtube_url

string

完整的 YouTube URL

strategy

string

scene

scene · interval · both

interval

integer

30

帧之间的秒数(用于 intervalboth 策略)

响应:

{
  "title": "Video Title",
  "duration": 847,
  "duration_formatted": "14:07",
  "frame_count": 12,
  "strategy": "scene",
  "frames": [
    {
      "t": 0.0,
      "t_formatted": "0:00",
      "keyframe": "<base64 JPEG>",
      "scene_change": false,
      "animation_detected": false
    }
  ],
  "summary": [ /* same list without keyframe bytes — for quick review */ ]
}

get_audio_features

使用 librosa 分析音频特征(在本地运行)。

参数

类型

默认值

描述

youtube_url

string

完整的 YouTube URL

segment_duration

integer

30

分析窗口大小(秒)

响应:

{
  "title": "Video Title",
  "duration": 847,
  "segment_duration": 30,
  "segments": [
    {
      "t_start": 0.0,
      "t_end": 30.0,
      "energy": "medium",
      "music": false,
      "tempo_bpm": 95.0,
      "rms_db": -22.1
    }
  ]
}

get_full_context

核心工具。 返回一个完整、同步的多模态时间轴 —— 转录内容 + 场景边界 + 动画检测 + 音频特征,所有内容均已按时间对齐。

参数

类型

默认值

描述

youtube_url

string

完整的 YouTube URL

include_frames

boolean

false

在每个片段中嵌入 base64 关键帧

model_size

string

base

Whisper 模型大小

响应:

{
  "title": "How Transformers Work",
  "channel": "AI Explained",
  "duration": 847,
  "duration_formatted": "14:07",
  "language": "en",
  "description": "In this video...",
  "segments": [
    {
      "t_start": 0.0,
      "t_end": 12.0,
      "transcript": "Welcome to this video on transformers...",
      "keyframe": null,
      "scene_change": false,
      "animation_detected": false,
      "audio": {
        "energy": "low",
        "speech_rate": "normal",
        "music": true,
        "tempo_bpm": 0.0,
        "rms_db": -28.4
      }
    }
  ]
}

上下文窗口提示: 先调用 get_full_context 并设置 include_frames=false 以了解视频结构,然后针对感兴趣的特定时间戳调用 get_video_frames


支持的 URL 格式

https://www.youtube.com/watch?v=VIDEO_ID
https://youtu.be/VIDEO_ID
https://youtube.com/shorts/VIDEO_ID

环境变量

变量

默认值

描述

YT_CACHE_DIR

/tmp/yt-analysis-cache

用于下载视频和音频的缓存目录


开发

# Activate the venv first
source .venv/bin/activate

# Run the server directly (stdio mode — same as MCP clients use)
python server/main.py

# Quick smoke test
python -c "
from server.utils.downloader import VideoDownloader
from server.tools.transcript import get_transcript
d = VideoDownloader()
vp, ap, info = d.download('https://www.youtube.com/watch?v=jNQXAC9IVRw')
print(get_transcript(ap)['language'])
"

测试

Python 服务器拥有完整的单元测试套件 —— 涵盖 6 个模块的 164 个测试。所有测试均在没有网络访问或模型下载的情况下运行;每个外部依赖项(Whisper、librosa、FFmpeg、PySceneDetect、OpenCV、yt-dlp)均已模拟。

安装测试依赖

pip install -r requirements-dev.txt

运行完整套件

python -m pytest

预期输出:164 passed in ~4s

运行特定模块的测试

python -m pytest tests/test_downloader.py   # VideoDownloader + VideoInfo
python -m pytest tests/test_transcript.py   # Whisper wrapper + range helpers
python -m pytest tests/test_frames.py       # FFmpeg, PySceneDetect, OpenCV
python -m pytest tests/test_audio.py        # librosa AudioAnalyzer
python -m pytest tests/test_timeline.py     # build_timeline + speech rate
python -m pytest tests/test_main.py         # all 4 MCP tool handlers

按名称运行单个测试

python -m pytest tests/test_timeline.py::TestBuildTimeline::test_rapid_cuts_below_min_merged -v

针对真实视频的实时冒烟测试

下面的示例使用了 プリマドンナ / 星街すいせい (星街彗星 · Suisei Channel, 2:52) —— 这是一个日本音乐视频,它测试了管道的每一层:多语言 Whisper 转录、通过 librosa HPSS 进行音乐检测、通过 PySceneDetect 进行快速场景切换,以及通过 OpenCV 像素差异进行动画检测。

from server.utils.downloader import VideoDownloader
from server.tools.transcript import get_transcript
from server.tools.audio import AudioAnalyzer
from server.tools.frames import detect_scene_timestamps

URL = "https://www.youtube.com/watch?v=M1GYqy0tHV0"

d = VideoDownloader()
video_path, audio_path, info = d.download(URL)

print(f"Title:    {info.title}")        # プリマドンナ / 星街すいせい(official)
print(f"Duration: {info.duration:.0f}s")  # 172

transcript = get_transcript(audio_path, model_size="base")
print(f"Language: {transcript['language']}")  # ja

cuts = detect_scene_timestamps(video_path)
print(f"Scene cuts detected: {len(cuts)}")    # typically 30–60 for a music video

analyzer = AudioAnalyzer(audio_path)
seg = analyzer.analyze_segment(0, 30)
print(f"First 30s — energy: {seg['energy']}, music: {seg['music']}")
# energy: 'medium' or 'high', music: True

有关完整的测试指南(固定装置、模拟模式、为新工具编写测试),请参阅 docs/testing.md


架构

有关系统设计、数据流以及如何添加新工具的详细说明:


TypeScript 服务器(已归档)

src/ 目录包含一个实验性的 TypeScript 服务器,它将视频分析委托给 Gemini API。它目前未处于活跃开发状态,仅供参考。

如果您正在寻找基于云的快速视频问答,TypeScript 服务器的方法(直接将 YouTube URL 传递给 Gemini)非常适合快速原型设计 —— 但 Python 服务器是唯一将获得持续维护的实现。

请参阅 docs/typescript-server.md 获取其 API 参考。


许可证

MIT

Install Server
A
license - permissive license
A
quality
B
maintenance

Maintenance

Maintainers
41dResponse time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    B
    quality
    D
    maintenance
    Enables AI-powered YouTube video analysis including transcript management, video summaries, chapter generation, keyword extraction, and playback control. Supports searching videos, retrieving channel/playlist information, and translating transcripts using Google Gemini AI.
    14
  • F
    license
    A
    quality
    C
    maintenance
    Enables analysis of YouTube videos using the Gemini API to generate summaries and answer specific questions via direct URLs. It supports standard videos and shorts, allowing users to interact with video content without requiring manual downloads.
    5
    4

View all related MCP servers

Related MCP Connectors

  • AI-powered YouTube to flashcards with spaced repetition and Anki export

  • Provide token-optimized, structured YouTube data to enhance your LLM applications. Access efficien…

  • Multimodal video analysis MCP — transcription, vision, and OCR for any video URL.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PakmanGames/yt-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server