UNPKG

@microagents/server-hackernews

Version:

MCP server for Hacker News API integration

51 lines 1.59 kB
import fetch from "node-fetch"; const API_BASE_URL = "https://hn.algolia.com/api/v1"; /** * Client for the Algolia Hacker News API */ export class AlgoliaAPI { /** * Search for stories and comments */ async search(query, options = {}) { const params = new URLSearchParams(); params.append("query", query); if (options.tags) params.append("tags", options.tags); if (options.numericFilters) params.append("numericFilters", options.numericFilters); if (options.page !== undefined) params.append("page", options.page.toString()); if (options.hitsPerPage !== undefined) params.append("hitsPerPage", options.hitsPerPage.toString()); const url = `${API_BASE_URL}/search?${params.toString()}`; const response = await fetch(url); return response.json(); } /** * Search for stories only */ async searchStories(query, options = {}) { return this.search(query, { tags: "story", ...options, }); } /** * Get a story with its comments */ async getStoryWithComments(storyId) { const response = await fetch(`${API_BASE_URL}/items/${storyId}`); return response.json(); } /** * Get a user profile */ async getUser(username) { const response = await fetch(`${API_BASE_URL}/users/${username}`); return response.json(); } } // Export a singleton instance export const algoliaApi = new AlgoliaAPI(); //# sourceMappingURL=algolia.js.map