Skip to main content
Glama

getComment

Retrieve a specific Hacker News comment by entering its unique ID. Enables direct access to individual discussion points within the platform, facilitating focused analysis or reference.

Instructions

Get a single comment by ID

Input Schema

NameRequiredDescriptionDefault
idYesThe ID of the comment

Input Schema (JSON Schema)

{ "properties": { "id": { "description": "The ID of the comment", "type": "number" } }, "required": [ "id" ], "type": "object" }

Implementation Reference

  • The main handler for the 'getComment' tool. Validates input using CommentRequestSchema, fetches the comment item via hnApi.getItem(id), checks if it's a comment, formats it with formatComment, constructs a text response, and returns it.
    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() }], }; }
  • Zod schema for validating the input parameters of the getComment tool (requires positive integer ID). Used in the handler via validateInput.
    export const CommentRequestSchema = z.object({ id: z.number().int().positive(), });
  • src/index.ts:112-122 (registration)
    Registration of the 'getComment' tool in the ListTools response, including name, description, and JSON schema for input validation.
    { name: "getComment", description: "Get a single comment by ID", inputSchema: { type: "object", properties: { id: { type: "number", description: "The ID of the comment" }, }, required: ["id"], }, },
  • Helper function that formats a raw Hacker News item object into a structured Comment interface, 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", }; }
  • Core API helper in HackerNewsAPI class that fetches a single item (story or comment) by ID from the Hacker News Firebase API endpoint. Called by the getComment handler.
    /** * Fetch an item by ID */ async getItem(id: number): Promise<any> { const response = await fetch(`${API_BASE_URL}/item/${id}.json`); return response.json(); }

Other Tools

Related 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