Skip to main content
Glama

yt-mcp

Ein vollständig lokaler MCP-Server (Model Context Protocol), der KI-Assistenten ein tiefgreifendes, multimodales Verständnis von YouTube-Videos verleiht. Keine API-Schlüssel erforderlich. Die gesamte Verarbeitung erfolgt lokal über yt-dlp, OpenAI Whisper, FFmpeg, PySceneDetect und librosa.

Hinweis: Dieses Repository enthält auch einen experimentellen TypeScript-Server (src/), der die Gemini-API verwendet. Dieser Server wird nicht aktiv weiterentwickelt — der lokale Python-Server (server/) ist die primäre Implementierung.


Inhaltsverzeichnis


Related MCP server: yt-analysis-mcp

Funktionsweise

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)

Alle Ergebnisse werden in /tmp/yt-analysis-cache/<video_id>/ zwischengespeichert. Ein erneuter Aufruf derselben URL erfolgt sofort.


Voraussetzungen

# macOS
brew install ffmpeg

# Ubuntu / Debian
sudo apt install ffmpeg

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

Installation

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

Die Whisper-Modellgewichte werden beim ersten Transkriptionsaufruf automatisch heruntergeladen (~75 MB für base, ~1,5 GB für large).


MCP-Integration

MCP-Clients starten den Server als Subprozess — sie aktivieren nicht automatisch Ihre Shell oder Ihr venv. Sie müssen sie direkt mit dem absoluten Pfad auf den Python-Interpreter des venv verweisen.

Finden Sie Ihren Interpreter-Pfad nach der Aktivierung des 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 — hinzufügen zu ~/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"]
    }
  }
}

Ersetzen Sie /path/to/yt-mcp durch den absoluten Pfad zu dem Ort, an dem Sie das Repo geklont haben. Unter Windows befindet sich der Interpreter unter .venv\Scripts\python.exe.


Tools

get_video_transcript

Transkribieren Sie ein YouTube-Video mit OpenAI Whisper (läuft vollständig lokal).

Parameter

Typ

Standard

Beschreibung

youtube_url

string

—

Vollständige YouTube-URL

model_size

string

base

tiny · base · small · medium · large

Antwort:

{
  "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

Extrahieren Sie Keyframes als base64-kodierte JPEGs. Verwendet PySceneDetect für die Szenenerkennung und FFmpeg für die Extraktion.

Parameter

Typ

Standard

Beschreibung

youtube_url

string

—

Vollständige YouTube-URL

strategy

string

scene

scene · interval · both

interval

integer

30

Sekunden zwischen den Frames (für interval oder both Strategien)

Antwort:

{
  "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

Analysieren Sie Audioeigenschaften mithilfe von librosa (läuft lokal).

Parameter

Typ

Standard

Beschreibung

youtube_url

string

—

Vollständige YouTube-URL

segment_duration

integer

30

Größe des Analysefensters in Sekunden

Antwort:

{
  "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

Primäres Tool. Gibt eine vollständige, synchronisierte multimodale Zeitachse zurück — Transkript + Szenengrenzen + Animationserkennung + Audioeigenschaften, alles zeitlich abgestimmt.

Parameter

Typ

Standard

Beschreibung

youtube_url

string

—

Vollständige YouTube-URL

include_frames

boolean

false

Base64-Keyframes pro Segment einbetten

model_size

string

base

Whisper-Modellgröße

Antwort:

{
  "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
      }
    }
  ]
}

Tipp zum Kontextfenster: Rufen Sie get_full_context zuerst mit include_frames=false auf, um die Videostruktur zu verstehen, und rufen Sie dann get_video_frames für bestimmte Zeitstempel von Interesse auf.


Unterstützte URL-Formate

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

Umgebungsvariablen

Variable

Standard

Beschreibung

YT_CACHE_DIR

/tmp/yt-analysis-cache

Cache-Verzeichnis für heruntergeladene Videos und Audio


Entwicklung

# 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'])
"

Testen

Der Python-Server verfügt über eine vollständige Unit-Test-Suite — 164 Tests in 6 Modulen. Alle Tests laufen ohne Netzwerkzugriff oder Model-Downloads; jede externe Abhängigkeit (Whisper, librosa, FFmpeg, PySceneDetect, OpenCV, yt-dlp) wird gemockt.

Testabhängigkeiten installieren

pip install -r requirements-dev.txt

Die gesamte Suite ausführen

python -m pytest

Erwartete Ausgabe: 164 passed in ~4s

Tests für ein bestimmtes Modul ausführen

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

Einen einzelnen Test nach Namen ausführen

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

Live-Rauchtest mit einem echten Video

Das folgende Beispiel verwendet プリマドンナ / 星街すいせい (Hoshimachi Suisei · Suisei Channel, 2:52) — ein japanisches Musikvideo, das jede Ebene der Pipeline nutzt: mehrsprachige Whisper-Transkription, Musikerkennung via librosa HPSS, schnelle Szenenschnitte via PySceneDetect und Animationserkennung via OpenCV Pixel-Diff.

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

Für den vollständigen Testleitfaden — Fixtures, Mock-Muster, Schreiben von Tests für neue Tools — siehe docs/testing.md.


Architektur

Für eine detaillierte Erläuterung des Systemdesigns, der Datenflüsse und wie neue Tools hinzugefügt werden:


TypeScript-Server (archiviert)

Das Verzeichnis src/ enthält einen experimentellen TypeScript-Server, der die Videoanalyse an die Gemini-API delegiert. Er wird nicht aktiv weiterentwickelt und dient nur als Referenz.

Wenn Sie nach einer schnellen cloudbasierten Video-Q&A-Lösung suchen, funktioniert der Ansatz des TypeScript-Servers (direktes Übergeben der YouTube-URL an Gemini) gut für einen schnellen Prototyp — aber der Python-Server ist die einzige Implementierung, die fortlaufend gewartet wird.

Siehe docs/typescript-server.md für die API-Referenz.


Lizenz

MIT

Available Tools

5 tools
ask_about_videoB

Ask a specific question about a YouTube video's content. Returns an answer based on the video.

Inputs: youtube_url (required), question (required).

extract_framesA

Extract frames from a YouTube video at specific timestamps you provide. Use this when you already know the exact timestamps you want (e.g., from get_video_timestamps or video summary).

Inputs: youtube_url (required), timestamps (required), output_dir, resolution.

extract_screenshotsA

Extract key screenshots from a YouTube video at important moments. Uses AI to identify visually significant timestamps, then extracts frames. Returns both base64 images and optionally saves to disk.

Inputs: youtube_url (required), count, output_dir, focus, +1 more.

get_video_timestampsA

Preview mode: Use AI to identify important moments in a YouTube video and return their timestamps WITHOUT extracting frames. Use this to preview what timestamps would be selected before committing to extraction.

Inputs: youtube_url (required), count, focus.

summarize_videoA

Summarize a YouTube video's content. Returns a text summary based on the specified detail level.

Inputs: youtube_url (required), detail_level.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 5 tools

    Disambiguation4/5

    Tools are mostly distinct: ask_about_video and summarize_video both deal with content analysis but differ in question vs. summary. extract_frames and extract_screenshots have clear differences (given timestamps vs. AI-chosen moments). get_video_timestamps is a preview for extraction, reducing overlap. Minor confusion possible between ask_about_video and summarize_video.

    Naming Consistency4/5

    All tool names use verb_* pattern with snake_case (ask_about_video, extract_frames, etc.), which is consistent. Some verbs are compound (ask_about), but the pattern is predictable and clear.

    Tool Count5/5

    5 tools is appropriate for a YouTube MCP: they cover core operations (summarize, Q&A, frame extraction, screenshot extraction, timestamp preview). Not too few or too many.

    Completeness4/5

    The tool set covers main user needs: summarization, Q&A, and visual extraction with a preview step. Missing operations like searching videos or managing playlists, but those may be out of scope. The workflow from preview to extraction is well-supported.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      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
      MIT
    • A
      license
      A
      quality
      D
      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
      13
      MIT