get_summary
Generate summaries of YouTube videos in multiple languages and lengths to quickly understand video content without watching the full video.
Instructions
Generate a summary of a YouTube video
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| language | No | en | |
| length | No | medium |
Implementation Reference
- src/youtube_translate_mcp/server.py:437-437 (registration)Registration of the 'get_summary' tool using the MCP server decorator.@mcp_server.tool(name="get_summary", description="Generate a summary of a YouTube video")
- The main handler function for the 'get_summary' tool. It validates inputs, processes the YouTube video URL to get a video ID, calls the YouTube Translate API to fetch the summary, handles errors, and returns the summary text.async def get_summary(url: str, language: str = "en", length: str = "medium") -> str: """Generate a summary of a YouTube video. This tool processes a video and generates a summary of its content in the specified language. It properly handles "processing" states by polling until completion rather than failing immediately. If the requested language is not available, it automatically requests a translation first. Args: url: The YouTube video URL language: Language code for the summary (e.g., "en", "fr") length: Length of the summary ("short", "medium", or "long") Returns: A summary of the video content """ logger.info(f"Getting summary for URL: {url}, language: {language}, length: {length}") # Validate length if length not in ["short", "medium", "long"]: error_msg = f"Invalid length: {length}. Must be 'short', 'medium', or 'long'." logger.error(error_msg) return f"Error: {error_msg}" # Process the video to ensure it's ready success, video_id, error_message = await process_video(url) if not success: logger.error(f"Failed to process video: {error_message}") return f"Error: {error_message}" # Get the summary from the API summary_response = await make_yt_api_request( f"/api/videos/{video_id}/summary", params={"language": language, "length": length} ) if not summary_response: error_msg = f"Failed to retrieve summary for language: {language}, length: {length}" logger.error(error_msg) return f"Error: {error_msg}" # Check if the response is a JSON object with the summary if isinstance(summary_response, dict) and "summary" in summary_response: return summary_response["summary"] elif isinstance(summary_response, dict) and "error" in summary_response: error_msg = summary_response["error"] logger.error(f"API error: {error_msg}") return f"Error: {error_msg}" else: error_msg = "Unexpected response format from API." logger.error(error_msg) return f"Error: {error_msg}"
- Input schema defined by function parameters: url (str, required), language (str, default 'en'), length (str, default 'medium'). Output: str (the summary).async def get_summary(url: str, language: str = "en", length: str = "medium") -> str: