Skip to main content
Glama

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
NameRequiredDescriptionDefault
user_nameYesUsername of the user
num_storiesNoNumber of stories to get, defaults to 10

Implementation Reference

  • 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
  • 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"], }, ),
  • 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)]
  • 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"]]

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/erithwik/mcp-hn'

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