Skip to main content
Glama
erithwik

mcp-hn

by erithwik

get_story_info

Retrieve detailed Hacker News story information including comments by providing a story ID.

Instructions

Get detailed story info from Hacker News, including the comments

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
story_idNoStory ID

Implementation Reference

  • Primary handler function implementing the get_story_info tool logic: fetches raw story data and formats it into a structured dict with title, url, author, points, and nested comments up to depth 2.
    def get_story_info(story_id: int) -> Dict:
        """
        Fetches detailed information about a specific story including comments.
    
        Args:
            story_id: The ID of the story to fetch
    
        Returns:
            Dict containing full story details:
            {
                "id": int,          # Story ID
                "title": str,       # Story title
                "url": str,         # Story URL (may be null for text posts)
                "author": str,      # Author username
                "points": int,      # Points (may be null)
                "comments": list    # Nested list of comment dictionaries
            }
    
        Raises:
            requests.exceptions.RequestException: If the API request fails
        """
        story = _get_story_info(story_id)
        return _format_story_details(story, basic=False)
  • Core helper function that performs the HTTP request to the Hacker News Algolia API to retrieve raw story information.
    def _get_story_info(story_id: int) -> Dict:
        """
        Fetches detailed information about a Hacker News story.
    
        Args:
            story_id: The ID of the story to fetch
    
        Returns:
            Dict: Raw story data from the HN API including title, author, points, url and comments
    
        Raises:
            requests.exceptions.RequestException: If the API request fails
        """
        url = f"{BASE_API_URL}/items/{story_id}"
        response = requests.get(url)
        response.raise_for_status()
        return response.json()
  • Helper function to format story details, handling both IDs and dicts, and optionally expanding comments with recursive formatting.
    def _format_story_details(story: Union[Dict, int], basic: bool = True) -> Dict:
        """
        Formats a story's details into a standardized dictionary structure.
    
        Args:
            story: Either a story ID or dictionary containing story data
            basic: If True, excludes comments. If False, includes formatted comments to depth of 2
    
        Returns:
            Dict with the following structure:
            {
                "id": int,          # Story ID
                "title": str,       # Story title if present
                "url": str,         # Story URL if present
                "author": str,      # Author username
                "points": int,      # Points (may be null)
                "comments": list    # List of comment dicts (only if basic=False)
            }
    
        The function handles both raw story IDs and story dictionaries, fetching additional
        data if needed. For non-basic requests, it ensures comments are properly formatted.
        """
        if isinstance(story, int):
            story = _get_story_info(story)
        output = {
            "id": story["story_id"],
            "author": story["author"],
        }
        if "title" in story:
            output["title"] = story["title"]
        if "points" in story:
            output["points"] = story["points"]
        if "url" in story:
            output["url"] = story["url"]
        if not basic:
            if _validate_comments_is_list_of_dicts(story["children"]):
                story = _get_story_info(story["story_id"])
            output["comments"] = [
                _format_comment_details(child) for child in story["children"]
            ]
        return output
  • JSON Schema definition for the tool input: requires a single 'story_id' integer property.
    types.Tool(
        name="get_story_info",
        description="Get detailed story info from Hacker News, including the comments",
        inputSchema={
            "type": "object",
            "properties": {
                "story_id": {
                    "type": "integer",
                    "description": "Story ID",
                },
            },
        },
    ),
  • MCP server registration and dispatch logic for the tool: parses input, calls the handler, and returns JSON-formatted result.
    elif name == "get_story_info":
        story_id = int(arguments.get("story_id"))
        output = json.dumps(hn.get_story_info(story_id), indent=2)
        return [types.TextContent(type="text", text=output)]
Behavior2/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 states the tool retrieves data (implying read-only) and includes comments, but doesn't cover aspects like rate limits, authentication needs, error conditions, or response format. This is a significant gap for a tool with zero annotation coverage.

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 a single, efficient sentence that front-loads the core purpose. Every word earns its place, with no redundant or unnecessary information.

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 the tool's low complexity (1 parameter, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks behavioral details and usage guidance. Without annotations or output schema, more context would be beneficial for a complete understanding.

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 already documents the 'story_id' parameter. The description doesn't add any meaning beyond what the schema provides, such as explaining what a story ID is or where to find it. Baseline 3 is appropriate when 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 verb ('Get') and resource ('detailed story info from Hacker News'), and specifies the inclusion of comments. However, it doesn't explicitly differentiate from sibling tools like 'get_stories' or 'search_stories' beyond mentioning 'detailed' info.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like 'get_stories' or 'search_stories'. The description implies it's for detailed story info with comments, but doesn't specify prerequisites, exclusions, or comparative use cases.

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