ask_about_youtube_video
Extract insights from YouTube videos by asking questions or receiving general descriptions using the 'Youtube Vision MCP' server powered by the Google Gemini Vision API.
Instructions
Answers a question about the video or provides a general description if no question is asked.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| question | No | Question about the video content. If omitted, a general description will be generated. | |
| youtube_url | Yes |
Implementation Reference
- src/index.ts:251-306 (handler)Handler function for the 'ask_about_youtube_video' tool. Parses input, constructs a prompt based on whether a question is provided or generates a general description, calls Gemini API with video URI, handles errors.case "ask_about_youtube_video": { // Define question variable outside try block to access in catch let question: string | undefined; try { // Parse and validate arguments const args = AskAboutYoutubeVideoInputSchema.parse(request.params.arguments); const { youtube_url } = args; question = args.question; // Assign parsed question here console.error(`[INFO] Received request for ask_about_youtube_video: ${youtube_url}`); let finalPrompt: string; if (question) { // If a question is provided, use the Q&A prompt console.error(`[INFO] Question: "${question}"`); finalPrompt = `Please answer the following question based on the provided video content:\n\nQuestion: ${question}`; } else { // If no question, use a general description prompt console.error(`[INFO] No question provided, generating general description.`); finalPrompt = "Describe this video content in detail."; } // Call Gemini API using the helper function const answerOrDescription = await callGeminiApi(finalPrompt, { mimeType: "video/youtube", fileUri: youtube_url, }); console.error(`[INFO] Successfully generated response (answer or description).`); // Return success response return { content: [{ type: "text", text: answerOrDescription }], }; } catch (error: any) { console.error(`[ERROR] Failed during ask_about_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 = question ? `Failed to answer the question based on the video.` : `Failed to generate description for the video.`; if (error.message) { errorMessage += ` Details: ${error.message}`; } return { content: [{ type: "text", text: errorMessage }], isError: true, }; } }
- src/index.ts:52-56 (schema)Zod input schema for the tool, validating youtube_url as URL and optional question.const AskAboutYoutubeVideoInputSchema = z.object({ youtube_url: z.string().url({ message: "Invalid YouTube URL provided." }), // Making question optional to handle general description requests as well question: z.string().optional().describe("Question about the video content. If omitted, a general description will be generated."), });
- src/index.ts:76-80 (registration)Tool registration in the ListTools response, including name, description, and input schema.{ name: "ask_about_youtube_video", description: "Answers a question about the video or provides a general description if no question is asked.", inputSchema: zodToJsonSchema(AskAboutYoutubeVideoInputSchema), // Schema updated to make question optional },