Skip to main content
Glama
devabdultech

Hacker News MCP Server

by devabdultech

getComment

Retrieve specific Hacker News comments by ID to analyze discussions, verify information, or reference user contributions within the platform.

Instructions

Get a single comment by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe ID of the comment

Implementation Reference

  • Main execution logic for the getComment tool: validates input, fetches the comment from HN API, formats it, and returns formatted text response.
    case "getComment": {
      const validatedArgs = validateInput(CommentRequestSchema, args);
      const { id } = validatedArgs;
      const item = await hnApi.getItem(id);
      if (!item || item.type !== "comment") {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Comment with ID ${id} not found`
        );
      }
      const comment = formatComment(item);
      const text =
        `Comment ID: ${comment.id}\n` +
        `Comment by ${comment.by}:\n` +
        `${comment.text}\n` +
        `Parent ID: ${comment.parent}\n`;
    
      return {
        content: [{ type: "text", text: text.trim() }],
      };
    }
  • src/index.ts:113-122 (registration)
    Tool registration in ListTools handler, defining name, description, and input schema.
      name: "getComment",
      description: "Get a single comment by ID",
      inputSchema: {
        type: "object",
        properties: {
          id: { type: "number", description: "The ID of the comment" },
        },
        required: ["id"],
      },
    },
  • Zod validation schema for getComment input, ensuring id is a positive integer.
    export const CommentRequestSchema = z.object({
      id: z.number().int().positive(),
    });
  • Helper function to format raw HN item data into a structured Comment object, used in the getComment 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

A4.1/5.0
Behavior4/5

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

Description accurately reflects a read operation; no annotations to contradict, but lacks detail on response format or post-fetch behavior.

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?

Single, clear sentence with no unnecessary words.

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

Completeness5/5

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

For a simple single-ID fetch with no output schema, the description is sufficient and 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 covers 100% of parameters; description adds no extra meaning beyond restating the purpose.

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 the action (get), resource (comment), and scope (single by ID), distinguishing it from siblings like getComments and getCommentTree.

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?

No explicit guidance on when to use this tool vs alternatives; context is implied by sibling names but not stated.

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