get-latest-posts
Retrieve recent HackerNews posts sorted by date, with filtering by content type and pagination support for monitoring real-time activity.
Instructions
Retrieve the most recent HackerNews posts sorted by date.
Returns posts in chronological order (newest first), including all types of content unless filtered.
Supports:
Filter by content type using tags (story, comment, poll, show_hn, ask_hn, etc.)
Pagination to view older posts
Customizable results per page (default: 20)
Empty query to get all recent posts
Examples:
Get latest stories: { "tags": ["story"] }
Get latest comments: { "tags": ["comment"] }
Get all recent activity: { }
Get with custom page size: { "hitsPerPage": 50 }
Use this to monitor real-time HackerNews activity or find the newest content.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hitsPerPage | No | Results per page (1-1000, default: 20) | |
| page | No | Page number (0-indexed, default: 0) | |
| tags | No | Optional filter tags (e.g., ['story'], ['comment']) |
Implementation Reference
- src/tools/get-latest-posts.ts:47-70 (handler)Core handler function that validates input using Zod schema, fetches latest HackerNews posts via HNAPIClient.searchByDate (with empty query for recency), validates output, and returns structured result or error.export async function getLatestPostsHandler(input: unknown): Promise<CallToolResult> { try { // Validate input const validatedParams = GetLatestPostsInputSchema.parse(input); // Create API client const client = new HNAPIClient(); // Call search_by_date API with empty query to get all latest posts const result = await client.searchByDate({ query: "", tags: validatedParams.tags, page: validatedParams.page, hitsPerPage: validatedParams.hitsPerPage, }); // Validate output const validatedResult = GetLatestPostsOutputSchema.parse(result); return createSuccessResult(validatedResult); } catch (error) { return handleAPIError(error, "get-latest-posts"); } }
- src/tools/get-latest-posts.ts:16-34 (schema)Zod schemas defining input parameters (tags, page, hitsPerPage) and output structure (hits, pagination info) for validation in the handler.export const GetLatestPostsInputSchema = z.object({ tags: z.array(z.string()).optional().describe("Optional filter tags (story, comment, etc.)"), page: z.number().int().nonnegative().default(0).describe("Page number (0-indexed)"), hitsPerPage: z.number().int().min(1).max(1000).default(20).describe("Results per page (1-1000)"), }); /** * Output schema for get-latest-posts tool (SearchResult) */ export const GetLatestPostsOutputSchema = z.object({ hits: z.array(z.any()), nbHits: z.number().int().nonnegative(), page: z.number().int().nonnegative(), nbPages: z.number().int().positive(), hitsPerPage: z.number().int().positive(), processingTimeMS: z.number().nonnegative(), query: z.string(), params: z.string().min(1), });
- src/tools/get-latest-posts.ts:75-116 (registration)Tool metadata object with name, description, and inputSchema, exported for registration in the MCP server.export const getLatestPostsTool = { name: "get-latest-posts", description: `Retrieve the most recent HackerNews posts sorted by date. Returns posts in chronological order (newest first), including all types of content unless filtered. Supports: - Filter by content type using tags (story, comment, poll, show_hn, ask_hn, etc.) - Pagination to view older posts - Customizable results per page (default: 20) - Empty query to get all recent posts Examples: - Get latest stories: { "tags": ["story"] } - Get latest comments: { "tags": ["comment"] } - Get all recent activity: { } - Get with custom page size: { "hitsPerPage": 50 } Use this to monitor real-time HackerNews activity or find the newest content.`, inputSchema: { type: "object", properties: { tags: { type: "array", items: { type: "string" }, description: "Optional filter tags (e.g., ['story'], ['comment'])", }, page: { type: "number", description: "Page number (0-indexed, default: 0)", default: 0, }, hitsPerPage: { type: "number", description: "Results per page (1-1000, default: 20)", default: 20, minimum: 1, maximum: 1000, }, }, }, };
- src/index.ts:45-55 (registration)Registration in ListToolsRequestHandler: getLatestPostsTool is included in the tools list advertised to MCP clients.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ searchPostsToolMetadata, getFrontPageTool, getLatestPostsTool, getItemTool, getUserTool, ], }; });
- src/index.ts:72-73 (registration)Registration in CallToolRequestHandler: switch case dispatches execution to getLatestPostsHandler.case "get-latest-posts": return await getLatestPostsHandler(args);