Skip to main content
Glama
qinyuanpei

Weibo MCP Server

get_profile

Retrieve profile details for a Weibo user by providing their unique identifier, enabling access to user information from the platform.

Instructions

Get a Weibo user's profile information.

Returns:
    dict: Dictionary containing user profile information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uidYesThe unique identifier of the Weibo user

Implementation Reference

  • MCP tool handler for 'get_profile', registers the tool and executes by calling WeiboCrawler.get_profile(uid). Defines input schema via Annotated Field.
    async def get_profile(
        uid: Annotated[int, Field(description="The unique identifier of the Weibo user")],
        ctx: Context
        ) -> dict:
        """
        Get a Weibo user's profile information.
    
        Returns:
            dict: Dictionary containing user profile information
        """
        return await crawler.get_profile(uid)
  • Pydantic BaseModel defining the UserProfile schema, used for output validation and typing in the get_profile implementation.
    class UserProfile(BaseModel):
        """
        Data model for a Weibo user's profile information.
        
        Attributes:
            id (int): User's unique identifier
            screen_name (str): User's display name
            profile_image_url (str): URL to user's profile image
            profile_url (str): URL to user's Weibo profile page
            description (str): User's profile description
            follow_count (int): Number of users the user is following
            followers_count (str): Number of followers (as string)
            avatar_hd (str): URL to user's high-resolution avatar image
            verified (bool): Whether the user is verified
            verified_reason (str): Reason for verification
            gender (str): User's gender
        """
        id: int = Field()
        screen_name: str = Field()
        profile_image_url: str = Field()
        profile_url: str = Field()
        description: str = Field()
        follow_count: int = Field()
        followers_count: str = Field()
        avatar_hd: str = Field()
        verified: bool = Field()
        verified_reason: str = Field()
        gender: str = Field()
  • Core helper function in WeiboCrawler that implements the profile fetching logic from Weibo API using PROFILE_URL and parsing with _to_user_profile.
    async def get_profile(self, uid: int) -> UserProfile:
        """
        Extract user profile information from Weibo.
    
        Args:
            uid (int): The unique identifier of the Weibo user
    
        Returns:
            UserProfile: User profile information or empty dict if extraction fails
        """
        async with httpx.AsyncClient() as client:
            try:
                response = await client.get(PROFILE_URL.format(userId=uid), headers=DEFAULT_HEADERS)
                result = response.json()
                return self._to_user_profile(result["data"]["userInfo"])
            except httpx.HTTPError:
                self.logger.error(
                    f"Unable to eextract profile for uid '{str(uid)}'", exc_info=True)
                return {}
  • Supporting helper that maps raw API user data to the UserProfile Pydantic model.
    def _to_user_profile(self, user: dict) -> UserProfile:
        """
        Convert raw user data to UserProfile object.
    
        Args:
            user (dict): Raw user data from Weibo API
    
        Returns:
            UserProfile: Formatted user profile information
        """
        return UserProfile(
            id = user['id'],
            screen_name = user['screen_name'],
            profile_image_url = user['profile_image_url'],
            profile_url = user['profile_url'], 
            description = user.get('description', ''),
            follow_count = user.get('follow_count', 0),
            followers_count = user.get('followers_count', ''),
            avatar_hd = user.get('avatar_hd', ''),
            verified = user.get('verified', False),
            verified_reason = user.get('verified_reason', ''),
            gender = user.get('gender', '')
        )
  • Constant URL template used in get_profile to fetch user profile data from Weibo API.
    # URL template for fetching user profile information
    # {userId} will be replaced with the actual user ID
    PROFILE_URL = 'https://m.weibo.cn/api/container/getIndex?type=uid&value={userId}'

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