get_user_info
Retrieve user details and submitted stories from Hacker News by specifying a username and optional story count.
Instructions
Get user info from Hacker News, including the stories they've submitted
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| num_stories | No | Number of stories to get, defaults to 10 | |
| user_name | Yes | Username of the user |
Implementation Reference
- src/mcp_hn/hn.py:233-260 (handler)Core implementation of get_user_info tool: fetches HN user profile data and their recent story submissions via API calls.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 (registration)Registers the get_user_info tool with MCP server, including name, description, and input schema.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 (handler)MCP server dispatch handler for get_user_info tool call, invokes hn.get_user_info and formats output as JSON.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/server.py:39-52 (schema)JSON schema defining input parameters for get_user_info tool: required user_name (string), optional num_stories (integer).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"], },