Skip to main content
Glama
paabloLC

MCP Hacker News

by paabloLC

getItem

Retrieve specific Hacker News items like stories, comments, or jobs by their unique ID to access detailed information.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe item ID to fetch

Implementation Reference

  • The execute handler for the 'getItem' tool, which fetches the specific Hacker News item by ID using fetchFromAPI, formats its properties including time and HN URL, 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 ), }, ], }; },
  • Input schema for 'getItem' tool, requiring a numeric 'id' parameter.
    inputSchema: { type: "object", properties: { id: { type: "number", description: "The item ID to fetch", }, }, required: ["id"], },
  • src/tools.ts:358-413 (registration)
    The complete 'getItem' tool object registered in the exported 'tools' array, which is imported and used by the MCP server 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 ), }, ], }; }, },
  • The fetchFromAPI helper function used by getItem to retrieve data from Hacker News API with caching support.
    export async function fetchFromAPI<T>(endpoint: string): Promise<T | null> { const cacheKey = endpoint; const cached = getCached<T>(cacheKey); if (cached) return cached; try { const response = await fetch( `https://hacker-news.firebaseio.com/v0${endpoint}.json` ); if (!response.ok) throw new Error(`HTTP ${response.status}`); const data = await response.json(); setCache(cacheKey, data); return data; } catch (error) { console.error(`Error fetching ${endpoint}:`, error); return null; } }

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