get-youtube-transcript
Extract YouTube video transcripts with customizable options for timestamps and language preferences, enabling efficient content analysis and accessibility.
Instructions
Extract transcripts from YouTube videos with optional parameters for timestamps and language preferences.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeTimestamps | No | Whether to include timestamps | |
| preferredLanguage | No | Preferred language code | |
| timestampsToCombine | No | Number of timestamps to combine | |
| videoUrl | Yes | URL of the YouTube video |
Implementation Reference
- src/index.ts:35-63 (handler)The handler function for the 'get-youtube-transcript' tool. It makes a POST request to the DumplingAI API endpoint with the provided parameters, authenticates using DUMPLING_API_KEY, and returns the transcript data as JSON stringified text content.async ({ videoUrl, includeTimestamps, timestampsToCombine, preferredLanguage, }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch( `${NWS_API_BASE}/api/v1/get-youtube-transcript`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ videoUrl, includeTimestamps, timestampsToCombine, preferredLanguage, }), } ); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; }
- src/index.ts:20-34 (schema)Zod input schema defining parameters for the tool: videoUrl (required URL), includeTimestamps (boolean, default true), timestampsToCombine (optional number), preferredLanguage (optional string).videoUrl: z.string().url().describe("URL of the YouTube video"), includeTimestamps: z .boolean() .optional() .default(true) .describe("Whether to include timestamps"), timestampsToCombine: z .number() .optional() .describe("Number of timestamps to combine"), preferredLanguage: z .string() .optional() .describe("Preferred language code"), },
- src/index.ts:16-64 (registration)Complete registration of the 'get-youtube-transcript' tool using McpServer.tool(), including name, description, input schema, and inline handler function.server.tool( "get-youtube-transcript", "Extract transcripts from YouTube videos with optional parameters for timestamps and language preferences.", { videoUrl: z.string().url().describe("URL of the YouTube video"), includeTimestamps: z .boolean() .optional() .default(true) .describe("Whether to include timestamps"), timestampsToCombine: z .number() .optional() .describe("Number of timestamps to combine"), preferredLanguage: z .string() .optional() .describe("Preferred language code"), }, async ({ videoUrl, includeTimestamps, timestampsToCombine, preferredLanguage, }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch( `${NWS_API_BASE}/api/v1/get-youtube-transcript`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ videoUrl, includeTimestamps, timestampsToCombine, preferredLanguage, }), } ); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } );