UNPKG

@mixio-pro/kalaasetu-mcp

Version:

A powerful Model Context Protocol server providing AI tools for content generation and analysis

53 lines (46 loc) 1.92 kB
import { z } from "zod"; import { GoogleGenAI } from "@google/genai"; const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY || "", }); export const analyzeYoutubeVideo = { name: "analyzeYoutubeVideo", description: "Analyze YouTube videos for content using the correct GenAI JS API approach with FileData fileUri. Perfect for extracting stock media content, analyzing video content, or getting descriptions of YouTube videos", parameters: z.object({ youtube_url: z.string().describe("YouTube video URL to analyze (format: https://www.youtube.com/watch?v=VIDEO_ID)"), prompt: z.string().describe("Analysis prompt or question about the YouTube video content"), }), execute: async (args: { youtube_url: string; prompt: string }) => { try { // Validate YouTube URL format if (!args.youtube_url || (!args.youtube_url.includes('youtube.com/watch') && !args.youtube_url.includes('youtu.be'))) { throw new Error("Invalid YouTube URL format. Expected: https://www.youtube.com/watch?v=VIDEO_ID"); } // Create content using the correct FileData approach with fileUri const response = await ai.models.generateContent({ model: 'models/gemini-2.5-flash', contents: { parts: [ { fileData: { fileUri: args.youtube_url } }, { text: args.prompt } ] } }); let result = ""; if (response.candidates && response.candidates[0]?.content?.parts) { for (const part of response.candidates[0].content.parts) { if (part.text) { result += part.text; } } } return result || "YouTube video analysis completed but no text response received"; } catch (error: any) { throw new Error(`YouTube video analysis failed: ${error.message}`); } }, };