Skip to main content
Glama
devabdultech

Hacker News MCP Server

search

Find stories and comments on Hacker News by searching with specific queries, content types, and pagination controls.

Instructions

Search for stories and comments on Hacker News

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query
typeNoThe type of content to search forall
pageNoThe page number
hitsPerPageNoThe number of results per page

Implementation Reference

  • Handler function for the 'search' tool: validates arguments using SearchParamsSchema, performs search via algoliaApi, formats results into a numbered list and returns as text content.
    case "search": {
      const validatedArgs = validateInput(SearchParamsSchema, args);
      const { query, type, page, hitsPerPage } = validatedArgs;
      const tags = type === "all" ? undefined : type;
      const results = await algoliaApi.search(query, {
        tags,
        page,
        hitsPerPage,
      });
    
      const hits = results.hits || [];
      const text = hits
        .map(
          (hit: any, index: number) =>
            `${index + 1}. ${hit.title}\n` +
            `   ID: ${hit.objectID}\n` +
            `   URL: ${hit.url || "(text post)"}\n` +
            `   Points: ${hit.points} | Author: ${hit.author} | Comments: ${hit.num_comments}\n\n`
        )
        .join("");
    
      return {
        content: [{ type: "text", text: text.trim() }],
      };
    }
  • Zod schema defining the input parameters for the 'search' tool, used for validation in the handler.
    export const SearchParamsSchema = z.object({
      query: z.string(),
      type: z.enum(["all", "story", "comment"]).default("all"),
      page: z.number().int().min(0).default(0),
      hitsPerPage: z.number().int().min(1).max(100).default(20),
    });
  • src/index.ts:42-68 (registration)
    Registration of the 'search' tool in the ListTools response, specifying name, description, and JSON schema for inputs.
    {
      name: "search",
      description: "Search for stories and comments on Hacker News",
      inputSchema: {
        type: "object",
        properties: {
          query: { type: "string", description: "The search query" },
          type: {
            type: "string",
            enum: ["all", "story", "comment"],
            description: "The type of content to search for",
            default: "all",
          },
          page: {
            type: "number",
            description: "The page number",
            default: 0,
          },
          hitsPerPage: {
            type: "number",
            description: "The number of results per page",
            default: 20,
          },
        },
        required: ["query"],
      },
    },
  • algoliaApi.search helper function that constructs the Algolia HN search API request and fetches results.
    async search(
      query: string,
      options: {
        tags?: string;
        numericFilters?: string;
        page?: number;
        hitsPerPage?: number;
      } = {}
    ): Promise<any> {
      const params = new URLSearchParams();
      params.append("query", query);
    
      if (options.tags) params.append("tags", options.tags);
      if (options.numericFilters)
        params.append("numericFilters", options.numericFilters);
      if (options.page !== undefined)
        params.append("page", options.page.toString());
      if (options.hitsPerPage !== undefined)
        params.append("hitsPerPage", options.hitsPerPage.toString());
    
      const url = `${API_BASE_URL}/search?${params.toString()}`;
      const response = await fetch(url);
      return response.json();
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'search' but doesn't disclose behavioral traits like pagination behavior (implied by 'page' and 'hitsPerPage' parameters but not explained), rate limits, authentication needs, or what the output looks like. This is inadequate for a tool with multiple parameters and no output schema.

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 directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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

Completeness2/5

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

Given the complexity (4 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain the search functionality, result format, or how parameters interact, leaving significant gaps for the agent to infer behavior. This is insufficient for effective tool selection and invocation.

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 fully documents all parameters. The description adds no additional meaning beyond the schema, such as explaining search syntax, result ordering, or default behaviors. This meets the baseline for high schema coverage but doesn't enhance understanding.

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 for') and target resources ('stories and comments on Hacker News'), which is specific and unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'getStories' or 'getComments', which appear to retrieve content without searching.

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 sibling tools like 'getStories' and 'getComments' available, there's no indication of whether this is for filtered retrieval, keyword-based search, or other use cases, leaving the agent to guess based on tool names alone.

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/devabdultech/hn-mcp'

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