get_youtube_transcript
Extract transcripts from YouTube videos by providing the video URL. Access captions and subtitles to analyze content, enable research, or support accessibility needs.
Instructions
Get the transcript of a YouTube video
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes |
Implementation Reference
- The main handler function that implements get_youtube_transcript logic. Extracts video ID from URL, fetches transcript using YouTubeTranscriptApi with Korean and English language preference, and returns concatenated transcript text.
def get_youtube_transcript(url: str) -> str: """Get the transcript of a YouTube video""" video_id_match = re.search(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url) if not video_id_match: raise ValueError("Invalid YouTube URL provided") video_id = video_id_match.group(1) languages = ["ko", "en"] try: transcript_list = YouTubeTranscriptApi.get_transcript(video_id, languages=languages) transcript_text = " ".join([entry["text"] for entry in transcript_list]) return transcript_text except Exception as e: raise RuntimeError(f"Could not find or use the transcript for video ID '{video_id}'. {e}") - FastMCP automatically generates the tool schema from Python type hints (url: str) -> str and the docstring. This serves as the input/output validation definition.
@mcp.tool() def get_youtube_transcript(url: str) -> str: """Get the transcript of a YouTube video""" - src/youtubeinsights_mcp_server/server.py:19-19 (registration)The @mcp.tool() decorator registers the get_youtube_transcript function as an MCP tool with the FastMCP server instance.
@mcp.tool()