YouTube Video Analyzer MCP
An MCP stdio server that uses Google Gemini to analyze public YouTube videos by attaching the YouTube URL as video input instead of only mentioning it in prompt text.
Features
analyze_youtube_videofor direct short-video or manual-clip analysisanalyze_long_youtube_videofor long videos with Files API-first long-video handling and URL-chunk fallbackcontinue_long_video_analysisfor follow-up questions on an uploaded long-video session- Automatic YouTube URL normalization for
watch,live,shorts,embed, andyoutu.belinks - Structured JSON output in the video's detected dominant language by default
- MCP-native
structuredContentresponses with JSON text preserved incontentfor compatibility - Structured stderr logging with request correlation IDs for long-running tool diagnostics
- Safe MCP error payloads with machine-readable
code,stage, and strategy metadata - Optional custom JSON schema support for final outputs
youtube-video-analyzer-mcp setupfor saving user-level config when using the npm package directly
Project layout
src/index.ts:stdiobootstrap onlysrc/server.ts: MCP server creation, request logging, andregisterTool(...)wiringsrc/lib/schemas.ts: input and output schemas plus JSON helperssrc/lib/youtube.ts: YouTube URL normalization andyt-dlphelperssrc/lib/gemini.ts: Gemini request builders, uploads, token budgeting, caching, and retry handlingsrc/lib/analysis.ts: short-video, long-video, and follow-up orchestration with in-memory sessionssrc/lib/logger.ts: structured stderr logging helperssrc/lib/errors.ts: safe diagnostic error types and retryability heuristics
Prerequisites
- Node.js 20+
- A Gemini API key
- A public YouTube video URL
yt-dlpinstalled locally for the long-video tool, either as a binary or viapython -m yt_dlpffmpegif youryt-dlpsetup needs it to merge adaptive video/audio downloads
Setup
-
Install dependencies:
npm install -
Copy the example environment file and add your API key:
copy .env.example .env -
Optionally point to a custom
yt-dlpbinary if it is not on yourPATH. -
Build the server:
npm run build
Running locally
For normal local development:
npm run dev
For the built package entrypoint behavior:
npm run build
npm start
Using the npm package
Run it without installing globally:
npx -y @ludylops/youtube-video-analyzer-mcp
Or install it globally:
npm install -g @ludylops/youtube-video-analyzer-mcp
youtube-video-analyzer-mcp
To save your API key and optional defaults in a user config file:
youtube-video-analyzer-mcp setup
The setup command writes a config file in the standard user config location:
- Windows:
%APPDATA%/youtube-video-analyzer-mcp/config.json - macOS/Linux:
~/.config/youtube-video-analyzer-mcp/config.json
Config precedence is:
- Explicit environment variables
- Local
.env - User config file created by
setup - Built-in defaults
MCP configuration example
Replace the example path below with the absolute path to your own built dist/index.js file.
{
"mcpServers": {
"youtube-analyzer": {
"command": "npx",
"args": ["-y", "@ludylops/youtube-video-analyzer-mcp"],
"env": {
"GEMINI_API_KEY": "your_gemini_api_key_here",
"GEMINI_MODEL": "gemini-2.5-pro",
"YT_DLP_PATH": "yt-dlp"
}
}
}
}
If you prefer a locally built checkout instead of npm, use node plus the absolute path to your own built dist/index.js.
Tool behavior
analyze_youtube_video
Inputs:
youtubeUrl: public YouTube URL inwatch,live,shorts,embed, oryoutu.beformanalysisPrompt: optional analysis focusstartOffsetSeconds: optional clip startendOffsetSeconds: optional clip endmodel: optional Gemini model overrideresponseSchemaJson: optional JSON schema string for custom structured output
Success output:
content[0].text: pretty-printed JSON for compatibility with text-only clientsstructuredContent: the same parsed object validated against the tool output schema
analyze_long_youtube_video
Inputs:
youtubeUrl: public YouTube URLanalysisPrompt: optional global analysis focuschunkModel: optional chunk-analysis model, defaultgemini-2.5-flashfinalModel: optional final synthesis model, defaultgemini-2.5-prostrategy: optionalauto,url_chunks, oruploaded_filepreferCache: optional boolean, defaulttrueresponseSchemaJson: optional JSON schema string for the final structured output
Strategy policy:
auto: prefers uploaded-file analysis first, then falls back to URL chunks if neededuploaded_file: deterministic Files API path for long videosurl_chunks: explicit preview-oriented path for public YouTube videos that avoids local download/upload work
Production guidance:
- Uploaded-file analysis is the recommended default for long videos because Gemini Files API is the documented path for larger and reusable media.
- URL chunking can still be useful when you want to avoid local download/upload work and the source video is public, but it depends on preview YouTube URL support and is not the primary production path.
Behavior:
- Uses
yt-dlpto resolve duration metadata for long videos - In
auto, prefers uploaded-file analysis before trying direct URL chunks - Returns a
sessionIdwhen an uploaded-file session is created successfully - Emits structured stderr logs for strategy choice, chunk progress, retries, fallbacks, and failures
- Returns
structuredContenton success andisError: trueon handled runtime failures
Handled failure output:
error.toolerror.requestIderror.codeerror.stageerror.messageerror.retryableerror.strategyRequestederror.strategyAttemptederror.causeMessageerror.details
continue_long_video_analysis
Inputs:
sessionId: session returned byanalyze_long_youtube_videoanalysisPrompt: follow-up promptmodel: optional model overrideresponseSchemaJson: optional JSON schema string for structured follow-up output
Notes
- The server uses the current MCP
registerTool(...)API and remains intentionallystdio-only in this project. - Streamable HTTP is the modern remote transport, but adding it is out of scope for this server.
- The server normalizes supported YouTube URL formats into a canonical
https://www.youtube.com/watch?v=...URL before sending the request to Gemini. - If
YT_DLP_PATHis not set, the server will trypython -m yt_dlpautomatically. - Cache reuse is an optimization for repeated analysis on the same uploaded asset; it does not increase the effective model context window.
- Sessions are stored in memory only and disappear if the MCP server restarts.