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
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the comment |
Implementation Reference
- src/index.ts:338-358 (handler)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"], }, },
- src/schemas/index.ts:49-51 (schema)Zod validation schema for getComment input, ensuring id is a positive integer.export const CommentRequestSchema = z.object({ id: z.number().int().positive(), });
- src/models/comment.ts:11-21 (helper)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", }; }