get_profile
Retrieve detailed Weibo user profile information by providing the unique identifier (UID). Use this tool to access key user data for analysis or integration purposes.
Instructions
Get a Weibo user's profile information.
Returns:
dict: Dictionary containing user profile information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | The unique identifier of the Weibo user |
Implementation Reference
- src/mcp_server_weibo/server.py:29-41 (handler)MCP tool handler and registration for 'get_profile'. Decorated with @mcp.tool(), defines input schema with Annotated[int, Field()], delegates execution to WeiboCrawler.get_profile(uid).@mcp.tool() 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)
- src/mcp_server_weibo/schemas.py:4-31 (schema)Pydantic BaseModel UserProfile defining the structure and validation for the output of get_profile tool.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()
- src/mcp_server_weibo/weibo.py:18-37 (helper)Implementation of profile fetching logic in WeiboCrawler class, makes HTTP request to Weibo API and parses response into UserProfile using _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 {}