Skip to main content
Glama
devabdultech

Hacker News MCP Server

getStoryWithComments

Retrieve Hacker News stories along with their associated comments using story IDs to analyze discussions and content in context.

Instructions

Get a story with its comments

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe ID of the story

Implementation Reference

  • Main handler for the 'getStoryWithComments' tool. Fetches story data using algoliaApi and formats the story details with a recursive comment tree representation.
    case "getStoryWithComments": {
      const { id } = args as { id: number };
      try {
        const data = await algoliaApi.getStoryWithComments(id);
        if (!data || !data.title) {
          throw new McpError(
            ErrorCode.InvalidParams,
            `Story with ID ${id} not found`
          );
        }
    
        const formatCommentTree = (comment: any, depth = 0): string => {
          const indent = "  ".repeat(depth);
          let text = `${indent}Comment by ${comment.author} (ID: ${comment.id}):\n`;
          text += `${indent}${comment.text}\n`;
          text += `${indent}Posted: ${comment.created_at}\n\n`;
    
          if (comment.children) {
            text += comment.children
              .map((child: any) => formatCommentTree(child, depth + 1))
              .join("");
          }
          return text;
        };
    
        const text =
          `Story ID: ${data.id}\n` +
          `Title: ${data.title}\n` +
          `URL: ${data.url || "(text post)"}\n` +
          `Points: ${data.points} | Author: ${data.author}\n\n` +
          `Comments:\n` +
          (data.children || [])
            .map((comment: any) => formatCommentTree(comment))
            .join("");
    
        return {
          content: [{ type: "text", text: text.trim() }],
        };
      } catch (err) {
        const error = err as Error;
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to fetch story: ${error.message}`
        );
      }
    }
  • src/index.ts:80-90 (registration)
    Tool registration in the ListTools handler, including name, description, and input schema.
    {
      name: "getStoryWithComments",
      description: "Get a story with its comments",
      inputSchema: {
        type: "object",
        properties: {
          id: { type: "number", description: "The ID of the story" },
        },
        required: ["id"],
      },
    },
  • Helper function in AlgoliaAPI that fetches the story item (including comments) from the Hacker News Algolia API endpoint.
    async getStoryWithComments(storyId: number): Promise<any> {
      const response = await fetch(`${API_BASE_URL}/items/${storyId}`);
      return response.json();
    }
  • Usage of the helper in another tool handler 'getCommentTree'.
    const data = await algoliaApi.getStoryWithComments(storyId);
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It lacks details on permissions, rate limits, error handling, or whether comments are paginated/nested. For a read operation without annotations, this is insufficient behavioral disclosure.

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, clear sentence with zero wasted words. It is appropriately sized for a simple tool and front-loads the core functionality effectively.

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 no annotations and no output schema, the description is incomplete. It doesn't explain what 'with its comments' entails (e.g., comment structure, limits, ordering) or the return format, leaving significant gaps for a tool that combines story and comment data.

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 already documents the 'id' parameter fully. The description adds no additional meaning about the parameter beyond what the schema provides, such as format examples or constraints, meeting the baseline for high schema coverage.

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 ('a story with its comments'), making the purpose understandable. It distinguishes from 'getStory' by specifying inclusion of comments, but doesn't differentiate from other comment-related siblings like 'getCommentTree' or 'getComments'.

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?

No guidance is provided about when to use this tool versus alternatives like 'getStory' (for story only) or 'getCommentTree' (for hierarchical comments). The description implies it retrieves both story and comments together, but offers no explicit comparison or usage context.

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