Skip to main content
Glama

MCP Hacker News

by paabloLC

getItem

Fetch and retrieve specific Hacker News items such as stories, comments, or jobs by their unique ID using the MCP protocol.

Instructions

Get a specific item (story, comment, job, etc.) by ID

Input Schema

NameRequiredDescriptionDefault
idYesThe item ID to fetch

Input Schema (JSON Schema)

{ "properties": { "id": { "description": "The item ID to fetch", "type": "number" } }, "required": [ "id" ], "type": "object" }

Implementation Reference

  • The main handler function for the 'getItem' tool. It fetches the specific Hacker News item by ID using fetchFromAPI, formats the response including metadata like title, score, author, comments, etc., and returns a structured JSON response.
    execute: async (args: any) => { const item = await fetchFromAPI<HackerNewsItem>(`/item/${args.id}`); if (!item) { return { content: [ { type: "text", text: JSON.stringify({ error: "Item not found" }) }, ], }; } const formattedItem = { id: item.id, type: item.type, title: item.title, url: item.url, score: item.score, author: item.by, time: item.time ? formatTime(item.time) : "unknown", comments: item.descendants || 0, text: item.text, parent: item.parent, kids: item.kids, hnUrl: `https://news.ycombinator.com/item?id=${item.id}`, }; return { content: [ { type: "text", text: JSON.stringify( { message: `Item ${args.id}`, item: formattedItem, }, null, 2 ), }, ], }; },
  • The input schema for the 'getItem' tool, defining a required 'id' parameter of type number.
    inputSchema: { type: "object", properties: { id: { type: "number", description: "The item ID to fetch", }, }, required: ["id"], },
  • src/tools.ts:358-413 (registration)
    The full 'getItem' tool object registered in the exported 'tools' array, which is imported and used in index.ts for tool listing and execution.
    { name: "getItem", description: "Get a specific item (story, comment, job, etc.) by ID", inputSchema: { type: "object", properties: { id: { type: "number", description: "The item ID to fetch", }, }, required: ["id"], }, execute: async (args: any) => { const item = await fetchFromAPI<HackerNewsItem>(`/item/${args.id}`); if (!item) { return { content: [ { type: "text", text: JSON.stringify({ error: "Item not found" }) }, ], }; } const formattedItem = { id: item.id, type: item.type, title: item.title, url: item.url, score: item.score, author: item.by, time: item.time ? formatTime(item.time) : "unknown", comments: item.descendants || 0, text: item.text, parent: item.parent, kids: item.kids, hnUrl: `https://news.ycombinator.com/item?id=${item.id}`, }; return { content: [ { type: "text", text: JSON.stringify( { message: `Item ${args.id}`, item: formattedItem, }, 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