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
| Name | Required | Description | Default |
|---|---|---|---|
| videoId | Yes | The YouTube video ID | |
| language | No | Language code for the transcript |
Implementation Reference
- src/services/transcript.ts:24-42 (handler)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)}`); } }
- src/types.ts:37-40 (schema)TypeScript interface defining the parameters for the transcript service methods: videoId (required) and language (optional).export interface TranscriptParams { videoId: string; language?: string; }
- src/server-utils.ts:177-197 (registration)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) }] }; } );