Skip to main content
Glama
jikime

YouTube Toolbox

get_video_transcript

Extract transcripts or captions from YouTube videos to access spoken content in text format for analysis, translation, or accessibility purposes.

Instructions

Get transcript/captions for a YouTube video

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
video_idYes
languageNoko

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary MCP tool handler implementing the get_video_transcript tool. Fetches video metadata using YouTube API, retrieves transcript segments via helper, formats with timestamps, and returns structured data including metadata, segment list, and plain timestamped text.
    @mcp.tool(
        name="get_video_transcript",
        description="Get transcript/captions for a YouTube video",
    )
    async def get_video_transcript(video_id: str, language: Optional[str] = 'ko') -> Dict[str, Any]:
        """
        Get transcript/captions for a YouTube video
        
        Args:
            video_id (str): YouTube video ID
            language (str, optional): Language code (e.g., 'en', 'ko', 'fr')
        
        Returns:
            Dict[str, Any]: Transcript data
        """
        try:
            # Get video details for metadata
            video_data = youtube_service.get_video_details(video_id)
            
            if not video_data.get('items'):
                return {'error': f"Video with ID {video_id} not found"}
                
            video = video_data['items'][0]
            
            # Get transcript
            try:
                transcript_data = youtube_service.get_video_transcript(video_id, language)
                
                # Format transcript with timestamps
                formatted_transcript = []
                for segment in transcript_data:
                    text = getattr(segment, 'text', '')
                    start = getattr(segment, 'start', 0)
                    duration = getattr(segment, 'duration', 0)
                    
                    formatted_transcript.append({
                        'text': text,
                        'start': start,
                        'duration': duration,
                        'timestamp': youtube_service.format_time(int(start * 1000))
                    })
                
                # Create metadata
                metadata = {
                    'videoId': video.get('id'),
                    'title': video.get('snippet', {}).get('title'),
                    'channelTitle': video.get('snippet', {}).get('channelTitle'),
                    'language': language or 'default',
                    'segmentCount': len(transcript_data)
                }
                
                # Create timestamped text version
                timestamped_text = "\n".join([
                    f"[{item['timestamp']}] {item['text']}" 
                    for item in formatted_transcript
                ])
                
                return {
                    'metadata': metadata,
                    'transcript': formatted_transcript,
                    'text': timestamped_text,
                    'channelId': video.get('snippet', {}).get('channelId')
                }
            except Exception as e:
                return {
                    'error': f"Could not retrieve transcript: {str(e)}",
                    'videoId': video_id,
                    'title': video.get('snippet', {}).get('title')
                }
                
        except Exception as e:
            logger.exception(f"Error in get_video_transcript: {e}")
            return {'error': str(e)}
  • Core helper method in YouTubeService that fetches raw transcript segments using youtube_transcript_api. Supports language-specific transcripts with fallbacks to generated and English transcripts.
    def get_video_transcript(self, video_id: str, language: Optional[str] = 'ko') -> List[Dict[str, Any]]:
        """
        Get transcript for a specific YouTube video
        """
        video_id = self.parse_url(video_id)
        
        try:
            if language:
                transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
                try:
                    transcript = transcript_list.find_transcript([language])
                    return transcript.fetch()
                except NoTranscriptFound:
                    # Fallback to generated transcript if available
                    try:
                        transcript = transcript_list.find_generated_transcript([language])
                        return transcript.fetch()
                    except:
                        # Final fallback to any available transcript
                        transcript = transcript_list.find_transcript(['en'])
                        return transcript.fetch()
            else:
                return YouTubeTranscriptApi.get_video_transcript(video_id)
                
        except (TranscriptsDisabled, NoTranscriptFound) as e:
            logger.error(f"No transcript available for video {video_id}: {e}")
            return []
        except Exception as e:
            logger.error(f"Error getting transcript for video {video_id}: {e}")
            raise e
  • server.py:684-687 (registration)
    The tool is listed in the available-youtube-tools resource, confirming its registration and providing description.
    {"name": "get_video_transcript", "description": "Get transcript/captions for a YouTube video"},
    {"name": "get_related_videos", "description": "Get videos related to a specific YouTube video"},
    {"name": "get_trending_videos", "description": "Get trending videos on YouTube by region"},
    {"name": "get_video_enhanced_transcript", "description": "Advanced transcript extraction tool with filtering, search, and multi-video capabilities. Provides rich transcript data for detailed analysis and processing. Features: 1) Extract transcripts from multiple videos; 2) Filter by time ranges; 3) Search within transcripts; 4) Segment transcripts; 5) Format output in different ways; 6) Include video metadata."}
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. It states the action but lacks details on permissions, rate limits, error handling, or response format. For a tool with an output schema, some context is implied, but key behavioral traits are missing.

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 a single, efficient sentence with no wasted words. It is front-loaded and directly states the tool's purpose, making it easy to parse quickly.

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

Completeness3/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 (2 parameters, no annotations, but with an output schema), the description is minimally adequate. The output schema reduces the need to explain return values, but the lack of behavioral context and usage guidelines leaves gaps in completeness.

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

Parameters3/5

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

The description mentions 'transcript/captions' and 'YouTube video', which loosely relates to the 'video_id' parameter, but adds minimal semantic value beyond the schema. With 0% schema description coverage, it partially compensates by hinting at the resource, but does not explain parameter roles or the 'language' parameter's purpose.

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 verb ('Get') and resource ('transcript/captions for a YouTube video'), making the tool's function immediately understandable. However, it does not distinguish this tool from its sibling 'get_video_enhanced_transcript', which could cause confusion about when to use each one.

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, such as 'get_video_enhanced_transcript' or other sibling tools. There is no mention of prerequisites, context, or exclusions, leaving the agent without usage direction.

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/jikime/py-mcp-youtube-toolbox'

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