Skip to main content
Glama
imprvhub

mcp-claude-hackernews

hn_comments

Retrieve comments for a Hacker News story by specifying its ID or index from the latest fetched story list for quick access to discussions.

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)
    Registration of the hn_comments tool including its name, description, and input schema in the ListToolsRequestSchema handler.
    {
      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
          }
        }
      }
    }
  • The handler logic for hn_comments tool call, which resolves story ID, fetches story and comments, formats them, and returns text content.
    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)
          }
        ]
      };
    }
  • Helper method in HackerNewsAPI to fetch multiple comments by their IDs.
    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 [];
      }
    }
  • Helper function to format the story title and list of comments into a readable text output.
    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;
    }
  • Input schema definition for hn_comments tool parameters.
      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
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states what the tool does ('Get comments') but lacks behavioral details such as whether it's read-only (implied by 'Get'), potential rate limits, authentication needs, error handling, or what the output format looks like (no output schema). This leaves significant gaps for an agent to understand how to interact with it effectively.

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 ('Get comments for a story') and includes key usage details without any wasted words. Every part earns its place, making it highly concise and well-structured.

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 moderate complexity (2 parameters, no output schema, no annotations), the description is adequate but incomplete. It covers the purpose and basic parameter context, but lacks behavioral transparency and output details, which are crucial for an agent to use it correctly without annotations or output schema.

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%, with clear descriptions for both parameters (story_id and story_index). The description adds minimal value beyond the schema by mentioning 'story ID or index from last story list', which aligns with but doesn't expand on the schema details. Baseline 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 verb 'Get' and the resource 'comments for a story', specifying it can be retrieved by story ID or index from a previous list. It distinguishes itself from sibling tools (hn_best, hn_latest, hn_story, hn_top) by focusing on comments rather than stories, but doesn't explicitly contrast with them in the description.

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

Usage Guidelines3/5

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

The description implies usage by mentioning 'story ID or index from last story list', suggesting it should be used when you have a story identifier from a prior operation. However, it doesn't provide explicit guidance on when to use this tool versus alternatives (e.g., for story details vs. comments) or any exclusions, leaving some ambiguity.

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

Related 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