Skip to main content
Glama

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
NameRequiredDescriptionDefault
idYesThe ID of the story

Implementation Reference

  • 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"], }, },
  • 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(); }
  • 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", }; }

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/devabdultech/hn-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server