Skip to main content
Glama
wei

HackerNews MCP Server

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);
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: returns posts in chronological order (newest first), includes all content types unless filtered, supports pagination, has a default page size of 20, and allows an empty query. It doesn't mention rate limits, authentication needs, or error handling, but covers the core functionality well for a read-only tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized. It starts with the core purpose, lists key features with bullet points, provides concrete examples, and ends with usage guidance. Every sentence adds value with no redundancy or fluff. The bullet points make it scannable and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a read-only tool with 3 parameters and 100% schema coverage but no output schema, the description is quite complete. It explains what the tool does, how to use it, and provides examples. The main gap is the lack of output format details (what fields posts include), which would be helpful since there's no output schema. Otherwise, it covers the essential context well.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds some value by explaining that tags filter by content type (e.g., story, comment) and providing examples, but doesn't add significant semantic meaning beyond what the schema provides. The baseline of 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Retrieve the most recent HackerNews posts sorted by date.' It specifies the resource (HackerNews posts), verb (retrieve), and sorting (newest first). It also distinguishes from siblings like 'get-front-page' (which likely shows curated content) and 'search-posts' (which likely searches by keyword).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool: 'Use this to monitor real-time HackerNews activity or find the newest content.' It distinguishes from 'search-posts' by focusing on recency rather than search queries. However, it doesn't explicitly state when NOT to use it or compare all alternatives (e.g., 'get-front-page' for curated content).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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