Skip to main content
Glama
imprvhub

mcp-claude-hackernews

hn_comments

Retrieve comments for a Hacker News story using its story ID or its index from the last fetched list.

Instructions

Get comments for a story (by story ID or index from last story list)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
story_idNoThe ID of the story to get comments for
story_indexNoThe index (1-based) of the story from the last fetched list

Implementation Reference

  • index.ts:208-225 (registration)
    Tool registration for hn_comments in ListToolsRequestSchema handler, defining name, description, and inputSchema (story_id or story_index).
    {
      name: "hn_comments",
      description: "Get comments for a story (by story ID or index from last story list)",
      inputSchema: {
        type: "object",
        properties: {
          story_id: {
            type: "number",
            description: "The ID of the story to get comments for"
          },
          story_index: {
            type: "number",
            description: "The index (1-based) of the story from the last fetched list",
            minimum: 1
          }
        }
      }
    }
  • Main handler logic for hn_comments: resolves story by ID or index, fetches story details, retrieves comments via api.getComments(), formats them, and returns response.
    if (name === "hn_comments") {
      const storyId = typeof args?.story_id === 'number' ? args.story_id : NaN;
      const storyIndex = typeof args?.story_index === 'number' ? args.story_index : NaN;
    
      if (isNaN(storyId) && isNaN(storyIndex)) {
        throw new Error('Either a story ID or a story index is required');
      }
    
      let targetStoryId: number;
      if (!isNaN(storyId)) {
        targetStoryId = storyId;
      } else if (!isNaN(storyIndex) && storyIndex > 0 && storyIndex <= lastStoriesList.length) {
        targetStoryId = lastStoriesList[storyIndex - 1].id;
      } else {
        throw new Error('Invalid story index or ID provided');
      }
    
      if (isNaN(targetStoryId)) {
        throw new Error('Story ID must be a number');
      }
    
      const story = await api.getItemDetails(targetStoryId) as Story | null;
      if (!story) {
        throw new Error(`Story with ID ${targetStoryId} not found`);
      }
    
      if (!story.kids || story.kids.length === 0) {
        return {
          content: [
            {
              type: "text",
              text: `No comments found for story "${story.title}" (ID: ${story.id})`
            }
          ]
        };
      }
    
      const comments = await api.getComments(story.kids);
      const formattedComments = comments.map(comment => ({
        id: comment.id,
        by: comment.by,
        time: api.formatTime(comment.time),
        text: api.cleanText(comment.text),
        replies: comment.kids ? comment.kids.length : 0
      }));
    
      return {
        content: [
          {
            type: "text",
            text: formatCommentsAsText(story.title, formattedComments)
          }
        ]
      };
    }
  • FormattedComment interface defining the output structure for comments (id, by, time, text, replies).
    interface FormattedComment {
      id: number;
      by: string;
      time: string;
      text: string;
      replies: number;
    }
  • Comment interface representing raw API comment data from Hacker News.
    interface Comment {
      id: number;
      by: string;
      time: number;
      text: string;
      kids?: number[];
    }
  • formatCommentsAsText helper function that formats the comment list into a readable text output for the response.
    function formatCommentsAsText(storyTitle: string, comments: FormattedComment[]): string {
      if (!comments || comments.length === 0) {
        return "No comments found.";
      }
      
      const header = `Comments for "${storyTitle}" (Total: ${comments.length}):\n`;
      
      const formattedComments = comments.map((comment, index) => {
        return `${index + 1}. Comment by ${comment.by} at ${comment.time}:
       "${comment.text}"
       ${comment.replies > 0 ? `(${comment.replies} replies)` : '(no replies)'}
       ------------------------------`;
      }).join('\n\n');
      
      return header + '\n' + formattedComments;
    }
Behavior3/5

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

No annotations are provided, so the description bears full burden. It discloses the basic functionality (getting comments) and the two ways to identify the story, but lacks details on pagination, ordering, or rate limits. The behavior is simple enough to be partially transparent.

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 concise sentence with no unnecessary words, efficiently conveying the tool's purpose and usage.

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

Completeness4/5

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

For a simple tool with two parameters and no output schema, the description covers the key points: what it does and how to specify the story. It could mention the return format (e.g., list of comments) but is largely complete given the tool's simplicity.

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

Parameters4/5

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

Schema coverage is 100% with descriptions for both parameters. The tool description adds value by explaining that story_index refers to the last fetched list and that either parameter can be used, which is not explicit in the schema.

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 'Get comments for a story' with a specific verb and resource, and distinguishes itself from sibling tools like hn_best or hn_story by focusing on comments. It also specifies two identification methods (story ID or index from last list).

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 tells when to use (to get comments for a story) and how to specify the story. It implies the context (using last fetched list for index) but does not explicitly state when not to use or provide alternatives, though sibling tools cover other story actions.

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