UNPKG

@opra-app/mcp

Version:

MCP server for OPRA's business and discount data

26 lines (25 loc) 1.43 kB
import { env } from "./env.js"; const API_BASE = `${env.API_BASE}/api`; const USER_AGENT = "opra-mcp/1.0"; const headers = { "User-Agent": USER_AGENT, "x-api-key": env.OPRA_API_KEY, }; const fetchJson = async (url) => { const response = await fetch(url, { headers }); if (!response.ok) { throw new Error(`API error: ${response.status} ${response.statusText}`); } return response.json(); }; export const listCategories = async () => fetchJson(`${API_BASE}/app/categories/all`); export const listDiscountsInCategory = async (categoryId) => fetchJson(`${API_BASE}/app/categories/${categoryId}`); export const listDiscounts = async () => fetchJson(`${API_BASE}/app/discounts/all`); export const listCampaigns = async () => fetchJson(`${API_BASE}/app/campaigns/all`); export const getDiscountDetails = async (id) => fetchJson(`${API_BASE}/app/discounts/${id}`); export const getDiscountCode = async (id) => fetchJson(`${API_BASE}/discounts/${id}`); export const getCities = async () => fetchJson(`${API_BASE}/app/cities/all`); export const getDiscountsByCity = async (cityId) => fetchJson(`${API_BASE}/app/cities/${cityId}`); export const getFavoriteDiscounts = async () => fetchJson(`${API_BASE}/app/discounts/favorites`); export const listBusinesses = async () => fetchJson(`${API_BASE}/app/businesses/all`); export const getBusinessDetails = async (id) => fetchJson(`${API_BASE}/app/businesses/${id}`);