get-story-comments
Retrieve all comments for a specific HackerNews story using its ID, with pagination support for browsing through discussion threads.
Instructions
Get all comments for a specific story by story ID
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) | |
| storyId | Yes | The ID of the story |
Implementation Reference
- src/index.ts:388-401 (handler)Executes the tool by querying HackerNews API for comments on a specific story ID using tags 'comment,story_${storyId}', with optional pagination, and returns formatted results.async ({ storyId, page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('tags', `comment,story_${storyId}`); if (page !== undefined) params.append('page', page.toString()); if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString()); const endpoint = `/search?${params.toString()}`; const result = await fetchHN(endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result }; }
- src/index.ts:372-386 (schema)Input schema requires storyId (number) and optional page/hitsPerPage; output schema defines search result structure.{ title: 'Get Comments for a Story', description: 'Get all comments for a specific story by story ID', inputSchema: { storyId: z.number().describe('The ID of the story'), 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:371-402 (registration)Registers the 'get-story-comments' tool with McpServer, including schema and handler function.'get-story-comments', { title: 'Get Comments for a Story', description: 'Get all comments for a specific story by story ID', inputSchema: { storyId: z.number().describe('The ID of the story'), 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 ({ storyId, page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('tags', `comment,story_${storyId}`); if (page !== undefined) params.append('page', page.toString()); if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString()); const endpoint = `/search?${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 utility to make API calls to HackerNews Algolia API, used by get-story-comments 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(); }