Skip to main content
Glama

get_trending_videos

Retrieve trending YouTube videos by region and specify the number of results. Use this tool to analyze or discover popular content across different geographic areas.

Instructions

Get trending videos on YouTube by region

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_resultsNo
region_codeNo

Implementation Reference

  • The MCP tool handler for 'get_trending_videos'. This is the function that executes the tool logic when called via MCP. It formats the raw API response into a user-friendly structure with video details and URLs.
    @mcp.tool( name="get_trending_videos", description="Get trending videos on YouTube by region", ) async def get_trending_videos(region_code: str = None, max_results: int = 5) -> Dict[str, Any]: """ Get trending videos on YouTube by region Args: region_code (str): ISO country code (default: 'US') max_results (int): Maximum number of videos to return (default: 10) Returns: Dict[str, Any]: Trending videos data """ try: # 이제 region_code 처리는 YouTubeService 클래스 내부에서 처리합니다 trending_data = youtube_service.get_trending_videos(region_code, max_results) # Format the response formatted_videos = [] for video in trending_data.get('items', []): formatted_videos.append({ 'id': video.get('id'), 'title': video.get('snippet', {}).get('title'), 'description': video.get('snippet', {}).get('description'), 'publishedAt': video.get('snippet', {}).get('publishedAt'), 'channelId': video.get('snippet', {}).get('channelId'), 'channelTitle': video.get('snippet', {}).get('channelTitle'), 'viewCount': video.get('statistics', {}).get('viewCount'), 'likeCount': video.get('statistics', {}).get('likeCount'), 'commentCount': video.get('statistics', {}).get('commentCount'), 'thumbnails': video.get('snippet', {}).get('thumbnails'), 'url': f"https://www.youtube.com/watch?v={video.get('id')}" }) return { 'videos': formatted_videos, 'region': region_code, 'totalResults': len(formatted_videos) } except Exception as e: logger.exception(f"Error in get_trending_videos: {e}") return {'error': str(e)}
  • The core helper method in YouTubeService class that performs the actual YouTube API call to fetch trending (mostPopular) videos for a given region code. Handles region normalization and API parameters.
    def get_trending_videos(self, region_code: Optional[str] = 'ko', max_results: Optional[int] = 5) -> Dict[str, Any]: """ Get trending videos for a specific region """ try: params = { 'part': 'snippet,contentDetails,statistics', 'chart': 'mostPopular', 'maxResults': max_results } if region_code: # Normalize region code to ensure valid ISO country code format normalized_code = self.normalize_region_code(region_code) params['regionCode'] = normalized_code response = self.youtube.videos().list(**params).execute() return response except HttpError as e: logger.error(f"Error getting trending videos: {e}") raise e
  • server.py:686-687 (registration)
    The tool is listed in the 'available-youtube-tools' resource, indicating its registration and providing a brief description.
    {"name": "get_trending_videos", "description": "Get trending videos on YouTube by region"}, {"name": "get_video_enhanced_transcript", "description": "Advanced transcript extraction tool with filtering, search, and multi-video capabilities. Provides rich transcript data for detailed analysis and processing. Features: 1) Extract transcripts from multiple videos; 2) Filter by time ranges; 3) Search within transcripts; 4) Segment transcripts; 5) Format output in different ways; 6) Include video metadata."}
  • Input schema defined in the docstring of the handler, specifying parameters region_code and max_results with types and defaults.
    Get trending videos on YouTube by region Args: region_code (str): ISO country code (default: 'US') max_results (int): Maximum number of videos to return (default: 10) Returns: Dict[str, Any]: Trending videos data """

Other Tools

Related 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/jikime/py-mcp-youtube-toolbox'

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