Skip to main content
Glama

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
NameRequiredDescriptionDefault
youtube_urlYes
summary_lengthNoDesired summary length: 'short', 'medium', or 'long' (default: 'medium').medium

Implementation Reference

  • 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,
         };
       }
     }
  • 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),
    },
  • 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
      }
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other 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/minbang930/Youtube-Vision-MCP'

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