Skip to main content
Glama

get_youtube_transcript_tool

Extract timestamped English transcripts from YouTube videos using video URLs or IDs for accessibility and content analysis.

Instructions

Extract English transcript with timestamps from a YouTube video using its URL or video ID.

Args:
    url: YouTube video URL or video ID

Returns:
    The timestamped transcript text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • main.py:74-98 (handler)
    The main handler function for the 'get_youtube_transcript_tool' tool, decorated with @mcp.tool() to register it with the FastMCP server. It processes the YouTube URL, extracts the video ID, fetches the transcript using helpers, formats the output, and returns a user-friendly response.
    @mcp.tool()
    async def get_youtube_transcript_tool(url: str) -> str:
        """Extract English transcript with timestamps from a YouTube video using its URL or video ID.
        
        Args:
            url: YouTube video URL or video ID
        
        Returns:
            The timestamped transcript text
        """
        try:
            video_id = extract_video_id(url)
            result = get_youtube_transcript(video_id)
            
            if result['success']:
                response = f"✅ Successfully extracted English transcript for video: {video_id}\n\n"
                response += f"📄 Transcript with timestamps:\n{result['transcript']}\n\n"
                response += f"🔍 Total segments: {result['segments_count']}"
                
                return response
            else:
                return f"❌ Failed to extract transcript: {result['error']}"
        
        except Exception as e:
            return f"❌ Error processing video: {str(e)}"
  • main.py:44-71 (helper)
    Helper function that fetches the English transcript from YouTube using youtube_transcript_api, formats it with timestamps using format_timestamp, and returns a structured dict with success status.
    def get_youtube_transcript(video_id: str) -> dict[str, Any]:
        """Get YouTube transcript using youtube-transcript-api (English only)."""
        try:
            # Get English transcript
            transcript_list = YouTubeTranscriptApi.get_transcript(video_id, ['en'])
            
            # Create timestamped transcript
            timestamped_transcript = []
            for entry in transcript_list:
                timestamp = format_timestamp(entry['start'])
                timestamped_transcript.append(f"[{timestamp}] {entry['text']}")
            
            # Join all segments
            full_transcript = '\n'.join(timestamped_transcript)
            
            return {
                'success': True,
                'video_id': video_id,
                'transcript': full_transcript,
                'segments_count': len(transcript_list)
            }
        
        except Exception as e:
            return {
                'success': False,
                'error': str(e),
                'video_id': video_id
            }
  • main.py:12-29 (helper)
    Helper function to extract the YouTube video ID from various URL formats using regular expressions.
    def extract_video_id(url: str) -> str:
        """Extract YouTube video ID from various YouTube URL formats."""
        # Handle different YouTube URL formats
        patterns = [
            r'(?:youtube\.com/watch\?v=|youtu\.be/|youtube\.com/embed/)([a-zA-Z0-9_-]{11})',
            r'youtube\.com/watch\?.*v=([a-zA-Z0-9_-]{11})',
        ]
        
        for pattern in patterns:
            match = re.search(pattern, url)
            if match:
                return match.group(1)
        
        # If no pattern matches, maybe it's already a video ID
        if len(url) == 11 and re.match(r'^[a-zA-Z0-9_-]{11}$', url):
            return url
        
        raise ValueError(f"Could not extract video ID from URL: {url}")
  • main.py:32-41 (helper)
    Helper function to format seconds into a readable timestamp string (MM:SS or HH:MM:SS).
    def format_timestamp(seconds: float) -> str:
        """Convert seconds to MM:SS or HH:MM:SS format."""
        hours = int(seconds // 3600)
        minutes = int((seconds % 3600) // 60)
        seconds = int(seconds % 60)
        
        if hours > 0:
            return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
        else:
            return f"{minutes:02d}:{seconds:02d}"
Behavior3/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. It describes the core functionality (extracting transcripts) and output format (timestamped text), but lacks details on error handling, rate limits, authentication needs, or processing constraints. It adds basic context but misses key behavioral traits.

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 well-structured and front-loaded with the core purpose in the first sentence, followed by clear sections for Args and Returns. Every sentence adds value without redundancy, making it efficient and easy to parse.

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

Completeness4/5

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

Given the tool's moderate complexity (single parameter, no annotations, but with an output schema), the description is mostly complete. It covers purpose, input semantics, and return values, and the output schema handles return details. However, it lacks behavioral context like error cases or limitations, which slightly reduces completeness.

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

Parameters4/5

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

The schema description coverage is 0%, so the description must compensate. It adds meaning by explaining that the 'url' parameter accepts either a 'YouTube video URL or video ID', clarifying the input format beyond the schema's generic string type. However, it doesn't detail validation rules or examples, leaving some gaps.

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

Purpose5/5

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

The description clearly states the specific action ('Extract'), resource ('English transcript with timestamps from a YouTube video'), and input method ('using its URL or video ID'). It distinguishes itself by specifying the transcript format (English with timestamps) and input options, though there are no sibling tools for explicit differentiation.

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

Usage Guidelines3/5

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

The description implies usage by stating the input method ('URL or video ID'), but provides no explicit guidance on when to use this tool versus alternatives, prerequisites, or exclusions. Since there are no sibling tools, the lack of comparative guidance is less critical, but it still lacks comprehensive usage context.

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

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