Skip to main content
Glama
wei
by wei

get-story-comments

Retrieve all comments for a specific HackerNews story using its ID, with pagination support for browsing through discussion threads.

Instructions

Get all comments for a specific story by story ID

Input Schema

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

Implementation Reference

  • Executes the tool by querying HackerNews API for comments on a specific story ID using tags 'comment,story_${storyId}', with optional pagination, and returns formatted results.
    async ({ storyId, page, hitsPerPage }) => {
      const params = new URLSearchParams();
      params.append('tags', `comment,story_${storyId}`);
      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
      };
    }
  • Input schema requires storyId (number) and optional page/hitsPerPage; output schema defines search result structure.
    {
      title: 'Get Comments for a Story',
      description: 'Get all comments for a specific story by story ID',
      inputSchema: {
        storyId: z.number().describe('The ID of the story'),
        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:371-402 (registration)
    Registers the 'get-story-comments' tool with McpServer, including schema and handler function.
      'get-story-comments',
      {
        title: 'Get Comments for a Story',
        description: 'Get all comments for a specific story by story ID',
        inputSchema: {
          storyId: z.number().describe('The ID of the story'),
          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 ({ storyId, page, hitsPerPage }) => {
        const params = new URLSearchParams();
        params.append('tags', `comment,story_${storyId}`);
        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 utility to make API calls to HackerNews Algolia API, used by get-story-comments 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();
    }

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