Skip to main content
Glama
imprvhub

mcp-claude-hackernews

hn_story

Fetch detailed information for a specific Hacker News story by providing its unique ID. Use this tool to quickly retrieve targeted story data from the Hacker News platform.

Instructions

Get details for a specific story by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
story_idYesThe ID of the story to fetch

Implementation Reference

  • Executes the hn_story tool: validates story_id argument, fetches story details using HackerNewsAPI.getItemDetails, formats the story data, and returns formatted text response.
    if (name === "hn_story") {
      const storyId = typeof args?.story_id === 'number' ? args.story_id : NaN;
      if (isNaN(storyId)) {
        throw new Error('Story ID must be a number');
      }
      const story = await api.getItemDetails(storyId) as Story | null;
      if (!story) {
        throw new Error(`Story with ID ${storyId} not found`);
      }
      const formattedStory = {
        id: story.id,
        title: story.title,
        by: story.by,
        time: api.formatTime(story.time),
        url: story.url,
        text: story.text ? api.cleanText(story.text) : '',
        score: story.score,
        commentsCount: story.kids?.length || 0
      };
      return {
        content: [
          {
            type: "text",
            text: formatStoryAsText(formattedStory)
          }
        ]
      };
    }
  • index.ts:194-207 (registration)
    Registers the hn_story tool in the ListTools response, including name, description, and input schema requiring story_id.
    {
      name: "hn_story",
      description: "Get details for a specific story by ID",
      inputSchema: {
        type: "object",
        properties: {
          story_id: {
            type: "number",
            description: "The ID of the story to fetch"
          }
        },
        required: ["story_id"]
      }
    },
  • Formats the story details into a readable text string used by the hn_story handler.
    function formatStoryAsText(story: FormattedStory): string {
      if (!story) {
        return "Story not found.";
      }
      
      let result = `Title: ${story.title}
    ID: ${story.id}
    By: ${story.by}
    Published: ${story.time}
    Score: ${story.score}
    Comments: ${story.commentsCount}
    URL: ${story.url || 'N/A'}`;
    
      if (story.text) {
        result += `\n\nContent:\n${story.text}`;
      }
      
      return result;
    }
  • Fetches item details (story or comment) from Hacker News API by ID, used by hn_story handler.
    async getItemDetails(itemId: number): Promise<Story | Comment | null> {
      try {
        const response = await axios.get(`${baseUrl}/item/${itemId}.json`);
        return response.data;
      } catch (error) {
        console.error(`Error fetching item ${itemId}:`, error);
        return null;
      }
    }
Install Server

Other Tools

Related 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/imprvhub/mcp-claude-hackernews'

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