Skip to main content
Glama
paabloLC

MCP Hacker News

by paabloLC

getBestStories

Retrieve algorithmically ranked stories from Hacker News to access top community content programmatically.

Instructions

Get best stories from Hacker News (algorithmically ranked)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNumber of stories to return (default: 10, max: 50)

Implementation Reference

  • The execute handler function for getBestStories tool. Fetches best story IDs from HN API, retrieves story details using helper functions, formats the data including relative time and HN links, and returns a JSON-formatted text content response.
    execute: async (args: any) => {
      const limit = Math.min(args.limit || 10, 50);
      const bestIds = await fetchFromAPI<number[]>("/beststories");
    
      if (!bestIds) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({ error: "Failed to fetch best stories" }),
            },
          ],
        };
      }
    
      const stories = await fetchMultipleItems(bestIds, limit);
      const formattedStories = stories.map((story) => ({
        id: story.id,
        title: story.title,
        url: story.url,
        score: story.score,
        author: story.by,
        comments: story.descendants || 0,
        time: story.time ? formatTime(story.time) : "unknown",
        hnUrl: `https://news.ycombinator.com/item?id=${story.id}`,
      }));
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                message: `Best ${limit} stories from Hacker News`,
                stories: formattedStories,
              },
              null,
              2
            ),
          },
        ],
      };
    },
  • Input schema defining the optional 'limit' parameter for the number of best stories to retrieve (default 10, max 50).
    inputSchema: {
      type: "object",
      properties: {
        limit: {
          type: "number",
          description: "Number of stories to return (default: 10, max: 50)",
          default: 10,
        },
      },
    },
  • src/tools.ts:71-127 (registration)
    The full tool definition object for 'getBestStories' included in the exported 'tools' array, which is imported and served by index.ts for MCP tools/list and tools/call methods.
    {
      name: "getBestStories",
      description: "Get best stories from Hacker News (algorithmically ranked)",
      inputSchema: {
        type: "object",
        properties: {
          limit: {
            type: "number",
            description: "Number of stories to return (default: 10, max: 50)",
            default: 10,
          },
        },
      },
      execute: async (args: any) => {
        const limit = Math.min(args.limit || 10, 50);
        const bestIds = await fetchFromAPI<number[]>("/beststories");
    
        if (!bestIds) {
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({ error: "Failed to fetch best stories" }),
              },
            ],
          };
        }
    
        const stories = await fetchMultipleItems(bestIds, limit);
        const formattedStories = stories.map((story) => ({
          id: story.id,
          title: story.title,
          url: story.url,
          score: story.score,
          author: story.by,
          comments: story.descendants || 0,
          time: story.time ? formatTime(story.time) : "unknown",
          hnUrl: `https://news.ycombinator.com/item?id=${story.id}`,
        }));
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  message: `Best ${limit} stories from Hacker News`,
                  stories: formattedStories,
                },
                null,
                2
              ),
            },
          ],
        };
      },
    },
  • Helper function used to fetch multiple story items in parallel from HN API, filtering out deleted/dead items. Called with bestIds and limit.
    export async function fetchMultipleItems(
      ids: number[],
      maxItems = 30
    ): Promise<HackerNewsItem[]> {
      const limitedIds = ids.slice(0, maxItems);
      const promises = limitedIds.map((id) =>
        fetchFromAPI<HackerNewsItem>(`/item/${id}`)
      );
      const results = await Promise.all(promises);
    
      return results.filter(
        (item): item is HackerNewsItem =>
          item !== null && !item.deleted && !item.dead
      );
    }
  • Helper function to format Unix timestamps to human-readable relative time strings (e.g., '2h ago'), used for story time fields.
    export function formatTime(timestamp: number): string {
      const date = new Date(timestamp * 1000);
      const now = new Date();
      const diff = now.getTime() - date.getTime();
    
      const minutes = Math.floor(diff / (1000 * 60));
      const hours = Math.floor(diff / (1000 * 60 * 60));
      const days = Math.floor(diff / (1000 * 60 * 60 * 24));
    
      if (minutes < 60) return `${minutes}m ago`;
      if (hours < 24) return `${hours}h ago`;
      return `${days}d ago`;
    }
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. It mentions 'algorithmically ranked' which adds some behavioral context, but lacks details on rate limits, authentication needs, pagination, or response format. For a read operation with no annotations, this leaves significant gaps in understanding how the tool behaves.

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. It's front-loaded with the core action and resource, with no wasted words. Every part of the sentence earns its place by clarifying the ranking mechanism.

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 (one optional parameter, no output schema, no annotations), the description is minimally adequate. It covers what the tool does but lacks context on usage, behavioral details, or output. Without annotations or output schema, the agent has incomplete information about the tool's operation and results.

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 'limit' parameter. The description adds no parameter-specific information beyond what the schema provides. According to guidelines, baseline is 3 when schema coverage is high (>80%) and no param info is in the description.

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 ('best stories from Hacker News') with additional context about ranking ('algorithmically ranked'). It distinguishes from siblings like 'getTopStories' or 'getNewStories' by specifying the 'best' algorithmic ranking. However, it doesn't explicitly contrast with all siblings like 'getAskHNStories' or 'getJobStories'.

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 when to choose 'getBestStories' over siblings like 'getTopStories' or 'getNewStories', nor does it specify prerequisites or exclusions. The agent must infer usage from the name and description 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/paabloLC/mcp-hacker-news'

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