Skip to main content
Glama
williamvd4

YouTube Transcript Server

by williamvd4

get_transcript

Extract text transcripts from YouTube videos using video URLs or IDs. Supports multiple languages for accessibility and content analysis.

Instructions

Extract transcript from a YouTube video URL or ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesYouTube video URL or ID
langYesLanguage code for transcript (e.g., 'ko', 'en')en

Implementation Reference

  • Tool dispatch handler for 'get_transcript': validates input arguments, extracts video ID, fetches transcript via extractor, formats response with metadata.
    case "get_transcript": {
      const { url: input, lang = "en" } = args;
      
      if (!input || typeof input !== 'string') {
        throw new McpError(
          ErrorCode.InvalidParams,
          'URL parameter is required and must be a string'
        );
      }
    
      if (lang && typeof lang !== 'string') {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Language code must be a string'
        );
      }
      
      try {
        const videoId = this.extractor.extractYoutubeId(input);
        console.error(`Processing transcript for video: ${videoId}`);
        
        const transcript = await this.extractor.getTranscript(videoId, lang);
        console.error(`Successfully extracted transcript (${transcript.length} chars)`);
        
        return {
          toolResult: {
            content: [{
              type: "text",
              text: transcript,
              metadata: {
                videoId,
                language: lang,
                timestamp: new Date().toISOString(),
                charCount: transcript.length
              }
            }],
            isError: false
          }
        };
      } catch (error) {
        console.error('Transcript extraction failed:', error);
        
        if (error instanceof McpError) {
          throw error;
        }
        
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to process transcript: ${(error as Error).message}`
        );
      }
    }
  • Core implementation of transcript extraction: calls external 'getSubtitles' library and formats the result.
    async getTranscript(videoId: string, lang: string): Promise<string> {
      try {
        const transcript = await getSubtitles({
          videoID: videoId,
          lang: lang,
        });
    
        return this.formatTranscript(transcript);
      } catch (error) {
        console.error('Failed to fetch transcript:', error);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to retrieve transcript: ${(error as Error).message}`
        );
      }
    }
  • Tool schema definition including name, description, and input schema for parameters 'url' and 'lang'.
    const TOOLS: Tool[] = [
      {
        name: "get_transcript",
        description: "Extract transcript from a YouTube video URL or ID",
        inputSchema: {
          type: "object",
          properties: {
            url: {
              type: "string",
              description: "YouTube video URL or ID"
            },
            lang: {
              type: "string",
              description: "Language code for transcript (e.g., 'ko', 'en')",
              default: "en"
            }
          },
          required: ["url", "lang"]
        }
      }
    ];
  • src/index.ts:155-157 (registration)
    Registers the tool by providing it in the listTools response.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: TOOLS
    }));
  • Helper function to extract canonical YouTube video ID from URL or direct ID input.
    extractYoutubeId(input: string): string {
      if (!input) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'YouTube URL or ID is required'
        );
      }
    
      // Handle URL formats
      try {
        const url = new URL(input);
        if (url.hostname === 'youtu.be') {
          return url.pathname.slice(1);
        } else if (url.hostname.includes('youtube.com')) {
          const videoId = url.searchParams.get('v');
          if (!videoId) {
            throw new McpError(
              ErrorCode.InvalidParams,
              `Invalid YouTube URL: ${input}`
            );
          }
          return videoId;
        }
      } catch (error) {
        // Not a URL, check if it's a direct video ID
        if (!/^[a-zA-Z0-9_-]{11}$/.test(input)) {
          throw new McpError(
            ErrorCode.InvalidParams,
            `Invalid YouTube video ID: ${input}`
          );
        }
        return input;
      }
    
      throw new McpError(
        ErrorCode.InvalidParams,
        `Could not extract video ID from: ${input}`
      );
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions extraction but doesn't disclose behavioral traits like rate limits, authentication needs, error handling, or what happens if the video lacks a transcript. This leaves significant gaps for an agent to understand 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 a single, efficient sentence that directly states the tool's purpose without any wasted words. It is appropriately sized and front-loaded, making it easy to parse.

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?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain return values, error cases, or operational constraints, which are crucial for a tool that interacts with external services like YouTube. This leaves the agent with insufficient context for effective use.

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 implies parameters for URL/ID and language, but the input schema already has 100% coverage with clear descriptions for 'url' and 'lang'. The description adds minimal value beyond the schema, so it meets the baseline of 3 for high schema coverage.

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 'extract' and the resource 'transcript from a YouTube video', making the purpose specific and understandable. However, with no sibling tools mentioned, it cannot differentiate from alternatives, so it doesn't reach the highest score of 5.

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 exclusions. It only states what the tool does, with no context for usage decisions.

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

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