Skip to main content
Glama
paabloLC

MCP Hacker News

by paabloLC

getTopStories

Fetch top stories from Hacker News using the MCP Hacker News server. Retrieve up to 50 stories to access trending tech news and discussions.

Instructions

Get top stories from Hacker News (up to 500 available)

Input Schema

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

Implementation Reference

  • The async execute handler function for the getTopStories tool. It fetches the top story IDs from Hacker News API, limits and fetches the story details using helper functions, formats the output including time and HN URLs, and returns a structured JSON response.
    execute: async (args: any) => {
      const limit = Math.min(args.limit || 10, 50);
      const topIds = await fetchFromAPI<number[]>("/topstories");
    
      if (!topIds) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({ error: "Failed to fetch top stories" }),
            },
          ],
        };
      }
    
      const stories = await fetchMultipleItems(topIds, 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: `Top ${limit} stories from Hacker News`,
                stories: formattedStories,
              },
              null,
              2
            ),
          },
        ],
      };
    },
  • The input schema for getTopStories tool, defining an optional 'limit' parameter (number, default 10).
    inputSchema: {
      type: "object",
      properties: {
        limit: {
          type: "number",
          description: "Number of stories to return (default: 10, max: 50)",
          default: 10,
        },
      },
    },
  • src/index.ts:52-65 (registration)
    MCP server registration and invocation logic for all tools, including getTopStories. Finds the tool by name from the imported tools array and executes its handler.
    if (json.method === "tools/call") {
      const tool = tools.find((tool) => tool.name === json.params.name);
      if (tool) {
        const toolResponse = await tool.execute(json.params.arguments);
        sendResponse(json.id, toolResponse);
      } else {
        sendResponse(json.id, {
          error: {
            code: -32602,
            message: `MCP error -32602: Tool ${json.params.name} not found`,
          },
        });
      }
    }
  • Helper function used in getTopStories to fetch multiple story items by IDs in parallel, filtering out deleted or dead items.
    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 used to format Unix timestamps into human-readable relative time strings (e.g., '2h ago').
    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?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool fetches stories and mentions availability ('up to 500'), but lacks details on rate limits, authentication needs, error handling, or response format. This is a significant gap 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 with zero wasted words. It's front-loaded with the core purpose and includes a useful scope note, making it appropriately sized and easy to parse.

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, no output schema, and a simple input schema, the description is incomplete. It lacks behavioral context (e.g., rate limits, response structure) and doesn't compensate for the absence of structured fields, making it inadequate for a tool that likely returns 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?

The input schema has 100% description coverage, documenting the 'limit' parameter with default and max values. The description adds no additional parameter information beyond implying a range ('up to 500'), which doesn't enhance the schema's details. Baseline 3 is appropriate as the schema does 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 action ('Get') and resource ('top stories from Hacker News'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from siblings like 'getBestStories' or 'getNewStories' beyond mentioning 'top stories', which is somewhat vague compared to the specific sibling names.

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 'getBestStories' or 'getNewStories'. It mentions 'up to 500 available', which hints at scope but doesn't clarify context or exclusions, leaving the agent with minimal usage direction.

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