Skip to main content
Glama

DownloadClosedCaptions

Extract closed captions from YouTube videos to enable content analysis, summarization, and accessibility applications.

Instructions

Download closed captions from YouTube video.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
video_urlYes

Implementation Reference

  • The main handler function for the DownloadClosedCaptions tool, decorated with @tool_runner.register. It parses the YouTube video URL, retrieves or caches the transcript using youtube_transcript_api, extracts the text content, and returns it as TextContent.
    @tool_runner.register
    async def download_closed_captions(
        args: DownloadClosedCaptions,
    ) -> t.Sequence[TextContent | ImageContent | EmbeddedResource]:
        transcripts_dir = xdg_cache_home() / "mcp-youtube" / "transcripts"
        transcripts_dir.mkdir(parents=True, exist_ok=True)
    
        video_id = _parse_youtube_url(args.video_url)
        if not video_id:
            raise ValueError(f"Unrecognized YouTube URL: {args.video_url}")
    
        if not transcripts_dir.joinpath(f"{video_id}.json").exists():
            transcript = YouTubeTranscriptApi.get_transcript(video_id)
            if not transcript or not isinstance(transcript, list):
                raise ValueError("No transcript found for the video.")
    
            json_data = json.dumps(transcript, indent=None)
            transcripts_dir.joinpath(f"{video_id}.json").write_text(json_data)
    
        else:
            json_data = transcripts_dir.joinpath(f"{video_id}.json").read_text()
            transcript = json.loads(json_data)
    
        content = " ".join([line["text"] for line in transcript])
    
        return [
            TextContent(
                type="text",
                text=content,
            ),
        ]
  • Pydantic model defining the input schema for the tool, including the required video_url parameter and tool description docstring.
    class DownloadClosedCaptions(ToolArgs):
        """Download closed captions from YouTube video."""
    
        video_url: str
  • Helper function to parse YouTube URLs (both youtu.be and youtube.com/watch?v= formats) and extract the video ID, used in the handler.
    def _parse_youtube_url(url: str) -> str | None:
        """
        Parse a YouTube URL and extract the video ID from the v= parameter.
    
        Args:
            url (str): YouTube URL in various formats
    
        Returns:
            str: Video ID if found, None otherwise
    
        Examples:
            >>> parse_youtube_url("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
            'dQw4w9WgXcQ'
            >>> parse_youtube_url("https://youtu.be/dQw4w9WgXcQ")
            'dQw4w9WgXcQ'
            >>> parse_youtube_url("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=123")
            'dQw4w9WgXcQ'
        """
    
        # Handle youtu.be format
        if "youtu.be" in url:
            return url.split("/")[-1].split("?")[0]
    
        # Handle regular youtube.com format
        try:
            parsed_url = urlparse(url)
            if "youtube.com" in parsed_url.netloc:
                params = parse_qs(parsed_url.query)
                if "v" in params:
                    return params["v"][0]
        except:  # noqa: E722, S110
            pass
    
        return None
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'download' implies a read operation, it doesn't specify authentication requirements, rate limits, output format, error conditions, or whether it modifies any state. This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just one sentence with no wasted words. It's front-loaded with the core purpose and contains no unnecessary information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations, no output schema, and 0% schema description coverage, the description is insufficient. It doesn't explain what format the captions are returned in, whether authentication is needed, or any error handling. The minimal description leaves too many questions unanswered for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, and the description doesn't provide any information about the single parameter beyond what's implied by the tool name. No details about the video_url format, validation rules, or examples are given, leaving the parameter poorly documented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('download') and resource ('closed captions from YouTube video'), making the purpose immediately understandable. However, with no sibling tools mentioned, there's no opportunity to differentiate from alternatives, which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or limitations. It simply states what the tool does without contextual usage information.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/sparfenyuk/mcp-youtube'

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