Skip to main content
Glama
wei
by wei

Get Latest HackerNews Comments

get-latest-comments

Retrieve recently posted comments from HackerNews to monitor community discussions and stay updated on current conversations.

Instructions

Get the most recent comments posted to HackerNews

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

  • The handler function for the 'get-latest-comments' tool. It constructs a search query for recent comments (tag 'comment') using the HackerNews Algolia API's search_by_date endpoint and returns the structured results along with a JSON string representation.
    async ({ page, hitsPerPage }) => {
      const params = new URLSearchParams();
      params.append('tags', 'comment');
      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
      };
    }
  • The input and output schema definitions for the 'get-latest-comments' tool, using Zod for validation. Input supports optional pagination parameters; output matches the HN API search response structure.
    {
      title: 'Get Latest HackerNews Comments',
      description: 'Get the most recent comments posted to HackerNews',
      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:172-203 (registration)
    The registration of the 'get-latest-comments' tool using McpServer.registerTool, including the tool name, schema, and handler function.
    server.registerTool(
      'get-latest-comments',
      {
        title: 'Get Latest HackerNews Comments',
        description: 'Get the most recent comments posted to HackerNews',
        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', 'comment');
        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 to make API calls to the HackerNews Algolia API, used by the get-latest-comments handler and other tools.
    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 retrieving 'most recent comments' but doesn't specify whether this is a read-only operation, if there are rate limits, how freshness is determined, or what the output format looks like. The description is too vague for a tool with no annotation coverage.

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 states the core functionality without unnecessary words. It's appropriately sized and front-loaded with the essential information, making it easy to parse quickly.

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), 100% schema coverage for parameters, and no complex behavioral aspects, the description is minimally adequate. However, for a tool with no annotations, it should provide more context about the operation's nature (e.g., read-only, potential limitations) to be truly complete.

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 input schema has 100% description coverage, with both parameters ('hitsPerPage' and 'page') clearly documented in the schema itself. The description adds no additional parameter information beyond what's already in the structured schema, so it meets the baseline expectation but doesn't provide extra value.

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 ('Get') and resource ('most recent comments posted to HackerNews'), making the tool's purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get-story-comments' or 'search-posts-by-date', which might also retrieve comments in different contexts.

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 like 'get-story-comments' (which might fetch comments for a specific story) or 'search-posts-by-date' (which could filter comments by time). It simply states what the tool does without context about appropriate use cases.

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