Skip to main content
Glama

Bucket Feature Flags MCP Server

Official
by reflagcom
auth.ts1.51 kB
import { mkdir, readFile, writeFile } from "node:fs/promises"; import { dirname } from "node:path"; import { AUTH_FILE } from "../utils/constants.js"; class AuthStore { protected tokens: Map<string, string> = new Map(); protected apiKey: string | undefined; async initialize() { await this.loadTokenFile(); } protected async loadTokenFile() { try { const content = await readFile(AUTH_FILE, "utf-8"); this.tokens = new Map( content .split("\n") .filter(Boolean) .map((line) => { const [baseUrl, token] = line.split("|"); return [baseUrl, token]; }), ); } catch { // No tokens file found } } protected async saveTokenFile(newTokens: Map<string, string>) { const content = Array.from(newTokens.entries()) .map(([baseUrl, token]) => `${baseUrl}|${token}`) .join("\n"); await mkdir(dirname(AUTH_FILE), { recursive: true }); await writeFile(AUTH_FILE, content); this.tokens = newTokens; } getToken(baseUrl: string) { return { token: this.apiKey || this.tokens.get(baseUrl), isApiKey: !!this.apiKey, }; } async setToken(baseUrl: string, newToken: string | null) { if (newToken) { this.tokens.set(baseUrl, newToken); } else { this.tokens.delete(baseUrl); } await this.saveTokenFile(this.tokens); } useApiKey(key: string) { this.apiKey = key; } } export const authStore = new AuthStore();

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/reflagcom/bucket-javascript-sdk'

If you have feedback or need assistance with the MCP directory API, please join our Discord server