get-front-page
Retrieve current HackerNews front page posts sorted by popularity ranking. Supports pagination and customizable results per page to access trending stories.
Instructions
Retrieve posts currently on the HackerNews front page.
Returns stories sorted by HackerNews ranking algorithm. The front page typically contains the most popular and trending stories.
Supports:
Pagination to view beyond the first page
Customizable results per page (default: 30)
All posts are tagged with 'front_page'
Examples:
Get first page: { }
Get with custom page size: { "hitsPerPage": 50 }
Get second page: { "page": 1 }
Returns the same structure as search results with hits, pagination info, and metadata.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hitsPerPage | No | Results per page (1-1000, default: 30) | |
| page | No | Page number (0-indexed, default: 0) |
Implementation Reference
- src/tools/get-front-page.ts:46-69 (handler)The getFrontPageHandler function that executes the 'get-front-page' tool. Validates input, queries HackerNews API with 'front_page' tag filter, validates output, and handles errors.export async function getFrontPageHandler(input: unknown): Promise<CallToolResult> { try { // Validate input const validatedParams = GetFrontPageInputSchema.parse(input); // Create API client const client = new HNAPIClient(); // Call search API with front_page tag const result = await client.search({ query: "", tags: ["front_page"], page: validatedParams.page, hitsPerPage: validatedParams.hitsPerPage, }); // Validate output const validatedResult = GetFrontPageOutputSchema.parse(result); return createSuccessResult(validatedResult); } catch (error) { return handleAPIError(error, "get-front-page"); } }
- src/tools/get-front-page.ts:16-33 (schema)Zod schemas for input (page, hitsPerPage) and output validation of the get-front-page tool.export const GetFrontPageInputSchema = z.object({ page: z.number().int().nonnegative().default(0).describe("Page number (0-indexed)"), hitsPerPage: z.number().int().min(1).max(1000).default(30).describe("Results per page (1-1000)"), }); /** * Output schema for get-front-page tool (SearchResult) */ export const GetFrontPageOutputSchema = 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-front-page.ts:74-108 (registration)Tool metadata object (getFrontPageTool) containing name, description, and inputSchema, used for MCP tool registration.export const getFrontPageTool = { name: "get-front-page", description: `Retrieve posts currently on the HackerNews front page. Returns stories sorted by HackerNews ranking algorithm. The front page typically contains the most popular and trending stories. Supports: - Pagination to view beyond the first page - Customizable results per page (default: 30) - All posts are tagged with 'front_page' Examples: - Get first page: { } - Get with custom page size: { "hitsPerPage": 50 } - Get second page: { "page": 1 } Returns the same structure as search results with hits, pagination info, and metadata.`, inputSchema: { type: "object", properties: { page: { type: "number", description: "Page number (0-indexed, default: 0)", default: 0, }, hitsPerPage: { type: "number", description: "Results per page (1-1000, default: 30)", default: 30, minimum: 1, maximum: 1000, }, }, }, };
- src/index.ts:45-55 (registration)Registers the getFrontPageTool (line 49) in the MCP server's list of available tools via ListToolsRequestHandler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ searchPostsToolMetadata, getFrontPageTool, getLatestPostsTool, getItemTool, getUserTool, ], }; });
- src/index.ts:69-70 (registration)Dispatches calls to the 'get-front-page' tool by invoking getFrontPageHandler in the CallToolRequestHandler switch statement.case "get-front-page": return await getFrontPageHandler(args);