Get HackerNews Front Page
get-front-pageRetrieve current HackerNews front page stories with pagination controls to browse trending tech news and discussions.
Instructions
Get all stories currently on the HackerNews front page
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hitsPerPage | No | Number of results per page (default: 20) | |
| page | No | Page number for pagination (default: 0) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hits | Yes | ||
| page | Yes | ||
| nbHits | Yes | ||
| nbPages | Yes | ||
| hitsPerPage | Yes |
Implementation Reference
- src/index.ts:121-134 (handler)Handler function that fetches the current HackerNews front page stories using the HN API with 'tags=front_page', supports pagination.
async ({ page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('tags', 'front_page'); if (page !== undefined) params.append('page', page.toString()); if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString()); const endpoint = `/search?${params.toString()}`; const result = await fetchHN(endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result }; } - src/index.ts:106-119 (schema)Input and output schemas for the 'get-front-page' tool, defining optional pagination parameters and expected search result structure.
{ title: 'Get HackerNews Front Page', description: 'Get all stories currently on the HackerNews front page', 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:104-135 (registration)Registration of the 'get-front-page' tool using server.registerTool, including schema and handler.
server.registerTool( 'get-front-page', { title: 'Get HackerNews Front Page', description: 'Get all stories currently on the HackerNews front page', 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', 'front_page'); if (page !== undefined) params.append('page', page.toString()); if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString()); const endpoint = `/search?${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)Shared helper function to make API calls to HackerNews Algolia API, used by the get-front-page handler.
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(); }