getUpdates
Retrieve recent updates, including posts, comments, and user profiles, from Hacker News via a standardized MCP server endpoint for real-time data interaction.
Instructions
Get recently updated items and profiles
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"type": "object"
}
Implementation Reference
- src/tools.ts:556-586 (handler)The execute handler for the 'getUpdates' tool. Fetches recent updates from Hacker News API using fetchFromAPI('/updates'), handles errors, limits to top 10 items and profiles, and returns formatted JSON response.execute: async (args: any) => { const updates = await fetchFromAPI<HackerNewsUpdates>("/updates"); if (!updates) { return { content: [ { type: "text", text: JSON.stringify({ error: "Failed to fetch updates" }), }, ], }; } return { content: [ { type: "text", text: JSON.stringify( { message: "Recent updates", recentlyUpdatedItems: updates.items.slice(0, 10), recentlyUpdatedProfiles: updates.profiles.slice(0, 10), }, null, 2 ), }, ], }; },
- src/tools.ts:555-555 (schema)Input schema for 'getUpdates' tool, which requires no input parameters.inputSchema: { type: "object", properties: {} },
- src/tools.ts:552-587 (registration)Registration of the 'getUpdates' tool in the tools export array, including name, description, schema, and handler.{ name: "getUpdates", description: "Get recently updated items and profiles", inputSchema: { type: "object", properties: {} }, execute: async (args: any) => { const updates = await fetchFromAPI<HackerNewsUpdates>("/updates"); if (!updates) { return { content: [ { type: "text", text: JSON.stringify({ error: "Failed to fetch updates" }), }, ], }; } return { content: [ { type: "text", text: JSON.stringify( { message: "Recent updates", recentlyUpdatedItems: updates.items.slice(0, 10), recentlyUpdatedProfiles: updates.profiles.slice(0, 10), }, null, 2 ), }, ], }; }, },
- src/types-hn.ts:31-35 (helper)TypeScript interface defining the structure of updates data used in the getUpdates handler.export interface HackerNewsUpdates { items: number[]; profiles: string[]; }
- src/fetch-actions.ts:9-27 (helper)Helper function fetchFromAPI used by the getUpdates handler to fetch data from '/updates' endpoint.export async function fetchFromAPI<T>(endpoint: string): Promise<T | null> { const cacheKey = endpoint; const cached = getCached<T>(cacheKey); if (cached) return cached; try { const response = await fetch( `https://hacker-news.firebaseio.com/v0${endpoint}.json` ); if (!response.ok) throw new Error(`HTTP ${response.status}`); const data = await response.json(); setCache(cacheKey, data); return data; } catch (error) { console.error(`Error fetching ${endpoint}:`, error); return null; } }