Skip to main content
Glama
paabloLC

MCP Hacker News

by paabloLC

getAskHNStories

Fetch Ask HN stories from Hacker News to access community questions and discussions. Retrieve stories with configurable limits for research or content discovery.

Instructions

Get Ask HN stories

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNumber of stories to return (default: 10, max: 30)

Implementation Reference

  • Handler function implementing the core logic: fetches Ask HN story IDs from HN API, retrieves story details, formats output including title, score, author, comments, time, HN URL, and text, then returns structured JSON response.
    execute: async (args: any) => { const limit = Math.min(args.limit || 10, 30); const askIds = await fetchFromAPI<number[]>("/askstories"); if (!askIds) { return { content: [ { type: "text", text: JSON.stringify({ error: "Failed to fetch Ask HN stories" }), }, ], }; } const stories = await fetchMultipleItems(askIds, limit); const formattedStories = stories.map((story) => ({ id: story.id, title: story.title, score: story.score, author: story.by, comments: story.descendants || 0, time: story.time ? formatTime(story.time) : "unknown", hnUrl: `https://news.ycombinator.com/item?id=${story.id}`, text: story.text, })); return { content: [ { type: "text", text: JSON.stringify( { message: `Latest ${limit} Ask HN stories`, stories: formattedStories, }, null, 2 ), }, ], };
  • Input schema defining the optional 'limit' parameter for the number of Ask HN stories to retrieve (default 10, max 30).
    inputSchema: { type: "object", properties: { limit: { type: "number", description: "Number of stories to return (default: 10, max: 30)", default: 10, }, }, },
  • src/tools.ts:185-241 (registration)
    Tool object definition registered in the exported 'tools' array used by the MCP server.
    { name: "getAskHNStories", description: "Get Ask HN stories", inputSchema: { type: "object", properties: { limit: { type: "number", description: "Number of stories to return (default: 10, max: 30)", default: 10, }, }, }, execute: async (args: any) => { const limit = Math.min(args.limit || 10, 30); const askIds = await fetchFromAPI<number[]>("/askstories"); if (!askIds) { return { content: [ { type: "text", text: JSON.stringify({ error: "Failed to fetch Ask HN stories" }), }, ], }; } const stories = await fetchMultipleItems(askIds, limit); const formattedStories = stories.map((story) => ({ id: story.id, title: story.title, score: story.score, author: story.by, comments: story.descendants || 0, time: story.time ? formatTime(story.time) : "unknown", hnUrl: `https://news.ycombinator.com/item?id=${story.id}`, text: story.text, })); return { content: [ { type: "text", text: JSON.stringify( { message: `Latest ${limit} Ask HN stories`, stories: formattedStories, }, null, 2 ), }, ], }; }, },
  • src/index.ts:52-65 (registration)
    MCP protocol handler in server for 'tools/call' that dynamically finds and executes the tool by name from the imported tools array.
    if (json.method === "tools/call") { const tool = tools.find((tool) => tool.name === json.params.name); if (tool) { const toolResponse = await tool.execute(json.params.arguments); sendResponse(json.id, toolResponse); } else { sendResponse(json.id, { error: { code: -32602, message: `MCP error -32602: Tool ${json.params.name} not found`, }, }); } }

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