get-polls
Retrieve recent polls from HackerNews to analyze community opinions and discussions. Supports pagination for browsing through multiple pages of poll results.
Instructions
Get latest polls 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:458-471 (handler)Handler function that fetches the latest HackerNews polls using the Algolia API, filtered by the 'poll' tag, with optional pagination parameters.async ({ page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('tags', 'poll'); 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:443-456 (schema)Input and output schema definitions for the 'get-polls' tool using Zod validation.{ title: 'Get HackerNews Polls', description: 'Get latest polls 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:442-472 (registration)Registration of the 'get-polls' tool on the MCP server using server.registerTool.'get-polls', { title: 'Get HackerNews Polls', description: 'Get latest polls 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', 'poll'); 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)Shared helper function used by 'get-polls' (and other tools) to make API calls 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(); }
- src/index.ts:7-7 (helper)Base URL constant for HackerNews Algolia API used in fetchHN helper.// HackerNews API base URL