getMaxItemId
Retrieve the highest item ID from Hacker News to track the most recent posts or comments. This tool integrates with the MCP server for real-time data access.
Instructions
Get the current maximum item ID
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"type": "object"
}
Implementation Reference
- src/tools.ts:532-550 (handler)The execute handler function for the 'getMaxItemId' tool. It fetches the maximum item ID from the Hacker News API using fetchFromAPI('/maxitem') and returns a formatted JSON text response.execute: async (args: any) => { const maxId = await fetchFromAPI<number>("/maxitem"); return { content: [ { type: "text", text: JSON.stringify( { message: "Current maximum item ID", maxItemId: maxId, }, null, 2 ), }, ], }; },
- src/tools.ts:531-531 (schema)Input schema for the 'getMaxItemId' tool, which requires no parameters (empty object).inputSchema: { type: "object", properties: {} },
- src/tools.ts:528-551 (registration)The full tool registration object for 'getMaxItemId' in the tools array exported from tools.ts, which is imported and used by the MCP server in index.ts.{ name: "getMaxItemId", description: "Get the current maximum item ID", inputSchema: { type: "object", properties: {} }, execute: async (args: any) => { const maxId = await fetchFromAPI<number>("/maxitem"); return { content: [ { type: "text", text: JSON.stringify( { message: "Current maximum item ID", maxItemId: maxId, }, null, 2 ), }, ], }; }, },
- src/fetch-actions.ts:9-27 (helper)The fetchFromAPI helper function used by the getMaxItemId handler to retrieve data from the Hacker News API (/maxitem endpoint) with caching via getCached/setCache.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; } }