Skip to main content
Glama
paabloLC

MCP Hacker News

by paabloLC

getItem

Retrieve specific Hacker News items like stories, comments, or jobs by their unique ID to access detailed information.

Instructions

Get a specific item (story, comment, job, etc.) by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe item ID to fetch

Implementation Reference

  • The execute handler for the 'getItem' tool, which fetches the specific Hacker News item by ID using fetchFromAPI, formats its properties including time and HN URL, and returns a structured JSON response.
    execute: async (args: any) => {
      const item = await fetchFromAPI<HackerNewsItem>(`/item/${args.id}`);
    
      if (!item) {
        return {
          content: [
            { type: "text", text: JSON.stringify({ error: "Item not found" }) },
          ],
        };
      }
    
      const formattedItem = {
        id: item.id,
        type: item.type,
        title: item.title,
        url: item.url,
        score: item.score,
        author: item.by,
        time: item.time ? formatTime(item.time) : "unknown",
        comments: item.descendants || 0,
        text: item.text,
        parent: item.parent,
        kids: item.kids,
        hnUrl: `https://news.ycombinator.com/item?id=${item.id}`,
      };
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                message: `Item ${args.id}`,
                item: formattedItem,
              },
              null,
              2
            ),
          },
        ],
      };
    },
  • Input schema for 'getItem' tool, requiring a numeric 'id' parameter.
    inputSchema: {
      type: "object",
      properties: {
        id: {
          type: "number",
          description: "The item ID to fetch",
        },
      },
      required: ["id"],
    },
  • src/tools.ts:358-413 (registration)
    The complete 'getItem' tool object registered in the exported 'tools' array, which is imported and used by the MCP server in index.ts for tool listing and execution.
    {
      name: "getItem",
      description: "Get a specific item (story, comment, job, etc.) by ID",
      inputSchema: {
        type: "object",
        properties: {
          id: {
            type: "number",
            description: "The item ID to fetch",
          },
        },
        required: ["id"],
      },
      execute: async (args: any) => {
        const item = await fetchFromAPI<HackerNewsItem>(`/item/${args.id}`);
    
        if (!item) {
          return {
            content: [
              { type: "text", text: JSON.stringify({ error: "Item not found" }) },
            ],
          };
        }
    
        const formattedItem = {
          id: item.id,
          type: item.type,
          title: item.title,
          url: item.url,
          score: item.score,
          author: item.by,
          time: item.time ? formatTime(item.time) : "unknown",
          comments: item.descendants || 0,
          text: item.text,
          parent: item.parent,
          kids: item.kids,
          hnUrl: `https://news.ycombinator.com/item?id=${item.id}`,
        };
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  message: `Item ${args.id}`,
                  item: formattedItem,
                },
                null,
                2
              ),
            },
          ],
        };
      },
    },
  • The fetchFromAPI helper function used by getItem to retrieve data from 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;
      }
    }
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 it 'gets' an item, implying a read operation, but doesn't cover aspects like authentication needs, rate limits, error handling, or what happens if the ID is invalid. This leaves significant gaps 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 that front-loads the core action ('Get a specific item') and includes key details (item types and ID requirement) without any wasted words. It's appropriately sized for its purpose.

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 return values, error cases, or behavioral traits like rate limits. For a tool with no structured data support, more context is needed to adequately guide an AI agent.

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 'id' documented as 'The item ID to fetch'. The description adds minimal value by mentioning the item types (e.g., story, comment) but doesn't provide additional syntax or format details beyond what the schema already specifies.

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 specific item'), specifying it can fetch various item types like stories, comments, and jobs by ID. However, it doesn't explicitly differentiate from siblings like 'getComments' or 'getUser', which might fetch similar items through different mechanisms.

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 like 'getComments' or 'getUser', which might retrieve similar data. The description implies usage for fetching by ID but lacks explicit context, prerequisites, or exclusions.

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