Skip to main content
Glama
imprvhub

mcp-claude-hackernews

hn_best

Fetch top stories from Hacker News with customizable limits. Retrieve trending tech and startup content for insights and updates.

Instructions

Get the best stories from Hacker News

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNumber of stories to fetch (1-50, default: 10)

Implementation Reference

  • Handler for the 'hn_best' tool: fetches best stories via HackerNewsAPI, formats them, updates lastStoriesList, and returns formatted text response.
    if (name === "hn_best") { const limit = typeof args?.limit === 'number' ? args.limit : 10; const stories = await api.getBestStories(limit); const formattedStories = stories.map(story => ({ id: story.id, title: story.title, by: story.by, time: api.formatTime(story.time), url: story.url, score: story.score, commentsCount: story.kids?.length || 0 })); lastStoriesList = formattedStories; return { content: [ { type: "text", text: formatStoriesAsText(formattedStories) } ] }; }
  • index.ts:178-193 (registration)
    Tool registration in listTools handler: defines name, description, and input schema for 'hn_best'.
    { name: "hn_best", description: "Get the best stories from Hacker News", inputSchema: { type: "object", properties: { limit: { type: "number", description: "Number of stories to fetch (1-50, default: 10)", minimum: 1, maximum: 50, default: 10 } } } },
  • Core helper method in HackerNewsAPI that fetches best story IDs from HN API and retrieves full story details.
    async getBestStories(limit = 50): Promise<Story[]> { try { const response = await axios.get(`${baseUrl}/beststories.json`); const storyIds = response.data || []; const storyPromises = storyIds.slice(0, limit).map((id: number) => this.getItemDetails(id)); const stories = await Promise.all(storyPromises); return stories.filter((story): story is Story => story !== null && story.type === 'story'); } catch (error) { console.error('Error fetching best stories:', error); return []; } }
  • Helper function to format the list of stories as a readable text string, used in the tool response.
    function formatStoriesAsText(stories: FormattedStory[]): string { if (!stories || stories.length === 0) { return "No stories found."; } return stories.map((story, index) => { return `${index + 1}. ${story.title} ID: ${story.id} By: ${story.by} Published: ${story.time} Score: ${story.score} Comments: ${story.commentsCount} URL: ${story.url || 'N/A'} ------------------------------`; }).join('\n\n'); }

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/imprvhub/mcp-claude-hackernews'

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