Skip to main content
Glama
paabloLC

MCP Hacker News

by paabloLC

getNewStories

Fetch recent Hacker News stories using the MCP Hacker News server. Specify a limit parameter to control how many stories are returned.

Instructions

Get newest stories from Hacker News

Input Schema

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

Implementation Reference

  • Handler function that fetches the latest story IDs from Hacker News /newstories endpoint, retrieves up to 'limit' story details using fetchMultipleItems, formats the data including time with formatTime, and returns a structured JSON response.
    execute: async (args: any) => {
      const limit = Math.min(args.limit || 10, 50);
      const newIds = await fetchFromAPI<number[]>("/newstories");
    
      if (!newIds) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({ error: "Failed to fetch new stories" }),
            },
          ],
        };
      }
    
      const stories = await fetchMultipleItems(newIds, 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: `Latest ${limit} stories from Hacker News`,
                stories: formattedStories,
              },
              null,
              2
            ),
          },
        ],
      };
    },
  • Input schema defining an optional 'limit' parameter for the number of new stories to retrieve (default 10, maximum 50).
    inputSchema: {
      type: "object",
      properties: {
        limit: {
          type: "number",
          description: "Number of stories to return (default: 10, max: 50)",
          default: 10,
        },
      },
    },
  • src/tools.ts:128-184 (registration)
    Registration of the 'getNewStories' tool as an object in the exported 'tools' array, which is imported and used by the MCP server in src/index.ts for tools/list and tools/call methods.
    {
      name: "getNewStories",
      description: "Get newest stories from Hacker News",
      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 newIds = await fetchFromAPI<number[]>("/newstories");
    
        if (!newIds) {
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({ error: "Failed to fetch new stories" }),
              },
            ],
          };
        }
    
        const stories = await fetchMultipleItems(newIds, 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: `Latest ${limit} stories from Hacker News`,
                  stories: formattedStories,
                },
                null,
                2
              ),
            },
          ],
        };
      },
    },
  • Core helper function to fetch data from Hacker News API endpoints (used for /newstories), with caching via getCached/setCache.
    export async function fetchFromAPI<T>(endpoint: string): Promise<T | null> {
      const cacheKey = endpoint;
      const cached = getCached<T>(cacheKey);
      if (cached) return cached;
    
      try {
        const response = await fetch(
          `https://hacker-news.firebaseio.com/v0${endpoint}.json`
        );
        if (!response.ok) throw new Error(`HTTP ${response.status}`);
    
        const data = await response.json();
        setCache(cacheKey, data);
        return data;
      } catch (error) {
        console.error(`Error fetching ${endpoint}:`, error);
        return null;
      }
    }
  • Helper to fetch multiple story items in parallel from their IDs, filtering non-null and non-deleted/dead items (used after fetching new story IDs).
    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
      );
    }
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 retrieves stories but doesn't mention any behavioral traits such as rate limits, authentication needs, pagination, or what happens if the limit exceeds available stories. This leaves significant gaps in understanding how the tool behaves in practice.

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 front-loaded with the core purpose ('Get newest stories'), making it highly efficient and easy to parse, which is ideal for conciseness.

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) and high schema coverage, the description is minimally adequate. However, with no annotations and no output schema, it lacks details on behavioral aspects and return values, making it incomplete for fully informed use without additional context.

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, fully documenting the 'limit' parameter with its type, default, and max value. The description adds no additional parameter semantics beyond what the schema provides, so it meets the baseline score of 3 for high schema coverage without adding 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 ('newest stories from Hacker News'), making the tool's purpose immediately understandable. However, it doesn't explicitly differentiate from siblings like 'getTopStories' or 'getBestStories' beyond the 'newest' qualifier, which is why it doesn't reach a perfect score.

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 'getTopStories' or 'getBestStories'. It lacks any context about what 'newest' means (e.g., by time, by ID) or prerequisites for use, leaving the agent to infer usage from the name 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