Skip to main content
Glama
paabloLC

MCP Hacker News

by paabloLC

getComments

Fetch and analyze comments for a specific Hacker News post using an MCP server. Retrieve nested comments with customizable depth for targeted insights.

Instructions

Get comments for a specific item

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
depthNoMaximum depth of comments to fetch (default: 2)
idYesThe item ID to fetch comments for

Implementation Reference

  • Handler function that fetches the specified HN item, retrieves its top-level comments (up to 20), formats them with details like author, time, text, and HN URL, and returns a JSON response.
    execute: async (args: any) => { const item = await fetchFromAPI<HackerNewsItem>(`/item/${args.id}`); if (!item || !item.kids) { return { content: [ { type: "text", text: JSON.stringify({ error: "No comments found" }), }, ], }; } const depth = Math.min(args.depth || 2, 3); const comments = await fetchMultipleItems(item.kids, 20); const formattedComments = comments.map((comment) => ({ id: comment.id, author: comment.by, time: comment.time ? formatTime(comment.time) : "unknown", text: comment.text, parent: comment.parent, kids: comment.kids?.length || 0, hnUrl: `https://news.ycombinator.com/item?id=${comment.id}`, })); return { content: [ { type: "text", text: JSON.stringify( { message: `Comments for item ${args.id}`, totalComments: item.descendants || 0, topLevelComments: formattedComments.length, comments: formattedComments, }, null, 2 ), }, ], }; },
  • Input schema specifying the required 'id' parameter for the item and optional 'depth' for comment recursion.
    inputSchema: { type: "object", properties: { id: { type: "number", description: "The item ID to fetch comments for", }, depth: { type: "number", description: "Maximum depth of comments to fetch (default: 2)", default: 2, }, }, required: ["id"], },
  • src/tools.ts:464-527 (registration)
    Registration of the 'getComments' tool within the exported tools array, including name, description, schema, and handler.
    { name: "getComments", description: "Get comments for a specific item", inputSchema: { type: "object", properties: { id: { type: "number", description: "The item ID to fetch comments for", }, depth: { type: "number", description: "Maximum depth of comments to fetch (default: 2)", default: 2, }, }, required: ["id"], }, execute: async (args: any) => { const item = await fetchFromAPI<HackerNewsItem>(`/item/${args.id}`); if (!item || !item.kids) { return { content: [ { type: "text", text: JSON.stringify({ error: "No comments found" }), }, ], }; } const depth = Math.min(args.depth || 2, 3); const comments = await fetchMultipleItems(item.kids, 20); const formattedComments = comments.map((comment) => ({ id: comment.id, author: comment.by, time: comment.time ? formatTime(comment.time) : "unknown", text: comment.text, parent: comment.parent, kids: comment.kids?.length || 0, hnUrl: `https://news.ycombinator.com/item?id=${comment.id}`, })); return { content: [ { type: "text", text: JSON.stringify( { message: `Comments for item ${args.id}`, totalComments: item.descendants || 0, topLevelComments: formattedComments.length, comments: formattedComments, }, null, 2 ), }, ], }; }, },

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/paabloLC/mcp-hacker-news'

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