Skip to main content
Glama

summarize_transcript

Extract transcripts from YouTube videos and generate summaries using custom instructions or default prompts. Supports multiple languages and transcript formats for flexible content analysis.

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.

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
promptNo
languagesNo

Implementation Reference

  • main.py:123-162 (handler)
    The summarize_transcript tool handler decorated with @mcp.tool(). It fetches a YouTube video transcript, extracts metadata (language, type, video ID), and returns formatted output with instructions, metadata, and the transcript text for the LLM to summarize.
    @mcp.tool() def summarize_transcript( url: str, prompt: str | None = None, languages: list[str] | None = None, ) -> 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. 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. """ 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) text = TextFormatter().format_transcript(transcript) instructions = prompt or DEFAULT_SUMMARY_PROMPT language = transcript.language language_code = transcript.language_code is_generated = transcript.is_generated return ( f"[INSTRUCTIONS]\n{instructions}\n\n" f"[METADATA]\n" f"Video ID: {video_id}\n" f"Language: {language} ({language_code})\n" f"Type: {'auto-generated' if is_generated else 'manual'}\n\n" f"[TRANSCRIPT]\n{text}" ) except Exception as e: return _handle_transcript_error(e, video_id, langs)
  • main.py:123-123 (registration)
    Registration of the summarize_transcript tool using the @mcp.tool() decorator from FastMCP framework.
    @mcp.tool()
  • main.py:25-28 (helper)
    DEFAULT_SUMMARY_PROMPT constant - default summarization instructions used when no custom prompt is provided to the summarize_transcript tool.
    DEFAULT_SUMMARY_PROMPT = ( "Summarize the following YouTube video transcript. " "Provide a concise overview of the main topics, key points, and conclusions." )
  • main.py:37-47 (helper)
    extract_video_id helper function - parses YouTube video URLs or bare IDs to extract the 11-character video ID used by summarize_transcript.
    def extract_video_id(url_or_id: str) -> str: """Extract a YouTube video ID from a URL or bare ID string.""" url_or_id = url_or_id.strip() if BARE_ID_REGEX.match(url_or_id): return url_or_id match = VIDEO_ID_REGEX.search(url_or_id) if match: return match.group(1) raise ValueError( f"Could not extract a YouTube video ID from: {url_or_id}" )
  • main.py:58-88 (helper)
    _handle_transcript_error helper function - converts youtube_transcript_api exceptions into user-friendly error messages used by summarize_transcript.
    def _handle_transcript_error(e: Exception, video_id: str, languages: list[str] | None = None) -> str: """Convert youtube_transcript_api exceptions into user-friendly error strings.""" from youtube_transcript_api import ( AgeRestricted, InvalidVideoId, IpBlocked, NoTranscriptFound, RequestBlocked, TranscriptsDisabled, VideoUnavailable, ) if isinstance(e, TranscriptsDisabled): return f"Error: Transcripts are disabled for video '{video_id}'." if isinstance(e, NoTranscriptFound): lang_str = ", ".join(languages) if languages else "any" return ( f"Error: No transcript found for video '{video_id}' " f"in language(s): {lang_str}. Use list_transcripts to see available languages." ) if isinstance(e, VideoUnavailable): return f"Error: Video '{video_id}' is unavailable." if isinstance(e, InvalidVideoId): return f"Error: '{video_id}' is not a valid YouTube video ID." if isinstance(e, AgeRestricted): return f"Error: Video '{video_id}' is age-restricted and cannot be accessed." if isinstance(e, IpBlocked): return "Error: YouTube is blocking requests from this IP address." if isinstance(e, RequestBlocked): return "Error: The request to YouTube was blocked." return f"Error fetching transcript for '{video_id}': {e}"

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/zlatkoc/youtube-summarize'

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