getUpdates
Retrieve recently updated Hacker News items and profiles to monitor new activity and changes in real-time.
Instructions
Get recently updated items and profiles
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:556-586 (handler)The execute handler function for the 'getUpdates' MCP tool. It fetches recent updates from the Hacker News '/updates' endpoint, handles errors, limits results to top 10 items and profiles, and returns a standardized MCP content response with JSON text.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 definition for the 'getUpdates' tool, specifying no required parameters.inputSchema: { type: "object", properties: {} },
- src/index.ts:52-65 (registration)MCP 'tools/call' request handler in the main server that locates the 'getUpdates' tool by name from the tools array and invokes its execute method with arguments.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`, }, }); } }
- src/fetch-actions.ts:9-26 (helper)fetchFromAPI utility function called by the getUpdates handler to retrieve data from the Hacker News API (used with endpoint '/updates'), including caching via helpers.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; }
- src/types-hn.ts:31-34 (schema)TypeScript interface defining the structure of updates data returned by the Hacker News '/updates' endpoint, used in the handler's type annotation.export interface HackerNewsUpdates { items: number[]; profiles: string[]; }