Skip to main content
Glama
paabloLC

MCP Hacker News

by paabloLC

getUpdates

Retrieve recently updated Hacker News items and profiles to monitor new activity and changes in real-time.

Instructions

Get recently updated items and profiles

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The execute handler function for the 'getUpdates' MCP tool. It fetches recent updates from the Hacker News '/updates' endpoint, handles errors, limits results to top 10 items and profiles, and returns a standardized MCP content response with JSON text.
    execute: async (args: any) => {
      const updates = await fetchFromAPI<HackerNewsUpdates>("/updates");
    
      if (!updates) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({ error: "Failed to fetch updates" }),
            },
          ],
        };
      }
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                message: "Recent updates",
                recentlyUpdatedItems: updates.items.slice(0, 10),
                recentlyUpdatedProfiles: updates.profiles.slice(0, 10),
              },
              null,
              2
            ),
          },
        ],
      };
    },
  • Input schema definition for the 'getUpdates' tool, specifying no required parameters.
    inputSchema: { type: "object", properties: {} },
  • src/index.ts:52-65 (registration)
    MCP 'tools/call' request handler in the main server that locates the 'getUpdates' tool by name from the tools array and invokes its execute method with arguments.
    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 utility function called by the getUpdates handler to retrieve data from the Hacker News API (used with endpoint '/updates'), including caching via helpers.
    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;
      }
  • TypeScript interface defining the structure of updates data returned by the Hacker News '/updates' endpoint, used in the handler's type annotation.
    export interface HackerNewsUpdates {
      items: number[];
      profiles: string[];
    }

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