get-latest-comments
Retrieve recently posted comments from HackerNews to monitor community discussions and stay updated on current conversations.
Instructions
Get the most recent comments 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:189-202 (handler)The handler function for the 'get-latest-comments' tool. It constructs a search query for recent comments (tag 'comment') using the HackerNews Algolia API's search_by_date endpoint and returns the structured results along with a JSON string representation.async ({ page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('tags', 'comment'); 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:174-188 (schema)The input and output schema definitions for the 'get-latest-comments' tool, using Zod for validation. Input supports optional pagination parameters; output matches the HN API search response structure.{ title: 'Get Latest HackerNews Comments', description: 'Get the most recent comments 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:172-203 (registration)The registration of the 'get-latest-comments' tool using McpServer.registerTool, including the tool name, schema, and handler function.server.registerTool( 'get-latest-comments', { title: 'Get Latest HackerNews Comments', description: 'Get the most recent comments 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', 'comment'); 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 to make API calls to the HackerNews Algolia API, used by the get-latest-comments handler and other tools.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(); }