Skip to main content
Glama
devabdultech

Hacker News MCP Server

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",
      };
    }
Behavior2/5

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

With no annotations, the description carries full burden but only states the basic action without disclosing behavioral traits. It doesn't mention if this is a read-only operation, how comments are ordered, pagination details, error handling, or rate limits. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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?

The description is a single, efficient sentence with no wasted words. It's appropriately sized for a simple tool, though it could be more front-loaded with key details. Every word earns its place, but it's under-specified rather than concise.

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?

Given no annotations, no output schema, and a simple input schema, the description is incomplete. It doesn't cover return values, error cases, or how to handle the limit parameter effectively. For a tool fetching comments, more context on output format and usage is needed to be complete.

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 both parameters (storyId and limit) fully. The description adds no meaning beyond what the schema provides—it doesn't explain parameter interactions, default behavior for limit, or additional context. 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.

Purpose3/5

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

The description 'Get comments for a story' states the basic action (get) and resource (comments for a story), but it's vague about scope and doesn't distinguish from siblings like getComment, getCommentTree, or getStoryWithComments. It lacks specificity about what kind of comments or how they're returned.

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 getCommentTree (for hierarchical comments) or getStoryWithComments (which might include story details). The description implies usage for fetching comments but offers no context about prerequisites, exclusions, or comparison to sibling tools.

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/devabdultech/hn-mcp'

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