Skip to main content
Glama
imprvhub

mcp-claude-hackernews

hn_story

Retrieve details for a Hacker News story using its story ID.

Instructions

Get details for a specific story by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
story_idYesThe ID of the story to fetch

Implementation Reference

  • index.ts:194-207 (registration)
    Registration of the hn_story tool in the ListToolsRequestSchema handler. Defines the tool name, description, and input schema requiring a story_id number.
    {
      name: "hn_story",
      description: "Get details for a specific story by ID",
      inputSchema: {
        type: "object",
        properties: {
          story_id: {
            type: "number",
            description: "The ID of the story to fetch"
          }
        },
        required: ["story_id"]
      }
    },
  • Handler for the hn_story tool inside the CallToolRequestSchema. It validates the story_id argument, fetches the story via api.getItemDetails(), formats it using formatStoryAsText(), and returns the result.
    if (name === "hn_story") {
      const storyId = typeof args?.story_id === 'number' ? args.story_id : NaN;
      if (isNaN(storyId)) {
        throw new Error('Story ID must be a number');
      }
      const story = await api.getItemDetails(storyId) as Story | null;
      if (!story) {
        throw new Error(`Story with ID ${storyId} not found`);
      }
      const formattedStory = {
        id: story.id,
        title: story.title,
        by: story.by,
        time: api.formatTime(story.time),
        url: story.url,
        text: story.text ? api.cleanText(story.text) : '',
        score: story.score,
        commentsCount: story.kids?.length || 0
      };
      return {
        content: [
          {
            type: "text",
            text: formatStoryAsText(formattedStory)
          }
        ]
      };
    }
  • Helper methods used by the hn_story handler: getItemDetails() fetches a story by ID from the Firebase API, formatTime() converts timestamps, and cleanText() sanitizes HTML entities.
    async getItemDetails(itemId: number): Promise<Story | Comment | null> {
      try {
        const response = await axios.get(`${baseUrl}/item/${itemId}.json`);
        return response.data;
      } catch (error) {
        console.error(`Error fetching item ${itemId}:`, error);
        return null;
      }
    }
    
    async getComments(commentIds: number[] = []): Promise<Comment[]> {
      if (!commentIds || commentIds.length === 0) {
        return [];
      }
      try {
        const commentPromises = commentIds.map(id => this.getItemDetails(id));
        const comments = await Promise.all(commentPromises);
        return comments.filter((comment): comment is Comment => comment !== null);
      } catch (error) {
        console.error('Failed to load comments:', error);
        return [];
      }
    }
    
    formatTime(timestamp: number): string {
      const date = new Date(timestamp * 1000);
      return date.toLocaleString();
    }
    
    cleanText(text: string | undefined): string {
      if (!text) return '';
      return text
        .replace(/>/g, '>')
        .replace(/</g, '<')
        .replace(/&/g, '&')
        .replace(/"/g, '"')
        .replace(/<[^>]*>?/gm, '');
    }
  • The formatStoryAsText() helper function that formats a FormattedStory object into a human-readable text block for the tool response.
    function formatStoryAsText(story: FormattedStory): string {
      if (!story) {
        return "Story not found.";
      }
      
      let result = `Title: ${story.title}
    ID: ${story.id}
    By: ${story.by}
    Published: ${story.time}
    Score: ${story.score}
    Comments: ${story.commentsCount}
    URL: ${story.url || 'N/A'}`;
    
      if (story.text) {
        result += `\n\nContent:\n${story.text}`;
      }
      
      return result;
    }
  • index.ts:8-17 (schema)
    The Story interface and FormattedStory interface that define the shape of data used by the hn_story handler.
    interface Story {
      id: number;
      title: string;
      by: string;
      time: number;
      url?: string;
      score: number;
      kids?: number[];
      text?: string;
      type: string;
Behavior3/5

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

No annotations are provided, so the description is the sole source. It indicates a read operation ('get details'), but does not disclose error behavior, rate limits, or response structure. Basic transparency is achieved.

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, well-structured sentence with no extraneous words or filler. It is optimally concise.

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?

For a simple one-parameter tool with no output schema, the description provides minimal but sufficient context. It lacks detail on what 'details' includes, which is acceptable for a simple fetch.

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 coverage is 100% as the only parameter 'story_id' has a description. The description 'by ID' aligns with the parameter, adding no new meaning. Baseline score applies.

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

Purpose5/5

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

The description clearly states the action ('get details'), the resource ('story'), and the identification method ('by ID'). It distinctly differentiates from sibling tools (lists like hn_best, hn_top) which fetch multiple items.

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 implies usage when a specific story ID is known, but does not explicitly exclude cases like fetching stories in bulk or provide alternatives. Sibling tool names indirectly suggest other 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/imprvhub/mcp-claude-hackernews'

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