Skip to main content
Glama

transcripts_getTranscript

Retrieve YouTube video transcripts by providing the video ID and optional language code for accessibility and content analysis.

Instructions

Get the transcript of a YouTube video

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
videoIdYesThe YouTube video ID
languageNoLanguage code for the transcript

Implementation Reference

  • Core implementation of the getTranscript method in TranscriptService class, which fetches the transcript using YoutubeTranscript.fetchTranscript(videoId). Note that language param is captured but not passed to the library.
    async getTranscript({ 
      videoId, 
      language = process.env.YOUTUBE_TRANSCRIPT_LANG || 'en' 
    }: TranscriptParams): Promise<unknown> {
      try {
        this.initialize();
        
        // YoutubeTranscript.fetchTranscript only accepts videoId
        const transcript = await YoutubeTranscript.fetchTranscript(videoId);
        
        return {
          videoId,
          language,
          transcript
        };
      } catch (error) {
        throw new Error(`Failed to get transcript: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • TypeScript interface defining the parameters for the transcript service methods: videoId (required) and language (optional).
    export interface TranscriptParams {
      videoId: string;
      language?: string;
    }
  • Registration of the 'transcripts_getTranscript' MCP tool, including title, description, Zod input schema matching TranscriptParams, and thin async handler that wraps TranscriptService.getTranscript and formats response as MCP content.
    server.registerTool(
        'transcripts_getTranscript',
        {
            title: 'Get Video Transcript',
            description: 'Get the transcript of a YouTube video',
            annotations: { readOnlyHint: true, idempotentHint: true },
            inputSchema: {
                videoId: z.string().describe('The YouTube video ID'),
                language: z.string().optional().describe('Language code for the transcript'),
            },
        },
        async ({ videoId, language }) => {
            const result = await transcriptService.getTranscript({ videoId, language });
            return {
                content: [{
                    type: 'text',
                    text: JSON.stringify(result, null, 2)
                }]
            };
        }
    );

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

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