get-front-page
Retrieve trending posts from the HackerNews front page with pagination support to browse popular stories efficiently.
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 |
|---|---|---|---|
| page | No | Page number (0-indexed, default: 0) | |
| hitsPerPage | No | Results per page (1-1000, default: 30) |
Implementation Reference
- src/tools/get-front-page.ts:46-69 (handler)The primary handler function that executes the 'get-front-page' tool: validates input parameters, queries the HackerNews search API filtered by 'front_page' tag, validates the response, and returns a formatted MCP tool result or 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-19 (schema)Zod schema for validating the input parameters to the 'get-front-page' tool (page and hitsPerPage).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)"), });
- src/tools/get-front-page.ts:24-33 (schema)Zod schema for validating the output/response from the HackerNews API for the 'get-front-page' tool.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/index.ts:69-70 (registration)Registration of the 'get-front-page' tool handler in the MCP server's CallToolRequestHandler switch statement, dispatching calls to getFrontPageHandler.case "get-front-page": return await getFrontPageHandler(args);
- src/index.ts:47-53 (registration)Registration of the 'get-front-page' tool metadata (getFrontPageTool) in the MCP server's ListToolsRequestHandler tools list.tools: [ searchPostsToolMetadata, getFrontPageTool, getLatestPostsTool, getItemTool, getUserTool, ],