hn_story
Fetch detailed information for a specific Hacker News story by providing its unique ID. Use this tool to quickly retrieve targeted story data from the Hacker News platform.
Instructions
Get details for a specific story by ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| story_id | Yes | The ID of the story to fetch |
Implementation Reference
- index.ts:301-328 (handler)Executes the hn_story tool: validates story_id argument, fetches story details using HackerNewsAPI.getItemDetails, formats the story data, and returns formatted text response.if (name === "hn_story") { const storyId = typeof args?.story_id === 'number' ? args.story_id : NaN; if (isNaN(storyId)) { throw new Error('Story ID must be a number'); } const story = await api.getItemDetails(storyId) as Story | null; if (!story) { throw new Error(`Story with ID ${storyId} not found`); } const formattedStory = { id: story.id, title: story.title, by: story.by, time: api.formatTime(story.time), url: story.url, text: story.text ? api.cleanText(story.text) : '', score: story.score, commentsCount: story.kids?.length || 0 }; return { content: [ { type: "text", text: formatStoryAsText(formattedStory) } ] }; }
- index.ts:194-207 (registration)Registers the hn_story tool in the ListTools response, including name, description, and input schema requiring story_id.{ name: "hn_story", description: "Get details for a specific story by ID", inputSchema: { type: "object", properties: { story_id: { type: "number", description: "The ID of the story to fetch" } }, required: ["story_id"] } },
- index.ts:408-426 (helper)Formats the story details into a readable text string used by the hn_story handler.function formatStoryAsText(story: FormattedStory): string { if (!story) { return "Story not found."; } let result = `Title: ${story.title} ID: ${story.id} By: ${story.by} Published: ${story.time} Score: ${story.score} Comments: ${story.commentsCount} URL: ${story.url || 'N/A'}`; if (story.text) { result += `\n\nContent:\n${story.text}`; } return result; }
- index.ts:87-95 (helper)Fetches item details (story or comment) from Hacker News API by ID, used by hn_story handler.async getItemDetails(itemId: number): Promise<Story | Comment | null> { try { const response = await axios.get(`${baseUrl}/item/${itemId}.json`); return response.data; } catch (error) { console.error(`Error fetching item ${itemId}:`, error); return null; } }