summarize_transcript
Fetch a YouTube video transcript and prepare it for AI summarization. Supports custom prompts, timestamps, metadata, and multiple languages.
Instructions
Fetch a YouTube video's transcript and return it with summarization instructions.
The LLM client should use the returned instructions and transcript to produce a summary. The output is structured into clearly-labeled sections so a human can review the prompt before letting the LLM act on it.
Args: url: YouTube video URL or video ID prompt: Custom summarization instructions. If omitted, a default summary prompt is used. languages: Preferred languages in priority order (e.g. ["en", "de"]). Defaults to English. include_timestamps: When True, prefix each transcript line with [HH:MM:SS]. include_metadata: When True (default), include a [VIDEO] block with title, channel, published date, duration, views, and description.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| prompt | No | ||
| languages | No | ||
| include_timestamps | No | ||
| include_metadata | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- main.py:306-364 (handler)The main handler function for the summarize_transcript MCP tool. It extracts the video ID, fetches the transcript, and returns it structured with instructions, metadata, and transcript sections for LLM summarization.
def summarize_transcript( url: str, prompt: str | None = None, languages: list[str] | None = None, include_timestamps: bool = False, include_metadata: bool = True, ) -> str: """Fetch a YouTube video's transcript and return it with summarization instructions. The LLM client should use the returned instructions and transcript to produce a summary. The output is structured into clearly-labeled sections so a human can review the prompt before letting the LLM act on it. Args: url: YouTube video URL or video ID prompt: Custom summarization instructions. If omitted, a default summary prompt is used. languages: Preferred languages in priority order (e.g. ["en", "de"]). Defaults to English. include_timestamps: When True, prefix each transcript line with [HH:MM:SS]. include_metadata: When True (default), include a [VIDEO] block with title, channel, published date, duration, views, and description. """ try: video_id = extract_video_id(url) except ValueError as e: return f"Error: {e}" langs = languages or ["en"] try: transcript = api.fetch(video_id, languages=langs) if include_timestamps: text = _format_transcript_with_timestamps(transcript) else: text = TextFormatter().format_transcript(transcript) except Exception as e: return _handle_transcript_error(e, video_id, langs) instructions = prompt or DEFAULT_SUMMARY_PROMPT prompt_source = "user-supplied" if prompt else "default" language = transcript.language language_code = transcript.language_code is_generated = transcript.is_generated sections = [ f"[INSTRUCTIONS]\n{instructions}", f"[PROMPT_SOURCE]\n{prompt_source}", ] if include_metadata: meta = _fetch_metadata(video_id) sections.append(_format_metadata_block(meta, header="VIDEO")) sections.append( f"[METADATA]\n" f"Video ID: {video_id}\n" f"Language: {language} ({language_code})\n" f"Type: {'auto-generated' if is_generated else 'manual'}" ) sections.append(f"[TRANSCRIPT]\n{text}") return "\n\n".join(sections) - main.py:305-305 (registration)The @mcp.tool() decorator registers summarize_transcript as an MCP tool on the FastMCP server instance.
@mcp.tool() - main.py:25-28 (helper)Default summary prompt used when no custom prompt is provided by the user.
DEFAULT_SUMMARY_PROMPT = ( "Summarize the following YouTube video transcript. " "Provide a concise overview of the main topics, key points, and conclusions." ) - main.py:115-119 (helper)Helper function used to format transcript lines with timestamps (called when include_timestamps=True).
def _format_transcript_with_timestamps(transcript) -> str: """Render a FetchedTranscript as text with an [HH:MM:SS] prefix on each line.""" return "\n".join( f"{_format_timestamp(snippet.start)} {snippet.text}" for snippet in transcript )