Skip to main content
Glama
devabdultech

Hacker News MCP Server

by devabdultech

getComments

Fetch comments for Hacker News stories to analyze discussions and user feedback. Retrieve threaded conversations by providing a story ID, with configurable limits for focused research.

Instructions

Get comments for a story

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
storyIdYesThe ID of the story
limitNoThe maximum number of comments to fetch

Implementation Reference

  • Handler for getComments tool: validates input, fetches story kids, retrieves top limit comments, formats and returns them as text.
    case "getComments": {
      const validatedArgs = validateInput(CommentsRequestSchema, args);
      const { storyId, limit = 30 } = validatedArgs;
      try {
        const story = await hnApi.getItem(storyId);
    
        if (!story || !story.kids || story.kids.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `No comments found for story ID: ${storyId}`,
              },
            ],
          };
        }
    
        const commentIds = story.kids.slice(0, limit);
        const comments = await hnApi.getItems(commentIds);
        const formattedComments = comments
          .filter((item) => item && item.type === "comment")
          .map(formatComment);
    
        if (formattedComments.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `No comments found for story ID: ${storyId}`,
              },
            ],
          };
        }
    
        const text =
          `Comments for Story ID: ${storyId}\n\n` +
          formattedComments
            .map(
              (comment, index) =>
                `${index + 1}. Comment by ${comment.by} (ID: ${
                  comment.id
                }):\n` + `   ${comment.text}\n\n`
            )
            .join("");
    
        return {
          content: [{ type: "text", text: text.trim() }],
        };
      } catch (err) {
        const error = err as Error;
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to fetch comments: ${error.message}`
        );
      }
    }
  • Input schema for getComments tool using Zod validation.
    export const CommentsRequestSchema = z.object({
      storyId: z.number().int().positive(),
      limit: z.number().int().min(1).max(100).default(30),
    });
  • src/index.ts:123-138 (registration)
    Tool registration in ListTools response, including name, description, and input schema.
    {
      name: "getComments",
      description: "Get comments for a story",
      inputSchema: {
        type: "object",
        properties: {
          storyId: { type: "number", description: "The ID of the story" },
          limit: {
            type: "number",
            description: "The maximum number of comments to fetch",
            default: 30,
          },
        },
        required: ["storyId"],
      },
    },
  • Helper function to format raw comment data into structured Comment object, used in getComments handler.
    export function formatComment(item: any): Comment {
      return {
        id: item.id,
        text: item.text || "",
        by: item.by || "deleted",
        time: item.time,
        parent: item.parent,
        kids: item.kids || [],
        type: "comment",
      };
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior1/5

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

No annotations provided; description does not disclose any behavioral details (pagination, sorting, error handling, etc.). This is insufficient for a tool that may be called by an AI agent.

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

Conciseness4/5

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

Single sentence, front-loaded with key information. Could be expanded slightly but remains efficient.

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

Completeness2/5

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

No output schema and no annotations; description is too minimal to fully guide an agent, especially given the presence of overlapping sibling tools.

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%, so baseline is 3. The description does not add any meaning beyond what the schema already provides for 'limit' and 'storyId'.

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?

Description clearly states verb 'get', resource 'comments', and context 'for a story'. It distinguishes from siblings like 'getComment' (single) and 'getCommentTree' (hierarchical).

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 on when to use this tool over siblings such as 'getCommentTree' or 'getStoryWithComments'. No explicit context or exclusions provided.

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