Skip to main content
Glama
paabloLC

MCP Hacker News

by paabloLC

getShowHNStories

Fetch Show HN submissions from Hacker News to discover new projects and tools shared by developers.

Instructions

Get Show HN stories

Input Schema

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

Implementation Reference

  • The complete tool object for getShowHNStories, including the execute handler function that implements the core logic: fetching Show HN story IDs from /showstories, retrieving items, formatting, and returning structured JSON response.
    {
      name: "getShowHNStories",
      description: "Get Show HN stories",
      inputSchema: {
        type: "object",
        properties: {
          limit: {
            type: "number",
            description: "Number of stories to return (default: 10, max: 30)",
            default: 10,
          },
        },
      },
      execute: async (args: any) => {
        const limit = Math.min(args.limit || 10, 30);
        const showIds = await fetchFromAPI<number[]>("/showstories");
    
        if (!showIds) {
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({
                  error: "Failed to fetch Show HN stories",
                }),
              },
            ],
          };
        }
    
        const stories = await fetchMultipleItems(showIds, 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} Show HN stories`,
                  stories: formattedStories,
                },
                null,
                2
              ),
            },
          ],
        };
      },
    },
  • src/index.ts:44-65 (registration)
    MCP server handles tools/list to register available tools (including getShowHNStories) and tools/call to execute the selected tool by name.
      sendResponse(json.id, {
        tools: tools.map((tool) => ({
          name: tool.name,
          description: tool.description,
          inputSchema: tool.inputSchema,
        })),
      });
    }
    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`,
          },
        });
      }
    }
  • fetchFromAPI helper function used by the handler to fetch '/showstories' IDs and individual story items from the Hacker News API, with caching support.
    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;
      }
    }
  • formatTime utility function used to format story timestamps into human-readable relative time (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`;
    }
  • fetchMultipleItems helper used to parallel-fetch and filter story items by IDs, excluding deleted/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
      );
    }
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 of behavioral disclosure. It only states the action without detailing traits like whether it's read-only, safe, paginated, or rate-limited. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 extremely concise with a single sentence, front-loaded and free of unnecessary words. It efficiently conveys the core purpose without waste, making it easy to parse quickly.

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 the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., story objects, IDs), behavioral constraints, or how it fits with siblings. For a tool with minimal structured data, more context is needed to be fully helpful.

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%, with the single parameter 'limit' fully documented in the schema. The description adds no parameter information beyond what the schema provides, so it meets the baseline of 3 for high schema coverage without compensating value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Get Show HN stories' states the basic action (get) and resource (Show HN stories), but it's vague about what 'get' entails (e.g., list, fetch, retrieve) and doesn't differentiate from siblings like 'getNewStories' or 'getTopStories' beyond specifying the story type. It provides minimal but functional purpose information.

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 on when to use this tool versus alternatives. The description doesn't mention context, prerequisites, or exclusions, leaving it unclear how it differs from sibling tools like 'getNewStories' or 'getTopStories' beyond the story category.

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