Skip to main content
Glama
wei
by wei

Search HackerNews Posts

search-posts

Search HackerNews posts using keywords, tags, and numeric filters to find relevant content sorted by relevance, points, and comments.

Instructions

Search HackerNews posts by relevance (sorted by relevance, then points, then number of comments)

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)
queryYesSearch query text
tagsNoFilter tags (e.g., "story", "comment", "poll", "show_hn", "ask_hn", "front_page", "author_USERNAME", "story_ID")

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
hitsYes
pageYes
nbHitsYes
nbPagesYes
hitsPerPageYes

Implementation Reference

  • The handler function for the 'search-posts' tool. It constructs query parameters from inputs, calls the HackerNews Algolia /search endpoint via the fetchHN helper, and returns the results as both text and structured content.
    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?${params.toString()}`;
      const result = await fetchHN(endpoint);
      
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
        structuredContent: result
      };
    }
  • The inputSchema and outputSchema definitions using Zod for validating parameters and response of the 'search-posts' tool.
    {
      title: 'Search HackerNews Posts',
      description: 'Search HackerNews posts by relevance (sorted by relevance, then points, then number of comments)',
      inputSchema: {
        query: z.string().describe('Search query text'),
        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:26-62 (registration)
    The complete registration of the 'search-posts' tool using McpServer.registerTool, including name, schema, and handler.
    server.registerTool(
      'search-posts',
      {
        title: 'Search HackerNews Posts',
        description: 'Search HackerNews posts by relevance (sorted by relevance, then points, then number of comments)',
        inputSchema: {
          query: z.string().describe('Search query text'),
          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?${params.toString()}`;
        const result = await fetchHN(endpoint);
        
        return {
          content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
          structuredContent: result
        };
      }
    );
  • Shared helper function fetchHN used by the 'search-posts' handler (and other tools) to make API calls 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();
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions sorting behavior, which is valuable, but doesn't cover other important aspects like pagination handling (implied by 'page' parameter), rate limits, authentication requirements, error conditions, or what the output contains. For a search tool with 5 parameters, this leaves significant gaps.

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 a single, efficient sentence that communicates the core functionality and sorting behavior without any wasted words. It's appropriately sized for the tool's complexity and gets straight to the point.

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

Completeness3/5

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

Given that there's an output schema (which handles return values) and 100% schema description coverage, the description provides adequate context for basic understanding. However, for a search tool with multiple sibling alternatives and no annotations, it should ideally provide more guidance on usage scenarios and behavioral expectations beyond just sorting.

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?

The schema description coverage is 100%, providing good documentation for all 5 parameters. The description adds the sorting criteria ('by relevance, then points, then number of comments'), which gives context about how results are ordered beyond what individual parameters specify. However, it doesn't explain parameter interactions or provide additional semantic context beyond the schema.

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

Purpose4/5

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

The description clearly states the action ('search') and resource ('HackerNews posts'), and specifies the sorting criteria ('by relevance, then points, then number of comments'). However, it doesn't explicitly differentiate from sibling tools like 'search-by-time-range' or 'search-posts-by-date', which reduces it from a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With multiple sibling search tools available (e.g., 'search-by-time-range', 'search-posts-by-date'), there's no indication of when this relevance-based search is preferred over time-based or date-based searches.

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

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