getStory
Retrieve a specific Hacker News story by its unique ID using the Model Context Protocol. Ideal for accessing detailed story data directly through LLM clients.
Instructions
Get a single story by ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the story |
Implementation Reference
- src/index.ts:207-227 (handler)The handler function for the 'getStory' MCP tool. It extracts the story ID from arguments, fetches the raw item using hnApi.getItem, validates it is a story, formats it using formatStory, constructs a formatted text response, and returns it.case "getStory": { const { id } = args as { id: number }; const item = await hnApi.getItem(id); if (!item || item.type !== "story") { throw new McpError( ErrorCode.InvalidParams, `Story with ID ${id} not found` ); } const story = formatStory(item); const text = `Story ID: ${story.id}\n` + `Title: ${story.title}\n` + `URL: ${story.url || "(text post)"}\n` + `Points: ${story.score} | Author: ${story.by} | Comments: ${story.descendants}\n` + (story.text ? `\nContent:\n${story.text}\n` : ""); return { content: [{ type: "text", text: text.trim() }], }; }
- src/index.ts:69-79 (registration)Registration of the 'getStory' tool in the ListTools handler, including name, description, and inline input schema.{ name: "getStory", description: "Get a single story by ID", inputSchema: { type: "object", properties: { id: { type: "number", description: "The ID of the story" }, }, required: ["id"], }, },
- src/api/hn.ts:12-15 (helper)HackerNewsAPI.getItem helper: fetches a single HN item by ID from the official Firebase API endpoint.async getItem(id: number): Promise<any> { const response = await fetch(`${API_BASE_URL}/item/${id}.json`); return response.json(); }
- src/models/story.ts:14-27 (helper)formatStory helper: transforms raw HN story item into a typed Story object with defaults.export function formatStory(item: any): Story { return { id: item.id, title: item.title, url: item.url, text: item.text, by: item.by, score: item.score || 0, time: item.time, descendants: item.descendants || 0, kids: item.kids || [], type: "story", }; }