Skip to main content
Glama
wei

HackerNews MCP Server

by wei

search-posts

Search HackerNews content by keyword with filters for tags, points, comments, dates, and authors to find relevant stories and discussions.

Instructions

Search HackerNews for stories, comments, and other content by keyword.

Supports:

  • Keyword search across titles, text, and authors

  • Tag filtering (story, comment, poll, show_hn, ask_hn, front_page, author_USERNAME)

  • Numeric filters for points, comments, and dates

  • Pagination with customizable results per page

  • Advanced filtering with OR logic and multiple conditions

Basic Examples:

  • Search for AI stories: { "query": "AI", "tags": ["story"] }

  • Find popular posts: { "query": "Python", "numericFilters": ["points>=100"] }

  • Filter by author: { "query": "startup", "tags": ["author_pg"] }

  • Date range: { "query": "startup", "numericFilters": ["created_at_i>1640000000"] }

Advanced Filtering Examples:

  • High engagement posts: { "query": "programming", "numericFilters": ["points>=100", "num_comments>=50"] }

  • OR logic for tags: { "query": "web", "tags": ["(story,poll)"] } - returns stories OR polls

  • Author with filters: { "query": "", "tags": ["author_pg", "story"], "numericFilters": ["points>=50"] }

  • Multiple conditions: { "query": "AI", "tags": ["story"], "numericFilters": ["points>=200", "num_comments>=100"] }

Numeric Filter Operators: < (less than), <= (less than or equal), = (equal), >= (greater than or equal), > (greater than) Numeric Filter Fields: points, num_comments, created_at_i (Unix timestamp)

Tag Syntax:

  • Single tag: ["story"] - only stories

  • Multiple tags (AND): ["story", "show_hn"] - stories that are also show_hn

  • OR logic: ["(story,poll)"] - stories OR polls

  • Author filter: ["author_USERNAME"] - posts by specific author

Returns paginated results with hits, total count, and page information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query text (minimum 1 character)
tagsNoOptional filter tags (e.g., ['story'], ['comment'], ['(story,poll)'] for OR logic, ['author_pg'] for author filter)
numericFiltersNoOptional numeric filters (e.g., ['points>=100'], ['num_comments>=50'], ['created_at_i>1640000000']). Multiple filters use AND logic.
pageNoPage number (0-indexed, default: 0)
hitsPerPageNoResults per page (1-1000, default: 20)

Implementation Reference

  • The main handler function that executes the 'search-posts' tool: input validation, HN API call, error handling, and result formatting.
    export async function searchPostsTool(input: unknown): Promise<CallToolResult> {
    	try {
    		// Validate input
    		const params = validateInput(SearchPostsInputSchema, input);
    
    		// Call HackerNews API
    		const results = await hnApi.search({
    			query: params.query,
    			tags: params.tags,
    			numericFilters: params.numericFilters,
    			page: params.page,
    			hitsPerPage: params.hitsPerPage,
    		});
    
    		// Return success result
    		return createSuccessResult(results);
    	} catch (error) {
    		// Handle validation errors
    		if (error instanceof ZodError) {
    			return handleValidationError(error);
    		}
    
    		// Handle API errors
    		return handleAPIError(error, "searching posts");
    	}
    }
  • Zod schema defining input parameters and validation rules for the search-posts tool.
    export const SearchPostsInputSchema = z.object({
    	query: z.string().min(1, "query must contain at least 1 character"),
    	tags: z.array(z.string()).optional(),
    	numericFilters: z.array(z.string()).optional(),
    	page: z.number().int().nonnegative("page must be non-negative").default(0),
    	hitsPerPage: z
    		.number()
    		.int()
    		.min(1, "hitsPerPage must be at least 1")
    		.max(1000, "hitsPerPage must not exceed 1000")
    		.default(20),
    });
  • src/index.ts:45-55 (registration)
    Registration of searchPostsToolMetadata in the ListToolsRequestHandler, making the tool discoverable.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
    	return {
    		tools: [
    			searchPostsToolMetadata,
    			getFrontPageTool,
    			getLatestPostsTool,
    			getItemTool,
    			getUserTool,
    		],
    	};
    });
  • src/index.ts:66-68 (registration)
    Dispatch handler in CallToolRequestHandler that routes 'search-posts' calls to the searchPostsTool function.
    case "search-posts":
    	return await searchPostsTool(args);
  • Tool metadata including name, detailed description, and JSON inputSchema used for MCP tool registration and client-side validation.
    export const searchPostsToolMetadata = {
    	name: "search-posts",
    	description: `Search HackerNews for stories, comments, and other content by keyword.
    	
    Supports:
    - Keyword search across titles, text, and authors
    - Tag filtering (story, comment, poll, show_hn, ask_hn, front_page, author_USERNAME)
    - Numeric filters for points, comments, and dates
    - Pagination with customizable results per page
    - Advanced filtering with OR logic and multiple conditions
    
    Basic Examples:
    - Search for AI stories: { "query": "AI", "tags": ["story"] }
    - Find popular posts: { "query": "Python", "numericFilters": ["points>=100"] }
    - Filter by author: { "query": "startup", "tags": ["author_pg"] }
    - Date range: { "query": "startup", "numericFilters": ["created_at_i>1640000000"] }
    
    Advanced Filtering Examples:
    - High engagement posts: { "query": "programming", "numericFilters": ["points>=100", "num_comments>=50"] }
    - OR logic for tags: { "query": "web", "tags": ["(story,poll)"] } - returns stories OR polls
    - Author with filters: { "query": "", "tags": ["author_pg", "story"], "numericFilters": ["points>=50"] }
    - Multiple conditions: { "query": "AI", "tags": ["story"], "numericFilters": ["points>=200", "num_comments>=100"] }
    
    Numeric Filter Operators: < (less than), <= (less than or equal), = (equal), >= (greater than or equal), > (greater than)
    Numeric Filter Fields: points, num_comments, created_at_i (Unix timestamp)
    
    Tag Syntax:
    - Single tag: ["story"] - only stories
    - Multiple tags (AND): ["story", "show_hn"] - stories that are also show_hn
    - OR logic: ["(story,poll)"] - stories OR polls
    - Author filter: ["author_USERNAME"] - posts by specific author
    
    Returns paginated results with hits, total count, and page information.`,
    	inputSchema: {
    		type: "object",
    		properties: {
    			query: {
    				type: "string",
    				description: "Search query text (minimum 1 character)",
    			},
    			tags: {
    				type: "array",
    				items: { type: "string" },
    				description:
    					"Optional filter tags (e.g., ['story'], ['comment'], ['(story,poll)'] for OR logic, ['author_pg'] for author filter)",
    			},
    			numericFilters: {
    				type: "array",
    				items: { type: "string" },
    				description:
    					"Optional numeric filters (e.g., ['points>=100'], ['num_comments>=50'], ['created_at_i>1640000000']). Multiple filters use AND logic.",
    			},
    			page: {
    				type: "number",
    				description: "Page number (0-indexed, default: 0)",
    				default: 0,
    			},
    			hitsPerPage: {
    				type: "number",
    				description: "Results per page (1-1000, default: 20)",
    				default: 20,
    			},
    		},
    		required: ["query"],
    	},
    };
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 of behavioral disclosure. It effectively describes key behaviors: it's a read-only search operation (implied by 'search'), supports pagination with customizable results per page, returns paginated results with hits, total count, and page information, and explains advanced filtering logic (AND/OR). It doesn't mention rate limits or authentication needs, but covers most operational aspects well.

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

Conciseness4/5

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

The description is well-structured with clear sections (Supports, Basic Examples, Advanced Filtering Examples, Numeric Filter Operators, Tag Syntax, Returns). While comprehensive, it could be slightly more concise by reducing some example repetition. Every sentence adds value, and key information is front-loaded.

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 search tool with 5 parameters, 100% schema coverage, but no output schema or annotations, the description provides excellent context. It explains what the tool does, how to use parameters, provides multiple examples, describes return format (paginated results with hits, total count, page info), and covers filtering logic. The main gap is no explicit mention of error cases or rate limits.

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

Parameters4/5

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

Schema description coverage is 100%, so the baseline is 3. The description adds significant value beyond the schema by providing detailed examples of parameter usage, explaining numeric filter operators and fields, detailing tag syntax with OR logic examples, and showing how parameters combine in practice. This goes well beyond the schema's basic descriptions.

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 searches HackerNews for stories, comments, and other content by keyword. It specifies the verb 'search' and resource 'HackerNews content', distinguishing it from sibling tools like get-front-page (specific content), get-item (single item), get-latest-posts (recent posts), and get-user (user info).

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

Usage Guidelines5/5

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

The description explicitly provides usage guidance through examples and context. It shows when to use this tool (e.g., for keyword searches, tag filtering, numeric filtering) versus alternatives like get-front-page (front page only) or get-latest-posts (recent posts without search). The examples illustrate various use cases, making it clear when this tool is appropriate.

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