Skip to main content
Glama

get-ask-hn

Retrieve Ask HN posts where HackerNews users ask questions to the community, with pagination support for browsing multiple pages of results.

Instructions

Get latest "Ask HN" posts where users ask questions

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 'Ask HN' posts from the HackerNews API using the /search_by_date endpoint with the 'ask_hn' tag filter. Supports pagination via page and hitsPerPage parameters. Returns results in both plain text JSON and structured content formats.
    async ({ page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('tags', 'ask_hn'); 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 schemas defined using Zod for the 'get-ask-hn' tool, including optional pagination parameters for input and expected search result structure for output.
    { title: 'Get Ask HN Posts', description: 'Get latest "Ask HN" posts where users ask questions', 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:240-271 (registration)
    Full registration of the 'get-ask-hn' tool on the MCP server using server.registerTool, including name, metadata, schema, and handler function.
    server.registerTool( 'get-ask-hn', { title: 'Get Ask HN Posts', description: 'Get latest "Ask HN" posts where users ask questions', 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', 'ask_hn'); 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 the 'get-ask-hn' handler (and other tools) to perform API requests to the HackerNews Algolia API and handle errors.
    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(); }

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