Skip to main content
Glama

get_transcripts

Extract transcripts from YouTube videos by providing the video URL or ID. Specify optional language codes for multilingual transcripts or enable paragraph breaks for easier reading. Ideal for content analysis, subtitles, and processing tasks.

Instructions

Extract and process transcripts from a YouTube video.

Parameters:

  • url (string, required): YouTube video URL or ID.

  • lang (string, optional, default 'en'): Language code for transcripts (e.g. 'en', 'uk', 'ja', 'ru', 'zh').

  • enableParagraphs (boolean, optional, default false): Enable automatic paragraph breaks.

IMPORTANT: If the user does not specify a language code, DO NOT include the lang parameter in the tool call. Do not guess the language or use parts of the user query as the language code.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
enableParagraphsNoEnable automatic paragraph breaks, default `false`
langNoLanguage code for transcripts, default 'en' (e.g. 'en', 'uk', 'ja', 'ru', 'zh')en
urlYesYouTube video URL or ID

Implementation Reference

  • Primary handler function for the 'get_transcripts' tool. Extracts video ID from URL, fetches transcripts using the extractor, formats the text, and returns structured content with title and metadata.
    async (input) => { try { const videoId = this.extractor.extractYoutubeId(input.url); console.error(`Processing transcripts for video: ${videoId}`); const { transcripts, title } = await this.extractor.getTranscripts({ videoID: videoId, lang: input.lang }); // Format text with optional paragraph breaks const formattedText = YouTubeUtils.formatTranscriptText(transcripts, { enableParagraphs: input.enableParagraphs }); console.error(`Successfully extracted transcripts for "${title}" (${formattedText.length} chars)`); return { content: [{ type: "text", text: `# ${title}\n\n${formattedText}`, metadata: { videoId, title, language: input.lang, timestamp: new Date().toISOString(), charCount: formattedText.length, transcriptCount: transcripts.length, totalDuration: YouTubeUtils.calculateTotalDuration(transcripts), paragraphsEnabled: input.enableParagraphs } }] }; } catch (error) { if (error instanceof YouTubeTranscriptError || error instanceof McpError) { throw error; } throw new YouTubeTranscriptError(`Failed to process transcripts: ${(error as Error).message}`); } }
  • Zod input schema definition for the tool parameters: url (required), lang (optional), enableParagraphs (optional).
    { url: z.string().describe("YouTube video URL or ID"), lang: z.string().default("en").describe("Language code for transcripts, default 'en' (e.g. 'en', 'uk', 'ja', 'ru', 'zh')"), enableParagraphs: z.boolean().default(false).describe("Enable automatic paragraph breaks, default `false`") },
  • src/index.ts:60-108 (registration)
    Registration of the 'get_transcripts' tool with the MCP server, specifying name, description, input schema, and handler function.
    this.server.tool( "get_transcripts", `Extract and process transcripts from a YouTube video.\n\n**Parameters:**\n- \`url\` (string, required): YouTube video URL or ID.\n- \`lang\` (string, optional, default 'en'): Language code for transcripts (e.g. 'en', 'uk', 'ja', 'ru', 'zh').\n- \`enableParagraphs\` (boolean, optional, default false): Enable automatic paragraph breaks.\n\n**IMPORTANT:** If the user does *not* specify a language *code*, **DO NOT** include the \`lang\` parameter in the tool call. Do not guess the language or use parts of the user query as the language code.`, { url: z.string().describe("YouTube video URL or ID"), lang: z.string().default("en").describe("Language code for transcripts, default 'en' (e.g. 'en', 'uk', 'ja', 'ru', 'zh')"), enableParagraphs: z.boolean().default(false).describe("Enable automatic paragraph breaks, default `false`") }, async (input) => { try { const videoId = this.extractor.extractYoutubeId(input.url); console.error(`Processing transcripts for video: ${videoId}`); const { transcripts, title } = await this.extractor.getTranscripts({ videoID: videoId, lang: input.lang }); // Format text with optional paragraph breaks const formattedText = YouTubeUtils.formatTranscriptText(transcripts, { enableParagraphs: input.enableParagraphs }); console.error(`Successfully extracted transcripts for "${title}" (${formattedText.length} chars)`); return { content: [{ type: "text", text: `# ${title}\n\n${formattedText}`, metadata: { videoId, title, language: input.lang, timestamp: new Date().toISOString(), charCount: formattedText.length, transcriptCount: transcripts.length, totalDuration: YouTubeUtils.calculateTotalDuration(transcripts), paragraphsEnabled: input.enableParagraphs } }] }; } catch (error) { if (error instanceof YouTubeTranscriptError || error instanceof McpError) { throw error; } throw new YouTubeTranscriptError(`Failed to process transcripts: ${(error as Error).message}`); } } );
  • Helper method in YouTubeTranscriptExtractor class that wraps the core fetchTranscripts call and adds error handling.
    async getTranscripts({ videoID, lang }: TranscriptOptions): Promise<{ transcripts: Transcript[], title: string }> { try { const result = await YouTubeTranscriptFetcher.fetchTranscripts(videoID, { lang }); if (result.transcripts.length === 0) { throw new YouTubeTranscriptError('No transcripts found'); } return result; } catch (error) { if (error instanceof YouTubeTranscriptError || error instanceof McpError) { throw error; } throw new YouTubeTranscriptError(`Failed to fetch transcripts: ${(error as Error).message}`); } }
  • Core helper function in YouTubeTranscriptFetcher that extracts video ID, fetches transcript config/content and title concurrently, representing the main implementation logic for retrieving transcripts.
    static async fetchTranscripts(videoId: string, config?: { lang?: string }): Promise<{ transcripts: Transcript[], title: string }> { try { const identifier = this.extractVideoId(videoId); const [{ transcripts }, title] = await Promise.all([ this.fetchTranscriptConfigAndContent(identifier, config?.lang), this.fetchVideoTitle(identifier) ]); return { transcripts, title }; } catch (error) { if (error instanceof YouTubeTranscriptError || error instanceof McpError) { throw error; } throw new YouTubeTranscriptError(`Failed to fetch transcripts: ${(error as Error).message}`); } }

Other Tools

Related 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/sinco-lab/mcp-youtube-transcript'

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