Skip to main content
Glama

MCP Hacker News

by paabloLC

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

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "properties": {}, "type": "object" }

Implementation Reference

  • 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 ), }, ], }; },
  • 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 ), }, ], }; }, },
  • 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; } }

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/paabloLC/mcp-hacker-news'

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