Skip to main content
Glama

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
NameRequiredDescriptionDefault
hitsPerPageNoNumber of results per page (default: 20)
pageNoPage number for pagination (default: 0)

Implementation Reference

  • 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 }; }
  • 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 }; } );
  • 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(); }
  • Base URL constant for HackerNews Algolia API used in fetchHN helper.
    // HackerNews API base URL

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/wei/hn-mcp-server-vibe'

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