Skip to main content
Glama

search-posts-by-date

Find HackerNews posts by searching with keywords, filtering by tags and numeric criteria, and viewing results sorted by date.

Instructions

Search HackerNews posts sorted by date (most recent first)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hitsPerPageNoNumber of results per page (default: 20)
numericFiltersNoNumeric filters (e.g., "points>100", "created_at_i>1672531200")
pageNoPage number for pagination (default: 0)
queryNoSearch query text (optional)
tagsNoFilter tags (e.g., "story", "comment", "poll", "show_hn", "ask_hn", "front_page", "author_USERNAME", "story_ID")

Implementation Reference

  • The handler function that implements the core logic of the 'search-posts-by-date' tool. It builds URL parameters from inputs and calls the fetchHN helper to query the HackerNews Algolia API's /search_by_date endpoint.
    async ({ query, tags, numericFilters, page, hitsPerPage }) => { const params = new URLSearchParams(); if (query) params.append('query', query); if (tags) params.append('tags', tags); if (numericFilters) params.append('numericFilters', numericFilters); if (page !== undefined) params.append('page', page.toString()); if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString()); const endpoint = `/search_by_date?${params.toString()}`; const result = await fetchHN(endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result }; }
  • Input and output schema definitions for the 'search-posts-by-date' tool using Zod, including optional parameters for query, tags, numeric filters, pagination.
    { title: 'Search HackerNews Posts by Date', description: 'Search HackerNews posts sorted by date (most recent first)', inputSchema: { query: z.string().optional().describe('Search query text (optional)'), tags: z.string().optional().describe('Filter tags (e.g., "story", "comment", "poll", "show_hn", "ask_hn", "front_page", "author_USERNAME", "story_ID")'), numericFilters: z.string().optional().describe('Numeric filters (e.g., "points>100", "created_at_i>1672531200")'), page: z.number().optional().describe('Page number for pagination (default: 0)'), hitsPerPage: z.number().optional().describe('Number of results per page (default: 20)') }, outputSchema: { hits: z.array(z.any()), nbHits: z.number(), nbPages: z.number(), page: z.number(), hitsPerPage: z.number() }
  • src/index.ts:65-101 (registration)
    The server.registerTool call that registers the 'search-posts-by-date' tool with the MCP server, including its schema and handler function.
    server.registerTool( 'search-posts-by-date', { title: 'Search HackerNews Posts by Date', description: 'Search HackerNews posts sorted by date (most recent first)', inputSchema: { query: z.string().optional().describe('Search query text (optional)'), tags: z.string().optional().describe('Filter tags (e.g., "story", "comment", "poll", "show_hn", "ask_hn", "front_page", "author_USERNAME", "story_ID")'), numericFilters: z.string().optional().describe('Numeric filters (e.g., "points>100", "created_at_i>1672531200")'), page: z.number().optional().describe('Page number for pagination (default: 0)'), hitsPerPage: z.number().optional().describe('Number of results per page (default: 20)') }, outputSchema: { hits: z.array(z.any()), nbHits: z.number(), nbPages: z.number(), page: z.number(), hitsPerPage: z.number() } }, async ({ query, tags, numericFilters, page, hitsPerPage }) => { const params = new URLSearchParams(); if (query) params.append('query', query); if (tags) params.append('tags', tags); if (numericFilters) params.append('numericFilters', numericFilters); if (page !== undefined) params.append('page', page.toString()); if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString()); const endpoint = `/search_by_date?${params.toString()}`; const result = await fetchHN(endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result }; } );
  • Supporting helper function fetchHN used by the tool handler to perform HTTP requests to the HackerNews Algolia API.
    async function fetchHN(endpoint: string): Promise<any> { const response = await fetch(`${HN_API_BASE}${endpoint}`); if (!response.ok) { throw new Error(`HN API error: ${response.status} ${response.statusText}`); } return await response.json(); }

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-vibe'

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