UNPKG

@devabdultech/hn-mcp-server

Version:

MCP Server for using the Hacker News API

35 lines 1.32 kB
import fetch from "node-fetch"; const API_BASE_URL = "https://hn.algolia.com/api/v1"; export class AlgoliaAPI { 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(); } async searchStories(query, options = {}) { return this.search(query, { tags: "story", ...options, }); } async getStoryWithComments(storyId) { const response = await fetch(`${API_BASE_URL}/items/${storyId}`); return response.json(); } async getUser(username) { const response = await fetch(`${API_BASE_URL}/users/${username}`); return response.json(); } } export const algoliaApi = new AlgoliaAPI(); //# sourceMappingURL=algolia.js.map