Skip to main content
Glama
wei
by wei

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

TableJSON Schema
NameRequiredDescriptionDefault
hitsPerPageNoResults per page (1-1000, default: 30)
pageNoPage number (0-indexed, default: 0)

Implementation Reference

  • 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"); } }
  • 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), });
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wei/hn-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server