Get Show HN Posts
get-show-hnRetrieve user-submitted project showcases from HackerNews to discover new tools, applications, and innovations shared by the developer community.
Instructions
Get latest "Show HN" posts where users showcase their projects
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:223-236 (handler)The handler function for the 'get-show-hn' tool. It constructs a search query for 'show_hn' tagged posts using the HackerNews Algolia API's /search_by_date endpoint, applies optional pagination, fetches the results using the shared fetchHN helper, and returns both text and structured content.
async ({ page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('tags', 'show_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 }; } - src/index.ts:208-222 (schema)The schema definition for the 'get-show-hn' tool, including title, description, input schema (optional pagination params), and output schema matching the HN API search response structure.
{ title: 'Get Show HN Posts', description: 'Get latest "Show HN" posts where users showcase their projects', 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:207-237 (registration)The registration of the 'get-show-hn' tool using server.registerTool, which includes the tool name, schema, and inline handler function.
'get-show-hn', { title: 'Get Show HN Posts', description: 'Get latest "Show HN" posts where users showcase their projects', 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', 'show_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 }; } ); - src/index.ts:11-17 (helper)Shared helper function fetchHN used by the 'get-show-hn' handler (and all other tools) to make API calls 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(); } - src/index.ts:8-8 (helper)Base URL constant for the HackerNews Algolia API, used by fetchHN helper.
const HN_API_BASE = 'https://hn.algolia.com/api/v1';