Skip to main content
Glama

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

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