transcripts_getTranscript
Retrieve the transcript of a YouTube video by specifying its video ID and optional language code. Use this tool to access video content text for analysis, translation, or accessibility purposes.
Instructions
Get the transcript of a YouTube video
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | No | Language code for the transcript | |
| videoId | Yes | The YouTube video ID |
Implementation Reference
- src/services/transcript.ts:24-42 (handler)The primary handler function that fetches the YouTube video transcript using the YoutubeTranscript library and returns it structured with videoId, language, and transcript data.async getTranscript({ videoId, language = process.env.YOUTUBE_TRANSCRIPT_LANG || 'en' }: TranscriptParams): Promise<any> { 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 input parameters for the transcripts_getTranscript tool: videoId (required) and language (optional).export interface TranscriptParams { videoId: string; language?: string; }
- src/server.ts:81-98 (registration)Tool registration in the MCP server's ListToolsRequestHandler, defining the tool name, description, and input schema matching TranscriptParams.{ name: 'transcripts_getTranscript', description: 'Get the transcript of a YouTube video', inputSchema: { type: 'object', properties: { videoId: { type: 'string', description: 'The YouTube video ID', }, language: { type: 'string', description: 'Language code for the transcript', }, }, required: ['videoId'], }, },
- src/server.ts:192-200 (handler)Dispatch handler in the MCP CallToolRequestHandler that casts arguments to TranscriptParams and calls the TranscriptService.getTranscript method, formatting the result as MCP content.case 'transcripts_getTranscript': { const result = await transcriptService.getTranscript(args as unknown as TranscriptParams); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }