Skip to main content
Glama

get_trendings

Retrieve real-time trending topics from Weibo using a customizable limit for hot search items. Ideal for monitoring popular discussions and analyzing social media trends.

Instructions

Get the current hot search topics on Weibo. Returns: list[dict]: List of dictionaries containing hot search items

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of hot search items to return, defaults to 15

Implementation Reference

  • MCP tool handler for get_trendings including registration via @mcp.tool() decorator and input schema via Annotated Field. Delegates to WeiboCrawler implementation.
    @mcp.tool() async def get_trendings( ctx: Context, limit: Annotated[int, Field(description="Maximum number of hot search items to return, defaults to 15", default=15)] = 15 ) -> list[dict]: """ Get the current hot search topics on Weibo. Returns: list[dict]: List of dictionaries containing hot search items """ return await crawler.get_trendings(limit)
  • Core implementation in WeiboCrawler that fetches and parses Weibo hot search trends using HTTP requests.
    async def get_trendings(self, limit: int = 15) -> list[TrendingItem]: """ Get a list of hot search items from Weibo. Args: limit (int): Maximum number of hot search items to return, defaults to 15 Returns: list[HotSearchItem]: List of HotSearchItem objects containing hot search information """ try: params = { 'containerid': f'106003type=25&t=3&disable_hot=1&filter_type=realtimehot', } encoded_params = urlencode(params) async with httpx.AsyncClient() as client: response = await client.get(f'{SEARCH_URL}?{encoded_params}', headers=DEFAULT_HEADERS) data = response.json() cards = data.get('data', {}).get('cards', []) if not cards: return [] hot_search_card = next((card for card in cards if 'card_group' in card and isinstance(card['card_group'], list)), None) if not hot_search_card or 'card_group' not in hot_search_card: return [] items = [item for item in hot_search_card['card_group'] if item.get('desc')] trending_items = list(map(lambda pair: self._to_trending_item({**pair[1], 'id': pair[0]}), enumerate(items[:limit]))) return trending_items except httpx.HTTPError: self.logger.error( 'Unable to fetch Weibo hot search list', exc_info=True) return []
  • Pydantic BaseModel schema for TrendingItem used as return type in the crawler method.
    class TrendingItem(BaseModel): """ Data model for a single hot search item on Weibo. Attributes: id (int): Rank of the search item trending (int): Popularity value of the hot search item description (str): The description of hot search item url (str): URL to the hot search item """ id: int = Field() trending: int = Field() description: str = Field() url: str
  • Helper function to parse and construct TrendingItem from raw Weibo API response data.
    def _to_trending_item(self, item: dict) -> TrendingItem: """ Convert raw hot search item data to HotSearchItem object. Args: item (dict): Raw hot search item data from Weibo API Returns: HotSearchItem: Formatted hot search item information """ extr_values = re.findall(r'\d+', str(item.get('desc_extr'))) trending = int(extr_values[0]) if extr_values else 0 return TrendingItem( id=item['id'], trending=trending, description=item['desc'], url=item.get('scheme', '') )

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/qinyuanpei/mcp-server-weibo'

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