Skip to main content
Glama
jkawamoto

YouTube Transcript MCP Server

get_transcript

Retrieve YouTube video transcripts for integration with Goose CLI or Desktop, enabling transcript extraction and processing from video URLs.

Instructions

Retrieves the transcript of a YouTube video.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL of the YouTube video
langNoThe preferred language for the transcripten
next_cursorNoCursor to retrieve the next page of the transcript

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesTitle of the video
transcriptYesTranscript of the video
next_cursorNoCursor to retrieve the next page of the transcript

Implementation Reference

  • The handler function for the 'get_transcript' tool, registered via @mcp.tool() decorator. Handles fetching and paginating the transcript.
    @mcp.tool()
    async def get_transcript(
        ctx: Context[ServerSession, AppContext],
        url: str = Field(description="The URL of the YouTube video"),
        lang: str = Field(description="The preferred language for the transcript", default="en"),
        next_cursor: str | None = Field(description="Cursor to retrieve the next page of the transcript", default=None),
    ) -> Transcript:
        """Retrieves the transcript of a YouTube video."""
    
        title, snippets = _get_transcript_snippets(ctx.request_context.lifespan_context, _parse_video_id(url), lang)
        transcripts = (item.text for item in snippets)
    
        if response_limit is None or response_limit <= 0:
            return Transcript(title=title, transcript="\n".join(transcripts))
    
        res = ""
        cursor = None
        for i, line in islice(enumerate(transcripts), int(next_cursor or 0), None):
            if len(res) + len(line) + 1 > response_limit:
                cursor = str(i)
                break
            res += f"{line}\n"
    
        return Transcript(title=title, transcript=res[:-1], next_cursor=cursor)
  • Pydantic model defining the output schema for the get_transcript tool.
    class Transcript(BaseModel):
        """Transcript of a YouTube video."""
    
        title: str = Field(description="Title of the video")
        transcript: str = Field(description="Transcript of the video")
        next_cursor: str | None = Field(description="Cursor to retrieve the next page of the transcript", default=None)
  • Helper function to fetch the video title and transcript snippets using YouTubeTranscriptApi, with language fallback.
    @lru_cache
    def _get_transcript_snippets(ctx: AppContext, video_id: str, lang: str) -> Tuple[str, list[FetchedTranscriptSnippet]]:
        if lang == "en":
            languages = ["en"]
        else:
            languages = [lang, "en"]
    
        page = ctx.http_client.get(
            f"https://www.youtube.com/watch?v={video_id}", headers={"Accept-Language": ",".join(languages)}
        )
        page.raise_for_status()
        soup = BeautifulSoup(page.text, "html.parser")
        title = soup.title.string if soup.title and soup.title.string else "Transcript"
    
        transcripts = ctx.ytt_api.fetch(video_id, languages=languages)
        return title, transcripts.snippets
  • Utility function to extract YouTube video ID from various URL formats.
    def _parse_video_id(url: str) -> str:
        parsed_url = urlparse(url)
        if parsed_url.hostname == "youtu.be":
            return parsed_url.path.lstrip("/")
        else:
            q = parse_qs(parsed_url.query).get("v")
            if q is None:
                raise ValueError(f"couldn't find a video ID from the provided URL: {url}.")
            return q[0]
  • The server factory function where the get_transcript tool is registered by decorating its handler with @mcp.tool().
    def server(
        response_limit: int | None = None,
        webshare_proxy_username: str | None = None,
        webshare_proxy_password: str | None = None,
        http_proxy: str | None = None,
        https_proxy: str | None = None,
    ) -> FastMCP:
        """Initializes the MCP server."""
    
        proxy_config: ProxyConfig | None = None
        if webshare_proxy_username and webshare_proxy_password:
            proxy_config = WebshareProxyConfig(webshare_proxy_username, webshare_proxy_password)
        elif http_proxy or https_proxy:
            proxy_config = GenericProxyConfig(http_proxy, https_proxy)
    
        mcp = FastMCP("Youtube Transcript", lifespan=partial(_app_lifespan, proxy_config=proxy_config))
    
        @mcp.tool()
        async def get_transcript(
            ctx: Context[ServerSession, AppContext],
            url: str = Field(description="The URL of the YouTube video"),
            lang: str = Field(description="The preferred language for the transcript", default="en"),
            next_cursor: str | None = Field(description="Cursor to retrieve the next page of the transcript", default=None),
        ) -> Transcript:
            """Retrieves the transcript of a YouTube video."""
    
            title, snippets = _get_transcript_snippets(ctx.request_context.lifespan_context, _parse_video_id(url), lang)
            transcripts = (item.text for item in snippets)
    
            if response_limit is None or response_limit <= 0:
                return Transcript(title=title, transcript="\n".join(transcripts))
    
            res = ""
            cursor = None
            for i, line in islice(enumerate(transcripts), int(next_cursor or 0), None):
                if len(res) + len(line) + 1 > response_limit:
                    cursor = str(i)
                    break
                res += f"{line}\n"
    
            return Transcript(title=title, transcript=res[:-1], next_cursor=cursor)
    
        @mcp.tool()
        async def get_timed_transcript(
            ctx: Context[ServerSession, AppContext],
            url: str = Field(description="The URL of the YouTube video"),
            lang: str = Field(description="The preferred language for the transcript", default="en"),
            next_cursor: str | None = Field(description="Cursor to retrieve the next page of the transcript", default=None),
        ) -> TimedTranscript:
            """Retrieves the transcript of a YouTube video with timestamps."""
    
            title, snippets = _get_transcript_snippets(ctx.request_context.lifespan_context, _parse_video_id(url), lang)
    
            if response_limit is None or response_limit <= 0:
                return TimedTranscript(
                    title=title, snippets=[TranscriptSnippet.from_fetched_transcript_snippet(s) for s in snippets]
                )
    
            res = []
            size = len(title) + 1
            cursor = None
            for i, s in islice(enumerate(snippets), int(next_cursor or 0), None):
                snippet = TranscriptSnippet.from_fetched_transcript_snippet(s)
                if size + len(snippet) + 1 > response_limit:
                    cursor = str(i)
                    break
                res.append(snippet)
    
            return TimedTranscript(title=title, snippets=res, next_cursor=cursor)
    
        @mcp.tool()
        def get_video_info(
            ctx: Context[ServerSession, AppContext],
            url: str = Field(description="The URL of the YouTube video"),
        ) -> VideoInfo:
            """Retrieves the video information."""
            return _get_video_info(ctx.request_context.lifespan_context, url)
    
        return mcp
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 but only states the basic action. It lacks details on permissions, rate limits, error handling, or the format of the transcript (e.g., plain text, structured data). This is inadequate for a tool with parameters and an output schema, as it doesn't prepare the agent for potential complexities.

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, clear sentence with no wasted words, making it highly efficient and front-loaded. Every part of the sentence directly contributes to understanding the tool's purpose, achieving optimal conciseness without sacrificing clarity.

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 has an output schema and full schema coverage, the description doesn't need to explain return values or parameters in detail. However, with no annotations and sibling tools present, it should provide more context on usage and behavior to be fully complete. It's minimally adequate but leaves gaps in guiding the agent effectively.

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 doesn't add any parameter-specific information beyond what's already in the input schema, which has 100% coverage. It implies a 'url' parameter but doesn't explain its format or constraints. Since the schema fully documents the parameters, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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 ('Retrieves') and resource ('transcript of a YouTube video'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'get_timed_transcript' or 'get_video_info', which likely retrieve similar or related data, so it falls short of 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 like 'get_timed_transcript' or 'get_video_info'. There's no mention of prerequisites, exclusions, or specific contexts for usage, leaving the agent with insufficient information to make an informed choice among siblings.

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

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