Skip to main content
Glama
paabloLC

MCP Hacker News

by paabloLC

getComments

Fetch comments for Hacker News items to analyze discussions and community feedback on posts, supporting threaded conversations with configurable depth.

Instructions

Get comments for a specific item

Input Schema

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

Implementation Reference

  • The main handler (execute) function for the 'getComments' tool. Fetches the item by ID, retrieves its top-level comments (kids), fetches up to 20 comments, formats them with metadata, 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 defining the parameters for the 'getComments' tool: required 'id' (number) and optional 'depth' (number, default 2).
    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/index.ts:52-65 (registration)
    MCP server registration for tool calls: looks up tool by name from the imported tools array (which includes getComments) and invokes its execute function.
    if (json.method === "tools/call") { const tool = tools.find((tool) => tool.name === json.params.name); if (tool) { const toolResponse = await tool.execute(json.params.arguments); sendResponse(json.id, toolResponse); } else { sendResponse(json.id, { error: { code: -32602, message: `MCP error -32602: Tool ${json.params.name} not found`, }, }); } }
  • src/index.ts:43-50 (registration)
    MCP server lists available tools, including getComments with name, description, and schema.
    if (json.method === "tools/list") { sendResponse(json.id, { tools: tools.map((tool) => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema, })), });
  • Uses helper fetchMultipleItems to fetch comment details (imported from fetch-actions.ts).
    const comments = await fetchMultipleItems(item.kids, 20);

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