get_user_info
Retrieve Hacker News user profiles and submitted stories to analyze activity and contributions on the platform.
Instructions
Get user info from Hacker News, including the stories they've submitted
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_name | Yes | Username of the user | |
| num_stories | No | Number of stories to get, defaults to 10 |
Implementation Reference
- src/mcp_hn/hn.py:233-260 (handler)The core handler function implementing the get_user_info tool. Fetches user profile from HN API and appends their recent stories using a helper function.def get_user_info(user_name: str, num_stories: int = DEFAULT_NUM_STORIES) -> Dict: """ Fetches information about a Hacker News user and their recent submissions. Args: user_name: Username to fetch information for num_stories: Number of user's stories to include (default: 10) Returns: Dict containing user information and recent stories: { "id": str, # Username "created_at": str, # Account creation timestamp "karma": int, # User's karma points "about": str, # User's about text (may be null) "stories": list # List of user's recent story dictionaries } Raises: requests.exceptions.RequestException: If the API request fails """ url = f"{BASE_API_URL}/users/{user_name}" response = requests.get(url) response.raise_for_status() response = response.json() response["stories"] = _get_user_stories(user_name, num_stories) return response
- src/mcp_hn/server.py:36-53 (schema)JSON Schema defining the input parameters for the get_user_info tool: required 'user_name' (string) and optional 'num_stories' (integer).types.Tool( name="get_user_info", description="Get user info from Hacker News, including the stories they've submitted", inputSchema={ "type": "object", "properties": { "user_name": { "type": "string", "description": "Username of the user", }, "num_stories": { "type": "integer", "description": f"Number of stories to get, defaults to {DEFAULT_NUM_STORIES}", }, }, "required": ["user_name"], }, ),
- src/mcp_hn/server.py:113-117 (registration)Dispatch logic in the MCP server's call_tool handler that extracts arguments, calls the get_user_info function, and returns the JSON-formatted result as text content.elif name == "get_user_info": user_name = arguments.get("user_name") num_stories = arguments.get("num_stories", DEFAULT_NUM_STORIES) output = json.dumps(hn.get_user_info(user_name, num_stories), indent=2) return [types.TextContent(type="text", text=output)]
- src/mcp_hn/hn.py:214-231 (helper)Helper function called by get_user_info to retrieve and format the user's submitted stories.def _get_user_stories(user_name: str, num_stories: int = DEFAULT_NUM_STORIES) -> List[Dict]: """ Fetches stories submitted by a specific user. Args: user_name: Username whose stories to fetch num_stories: Number of stories to return (default: 10) Returns: List[Dict]: List of story dictionaries authored by the user Raises: requests.exceptions.RequestException: If the API request fails """ url = f"{BASE_API_URL}/search?tags=author_{user_name},story&hitsPerPage={num_stories}" response = requests.get(url) response.raise_for_status() return [_format_story_details(story) for story in response.json()["hits"]]