summarize_youtube_video
Generate text summaries of YouTube videos by providing a URL, with options for short, medium, or long output lengths.
Instructions
Generates a summary of a given YouTube video URL using Gemini Vision API.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| youtube_url | Yes | ||
| summary_length | No | Desired summary length: 'short', 'medium', or 'long' (default: 'medium'). | medium |
Implementation Reference
- src/index.ts:137-182 (handler)The main handler function for the 'summarize_youtube_video' tool. It validates input using the schema, constructs a prompt based on summary length, calls the Gemini API via callGeminiApi helper with the YouTube URL as video input, and returns the generated summary or handles errors.case "summarize_youtube_video": { try { // Parse and validate arguments const args = SummarizeYoutubeVideoInputSchema.parse(request.params.arguments); const { youtube_url, summary_length } = args; const length = summary_length || 'medium'; // Use default if not provided console.error(`[INFO] Received request to summarize YouTube URL: ${youtube_url} (Length: ${length})`); // Construct the prompt for Gemini API const finalPrompt = `Please summarize this video. Aim for a ${length} length summary.`; // Call Gemini API using the helper function const summary = await callGeminiApi(finalPrompt, { mimeType: "video/youtube", fileUri: youtube_url, }); console.error(`[INFO] Successfully generated summary.`); // Return success response return { content: [{ type: "text", text: summary }], }; } catch (error: any) { console.error(`[ERROR] Failed during summarize_youtube_video tool execution:`, error); // Handle Zod validation errors if (error instanceof z.ZodError) { return { content: [{ type: "text", text: `Invalid input: ${JSON.stringify(error.errors)}` }], isError: true, }; } // Handle generic errors let errorMessage = `Failed to generate summary for the video.`; if (error.message) { errorMessage += ` Details: ${error.message}`; } return { content: [{ type: "text", text: errorMessage }], isError: true, }; } }
- src/index.ts:45-49 (schema)Zod input schema for the tool, defining required YouTube URL and optional summary length enum.const SummaryLengthEnum = z.enum(['short', 'medium', 'long']).default('medium'); const SummarizeYoutubeVideoInputSchema = z.object({ youtube_url: z.string().url({ message: "Invalid YouTube URL provided." }), summary_length: SummaryLengthEnum.optional().describe("Desired summary length: 'short', 'medium', or 'long' (default: 'medium')."), });
- src/index.ts:70-74 (registration)Tool registration in the ListTools handler, providing name, description, and JSON schema derived from Zod schema.{ name: "summarize_youtube_video", description: "Generates a summary of a given YouTube video URL using Gemini Vision API.", inputSchema: zodToJsonSchema(SummarizeYoutubeVideoInputSchema), },
- src/index.ts:96-127 (helper)Shared helper function used by the tool handler to call the Gemini API with a prompt and YouTube video file data, handling errors and returning the generated text.async function callGeminiApi(prompt: string, fileData: { mimeType: string; fileUri: string }): Promise<string> { try { const result = await geminiModel.generateContent([ prompt, { fileData }, ]); const response = result.response; return response.text(); } catch (error: any) { console.error(`[ERROR] Gemini API call failed:`, error); // Attempt to provide more specific error info based on message content // (Since GoogleGenerativeAIError type seems unavailable for direct check) if (error instanceof Error) { // Check for common messages indicating client-side issues (API key, quota, etc.) // This part might need refinement based on actual observed error messages. if (error.message.includes('API key') || error.message.includes('permission denied')) { throw new Error(`Authentication/Authorization Error with Gemini API: ${error.message}`); } else if (error.message.includes('quota')) { throw new Error(`Gemini API quota likely exceeded: ${error.message}`); } else if (error.message.toLowerCase().includes('invalid')) { // Generic check for invalid inputs throw new Error(`Invalid input likely provided to Gemini API: ${error.message}`); } else if (error.message.includes('500') || error.message.includes('server error') || error.message.includes('network issue')) { // Guessing based on common error patterns for server/network issues throw new Error(`Gemini API server error or network issue: ${error.message}`); } // Re-throw generic error if specific checks don't match throw new Error(`Gemini API Error: ${error.message}`); } // Re-throw if it's not an Error instance for some reason throw error; // Keep original error if not an Error instance } }