Skip to main content
Glama
wei
by wei

Get Ask HN Posts

get-ask-hn

Retrieve Ask HN posts where HackerNews users ask questions to the community, with pagination support for browsing multiple pages of results.

Instructions

Get latest "Ask HN" posts where users ask questions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hitsPerPageNoNumber of results per page (default: 20)
pageNoPage number for pagination (default: 0)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
hitsYes
pageYes
nbHitsYes
nbPagesYes
hitsPerPageYes

Implementation Reference

  • Handler function that fetches the latest 'Ask HN' posts from the HackerNews API using the /search_by_date endpoint with the 'ask_hn' tag filter. Supports pagination via page and hitsPerPage parameters. Returns results in both plain text JSON and structured content formats.
    async ({ page, hitsPerPage }) => {
      const params = new URLSearchParams();
      params.append('tags', 'ask_hn');
      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 schemas defined using Zod for the 'get-ask-hn' tool, including optional pagination parameters for input and expected search result structure for output.
    {
      title: 'Get Ask HN Posts',
      description: 'Get latest "Ask HN" posts where users ask questions',
      inputSchema: {
        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:240-271 (registration)
    Full registration of the 'get-ask-hn' tool on the MCP server using server.registerTool, including name, metadata, schema, and handler function.
    server.registerTool(
      'get-ask-hn',
      {
        title: 'Get Ask HN Posts',
        description: 'Get latest "Ask HN" posts where users ask questions',
        inputSchema: {
          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 ({ page, hitsPerPage }) => {
        const params = new URLSearchParams();
        params.append('tags', 'ask_hn');
        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
        };
      }
    );
  • Shared helper function used by the 'get-ask-hn' handler (and other tools) to perform API requests to the HackerNews Algolia API and handle errors.
    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?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves posts but lacks details on permissions, rate limits, data freshness, or response format. While it implies a read-only operation, it doesn't confirm safety or other behavioral traits, leaving significant gaps for an agent.

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 is front-loaded and appropriately sized, with every element contributing to clarity, making it highly concise and well-structured.

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 the tool's low complexity (2 parameters, no annotations, but with an output schema), the description is minimally adequate. It covers the basic purpose but lacks behavioral context and usage guidelines. The presence of an output schema mitigates the need to explain return values, but overall completeness is limited to the core function.

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 the two parameters (hitsPerPage and page) with their types and defaults. The description adds no parameter-specific information beyond what the schema provides, resulting in a baseline score of 3 as the schema handles the heavy lifting.

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 verb ('Get') and resource ('latest "Ask HN" posts where users ask questions'), making the purpose evident. It distinguishes from some siblings like 'get-top-stories' or 'get-polls' by specifying the content type, though it doesn't explicitly differentiate from similar tools like 'get-show-hn' or 'get-latest-stories' beyond the 'Ask HN' focus.

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. It doesn't mention scenarios for using 'get-ask-hn' over other tools like 'search-posts' or 'get-latest-stories', nor does it specify prerequisites or exclusions, leaving usage context implied at best.

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