UNPKG

mcp-server-tft

Version:

MCP Server for Team Fight Tactics (TFT)

34 lines (33 loc) 1.17 kB
import fetch from "node-fetch"; import { RIOT_ACCOUNT_API } from "./constants.js"; import { getArgs } from "./types.js"; export let CURRENT_PUUID = null; export async function fetchWithErrorHandling(url, options = {}) { try { const headers = { "X-Riot-Token": getArgs().apiKey, ...options.headers }; const response = await fetch(url, { ...options, headers }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response; } catch (error) { throw new Error(`Failed to fetch: ${error instanceof Error ? error.message : String(error)}`); } } export async function initializePUUID() { try { const args = getArgs(); const url = `${RIOT_ACCOUNT_API}/accounts/by-riot-id/${encodeURIComponent(args.gameName)}/${encodeURIComponent(args.tagLine)}`; const response = await fetchWithErrorHandling(url); const data = (await response.json()); CURRENT_PUUID = data.puuid; } catch (error) { console.error("Failed to initialize PUUID:", error); process.exit(1); } }