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
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The item ID to fetch |
Input Schema (JSON Schema)
{
"properties": {
"id": {
"description": "The item ID to fetch",
"type": "number"
}
},
"required": [
"id"
],
"type": "object"
}
Implementation Reference
- src/tools.ts:371-412 (handler)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 ), }, ], }; },
- src/tools.ts:361-370 (schema)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 ), }, ], }; }, },