get-latest-stories
Retrieve recent stories from HackerNews with customizable pagination to access current discussions and technology news.
Instructions
Get the most recent stories posted to HackerNews
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hitsPerPage | No | Number of results per page (default: 20) | |
| page | No | Page number for pagination (default: 0) |
Implementation Reference
- src/index.ts:155-169 (handler)Handler function that fetches the most recent HackerNews stories using the /search_by_date endpoint with the 'story' tag filter.async ({ page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('tags', 'story'); if (page !== undefined) params.append('page', page.toString()); if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString()); const endpoint = `/search_by_date?${params.toString()}`; const result = await fetchHN(endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result }; } );
- src/index.ts:140-154 (schema)Schema definition including title, description, inputSchema (optional page and hitsPerPage), and outputSchema for the search results structure.{ title: 'Get Latest HackerNews Stories', description: 'Get the most recent stories posted to HackerNews', inputSchema: { page: z.number().optional().describe('Page number for pagination (default: 0)'), hitsPerPage: z.number().optional().describe('Number of results per page (default: 20)') }, outputSchema: { hits: z.array(z.any()), nbHits: z.number(), nbPages: z.number(), page: z.number(), hitsPerPage: z.number() } },
- src/index.ts:138-169 (registration)Complete registration of the 'get-latest-stories' tool on the MCP server.server.registerTool( 'get-latest-stories', { title: 'Get Latest HackerNews Stories', description: 'Get the most recent stories posted to HackerNews', inputSchema: { page: z.number().optional().describe('Page number for pagination (default: 0)'), hitsPerPage: z.number().optional().describe('Number of results per page (default: 20)') }, outputSchema: { hits: z.array(z.any()), nbHits: z.number(), nbPages: z.number(), page: z.number(), hitsPerPage: z.number() } }, async ({ page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('tags', 'story'); if (page !== undefined) params.append('page', page.toString()); if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString()); const endpoint = `/search_by_date?${params.toString()}`; const result = await fetchHN(endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result }; } );
- src/index.ts:11-17 (helper)Utility function used by the handler to perform API requests to the HackerNews Algolia API.async function fetchHN(endpoint: string): Promise<any> { const response = await fetch(`${HN_API_BASE}${endpoint}`); if (!response.ok) { throw new Error(`HN API error: ${response.status} ${response.statusText}`); } return await response.json(); }