Skip to main content
Glama
erithwik

mcp-hn

by erithwik

get_stories

Retrieve Hacker News stories by type (top, new, ask_hn, show_hn) without comments. Specify story type and quantity to fetch content.

Instructions

Get stories from Hacker News. The options are top, new, ask_hn, show_hn for types of stories. This doesn't include the comments. Use get_story_info to get the comments.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
story_typeNoType of stories to get, one of: `top`, `new`, `ask_hn`, `show_hn`
num_storiesNoNumber of stories to get

Implementation Reference

  • Core implementation of the get_stories tool. Fetches Hacker News stories of specified type using Algolia API, validates input, maps to API endpoints, retrieves data, formats using _format_story_details, and returns list of stories.
    def get_stories(story_type: str, num_stories: int = DEFAULT_NUM_STORIES):
        """
        Fetches and formats a list of Hacker News stories of the specified type.
    
        Args:
            story_type: Category of stories to fetch. Must be one of:
                       - "top": Front page stories
                       - "new": Most recent stories
                       - "ask_hn": Ask HN posts
                       - "show_hn": Show HN posts
            num_stories: Number of stories to return (default: 10)
    
        Returns:
            List[Dict]: List of story dictionaries, each containing:
            {
                "id": int,          # Story ID
                "title": str,       # Story title
                "url": str,         # Story URL
                "author": str,      # Author username
                "points": int,      # Points (may be null)
            }
    
        Raises:
            ValueError: If story_type is not one of the valid options
            requests.exceptions.RequestException: If the API request fails
        """
        story_type = story_type.lower().strip()
        if story_type not in ["top", "new", "ask_hn", "show_hn"]:
            raise ValueError("story_type must be one of: top, new, ask_hn, show_hn")
    
        # Map story type to appropriate API parameters
        api_params = {
            "top": {"endpoint": "search", "tags": "front_page"},
            "new": {"endpoint": "search_by_date", "tags": "story"},
            "ask_hn": {"endpoint": "search", "tags": "ask_hn"},
            "show_hn": {"endpoint": "search", "tags": "show_hn"}
        }
    
        params = api_params[story_type]
        url = f"{BASE_API_URL}/{params['endpoint']}?tags={params['tags']}&hitsPerPage={num_stories}"
        response = requests.get(url)
        response.raise_for_status()
        return [_format_story_details(story) for story in response.json()["hits"]]
  • JSON Schema defining the input parameters for the get_stories tool: story_type (string, enum-like via description) and optional num_stories (integer). Used for validation in MCP.
    inputSchema={
        "type": "object",
        "properties": {
            "story_type": {
                "type": "string",
                "description": "Type of stories to get, one of: `top`, `new`, `ask_hn`, `show_hn`",
            },
            "num_stories": {
                "type": "integer",
                "description": "Number of stories to get",
            },
        },
    },
  • MCP tool registration for get_stories in the server's list_tools handler, including name, description, and input schema.
    types.Tool(
        name="get_stories",
        description="Get stories from Hacker News. The options are `top`, `new`, `ask_hn`, `show_hn` for types of stories. This doesn't include the comments. Use `get_story_info` to get the comments.",
        inputSchema={
            "type": "object",
            "properties": {
                "story_type": {
                    "type": "string",
                    "description": "Type of stories to get, one of: `top`, `new`, `ask_hn`, `show_hn`",
                },
                "num_stories": {
                    "type": "integer",
                    "description": "Number of stories to get",
                },
            },
        },
    ),
  • Dispatch logic in the MCP server's call_tool handler that extracts arguments, calls the hn.get_stories implementation, and formats output as JSON.
    if name == "get_stories":
        story_type = arguments.get("story_type", "top")
        num_stories = arguments.get("num_stories", DEFAULT_NUM_STORIES)
        output = hn.get_stories(story_type, num_stories)
        return [types.TextContent(type="text", text=json.dumps(output, indent=2))]
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It clarifies that comments are excluded and mentions story types, but lacks details on rate limits, authentication needs, pagination, or response format. It adds some context but is incomplete for a tool with no annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and well-structured with two sentences: the first states purpose and parameters, the second provides usage guidance. Every sentence adds value without redundancy, making it front-loaded and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and 100% schema coverage, the description is adequate but has gaps. It covers purpose and basic usage but lacks behavioral details like response format or error handling. It's minimal viable for a read-only tool but could be more complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents both parameters. The description adds no additional parameter semantics beyond what's in the schema (e.g., no examples, constraints, or format details). Baseline score of 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get stories from Hacker News' with specific story types listed. It distinguishes from sibling 'get_story_info' by noting 'This doesn't include the comments.' However, it doesn't differentiate from 'search_stories' or 'get_user_info', keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear usage context: it specifies when to use this tool (for story types like 'top', 'new', etc.) and explicitly states when not to use it ('This doesn't include the comments. Use `get_story_info` to get the comments.'). It doesn't mention alternatives like 'search_stories' or 'get_user_info', preventing a score of 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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