Skip to main content
Glama
wei
by wei

get-latest-posts

Retrieve recent HackerNews posts sorted chronologically with filters for content types like stories or comments, supporting pagination and customizable results per page.

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

TableJSON Schema
NameRequiredDescriptionDefault
tagsNoOptional filter tags (e.g., ['story'], ['comment'])
pageNoPage number (0-indexed, default: 0)
hitsPerPageNoResults per page (1-1000, default: 20)

Implementation Reference

  • The getLatestPostsHandler function that executes the tool: validates input schema, calls HNAPIClient.searchByDate API with empty query for latest posts, validates and returns output or handles errors.
    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"); } }
  • Zod schema for input validation: optional tags filter, pagination parameters.
    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)"), });
  • Zod schema for output validation matching the HN search API response structure.
    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/index.ts:45-55 (registration)
    MCP server registration of getLatestPostsTool in the listTools request handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ searchPostsToolMetadata, getFrontPageTool, getLatestPostsTool, getItemTool, getUserTool, ], }; });
  • src/index.ts:72-73 (registration)
    Dispatch of 'get-latest-posts' tool calls to the handler in the callTool request handler switch statement.
    case "get-latest-posts": return await getLatestPostsHandler(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