UNPKG

@devabdultech/hn-mcp-server

Version:

MCP Server for using the Hacker News API

52 lines 1.93 kB
import fetch from "node-fetch"; const API_BASE_URL = "https://hacker-news.firebaseio.com/v0"; export class HackerNewsAPI { async getItem(id) { const response = await fetch(`${API_BASE_URL}/item/${id}.json`); return response.json(); } async getItems(ids) { return Promise.all(ids.map((id) => this.getItem(id))); } async getTopStories(limit = 30) { const response = await fetch(`${API_BASE_URL}/topstories.json`); const ids = (await response.json()); return ids.slice(0, limit); } async getNewStories(limit = 30) { const response = await fetch(`${API_BASE_URL}/newstories.json`); const ids = (await response.json()); return ids.slice(0, limit); } async getBestStories(limit = 30) { const response = await fetch(`${API_BASE_URL}/beststories.json`); const ids = (await response.json()); return ids.slice(0, limit); } async getAskStories(limit = 30) { const response = await fetch(`${API_BASE_URL}/askstories.json`); const ids = (await response.json()); return ids.slice(0, limit); } async getShowStories(limit = 30) { const response = await fetch(`${API_BASE_URL}/showstories.json`); const ids = (await response.json()); return ids.slice(0, limit); } async getJobStories(limit = 30) { const response = await fetch(`${API_BASE_URL}/jobstories.json`); const ids = (await response.json()); return ids.slice(0, limit); } async getUser(id) { const response = await fetch(`${API_BASE_URL}/user/${id}.json`); return response.json(); } async getMaxItemId() { const response = await fetch(`${API_BASE_URL}/maxitem.json`); const result = (await response.json()); return result; } } export const hnApi = new HackerNewsAPI(); //# sourceMappingURL=hn.js.map