UNPKG

@aurracloud/mcp-cli

Version:

A command-line tool to install, manage, and setup MCP (Model Context Protocol) servers with Docker support

122 lines 3.91 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.getConfigDir = getConfigDir; exports.getConfigFile = getConfigFile; exports.readConfig = readConfig; exports.getApiKey = getApiKey; exports.isAuthenticated = isAuthenticated; exports.getAuthHeaders = getAuthHeaders; exports.removeAuth = removeAuth; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const os = __importStar(require("os")); const logger_1 = require("./logger"); /** * Get the config directory for storing API keys */ function getConfigDir() { const configDir = path.join(os.homedir(), '.mcp-cli'); if (!fs.existsSync(configDir)) { fs.mkdirSync(configDir, { recursive: true }); } return configDir; } /** * Get the config file path */ function getConfigFile() { return path.join(getConfigDir(), 'config.json'); } /** * Read the configuration file */ function readConfig() { const configFile = getConfigFile(); if (!fs.existsSync(configFile)) { return null; } try { const configData = fs.readFileSync(configFile, 'utf8'); return JSON.parse(configData); } catch (error) { logger_1.logger.warn('Could not parse config file'); return null; } } /** * Get API key for a specific registry */ function getApiKey(registry = 'https://aurracloud.com') { const config = readConfig(); if (!config || !config.registries || !config.registries[registry]) { return null; } return config.registries[registry].apiKey; } /** * Check if user is authenticated with a registry */ function isAuthenticated(registry = 'https://aurracloud.com') { return getApiKey(registry) !== null; } /** * Get authentication headers for API requests */ function getAuthHeaders(registry = 'https://aurracloud.com') { const apiKey = getApiKey(registry); if (!apiKey) { throw new Error('Not authenticated. Please run "mcp login" first.'); } return { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json', }; } /** * Remove authentication for a registry (logout) */ function removeAuth(registry = 'https://aurracloud.com') { const config = readConfig(); if (!config || !config.registries) { return; } delete config.registries[registry]; const configFile = getConfigFile(); fs.writeFileSync(configFile, JSON.stringify(config, null, 2)); logger_1.logger.info(`Logged out from ${registry}`); } //# sourceMappingURL=auth.js.map