get-posts-by-author
Retrieve all posts, stories, and comments from a specific HackerNews author. Filter results by content type and manage pagination to browse user contributions efficiently.
Instructions
Get all posts (stories, comments, etc.) by a specific author
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) | |
| tags | No | Filter by type (e.g., "story", "comment") | |
| username | Yes | The username of the author |
Implementation Reference
- src/index.ts:351-366 (handler)Handler function that constructs a HackerNews API search query using the 'author_USERNAME' tag combined with optional tags filter, paginates if specified, fetches from /search_by_date endpoint using shared fetchHN helper, and returns structured results.async ({ username, tags, page, hitsPerPage }) => { const params = new URLSearchParams(); const authorTag = `author_${username}`; const combinedTags = tags ? `${authorTag},${tags}` : authorTag; params.append('tags', combinedTags); 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:334-349 (schema)Input schema requires username, optional tags filter, page, hitsPerPage. Output schema defines search result structure with hits array, pagination info.{ title: 'Get Posts by Author', description: 'Get all posts (stories, comments, etc.) by a specific author', inputSchema: { username: z.string().describe('The username of the author'), tags: z.string().optional().describe('Filter by type (e.g., "story", "comment")'), 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:331-367 (registration)Full registration of the 'get-posts-by-author' tool on the MCP server, including name, metadata, schemas, and handler reference.// Tool 10: Get posts by author server.registerTool( 'get-posts-by-author', { title: 'Get Posts by Author', description: 'Get all posts (stories, comments, etc.) by a specific author', inputSchema: { username: z.string().describe('The username of the author'), tags: z.string().optional().describe('Filter by type (e.g., "story", "comment")'), 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 ({ username, tags, page, hitsPerPage }) => { const params = new URLSearchParams(); const authorTag = `author_${username}`; const combinedTags = tags ? `${authorTag},${tags}` : authorTag; params.append('tags', combinedTags); 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 utility function to make HTTP requests to the HackerNews Algolia API, handles errors and JSON parsing, used by the get-posts-by-author handler.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(); }