get_video_info
Retrieve detailed metadata for YouTube videos including description, tags, and statistics by providing the video ID. Supports JSON or Markdown output formats.
Instructions
Get detailed information about a specific YouTube video.
Args: video_id: YouTube video ID (11 characters, e.g., "dQw4w9WgXcQ") output_format: Output format - "json" or "markdown" (default: "json")
Returns: Detailed video information including description, tags, and statistics
Example: get_video_info("dQw4w9WgXcQ", output_format="markdown")
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| video_id | Yes | ||
| output_format | No | json |
Implementation Reference
- The implementation of the 'get_video_info' MCP tool, which validates the video ID, fetches details from the search provider, and formats the response.
@mcp.tool() async def get_video_info(video_id: str, output_format: str = "json") -> str: """ Get detailed information about a specific YouTube video. Args: video_id: YouTube video ID (11 characters, e.g., "dQw4w9WgXcQ") output_format: Output format - "json" or "markdown" (default: "json") Returns: Detailed video information including description, tags, and statistics Example: get_video_info("dQw4w9WgXcQ", output_format="markdown") """ try: logger.info(f"Get video info request: video_id='{video_id}'") # Validate video ID if not validate_video_id(video_id): raise InvalidQueryError(f"Invalid video ID format: {video_id}") # Get video details provider = get_search_provider() details = await provider.get_video_details(video_id) # Format results formatter = get_formatter(output_format) result = formatter.format_video_details(details) logger.info(f"Retrieved info for: {details.title}") return result except InvalidQueryError as e: logger.warning(f"Invalid video ID: {e.message}") return json.dumps({"error": "invalid_video_id", "message": e.message}) except VideoNotFoundError as e: logger.warning(f"Video not found: {e.message}") return json.dumps( {"error": "video_not_found", "message": "Video not found or unavailable."} ) except NetworkError as e: logger.error(f"Network error: {e.message}") return json.dumps( { "error": "network_error", "message": "Failed to connect to YouTube.", "details": e.message, } ) except Exception: logger.exception("Unexpected error in get_video_info") return json.dumps( {"error": "internal_error", "message": "An unexpected error occurred."} )