UNPKG

@toriihq/torii-mcp

Version:

Model Context Protocol server for Torii API

36 lines 1.28 kB
import fetch from 'node-fetch'; // API utility functions for Torii API const apiKey = process.env.TORII_API_KEY; const baseUrl = 'https://api.toriihq.com/v1.0'; /** * Helper function for making API requests to the Torii API */ export async function makeApiRequest(endpoint, method = 'GET', body, headers = {}) { try { const requestOptions = { method, headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json', ...headers } }; if (!endpoint.startsWith('/')) { endpoint = `/${endpoint}`; } if (body && (method === 'POST' || method === 'PUT' || method === 'PATCH')) { requestOptions.body = JSON.stringify(body); } const response = await fetch(`${baseUrl}${endpoint}`, requestOptions); if (!response.ok) { const jsonError = await response.json(); throw new Error(`HTTP error! status: ${response.status} Response: ${JSON.stringify(jsonError, null, 2)}`); } return await response.json(); } catch (error) { console.error(`Error making API request to ${endpoint}:`, error); throw error; } } //# sourceMappingURL=api.js.map