UNPKG

fusion-mcp-cli

Version:

CLI tool for Fusion MCP Hub - Manage custom and community MCP servers. Web App: https://fusion-mcp-hub.vercel.app (General) | https://fusion-mcp-prod.isc-code-connect.dal.app.cirrus.ibm.com (IBM)

158 lines • 6.01 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.authCommand = void 0; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const inquirer_1 = __importDefault(require("inquirer")); const ora_1 = __importDefault(require("ora")); const config_1 = require("../utils/config"); const client_1 = require("../api/client"); exports.authCommand = new commander_1.Command("auth").description("Authentication commands"); /** * Login command */ exports.authCommand .command("login") .description("Login to Fusion MCP with API token") .requiredOption("-u, --url <url>", "API URL (e.g., https://fusion-mcp-hub.vercel.app or http://localhost:3000)") .option("-t, --token <token>", "API token") .action(async (options) => { try { console.log(chalk_1.default.cyan("\nšŸ” Fusion MCP Login\n")); // Check if already authenticated if ((0, config_1.isAuthenticated)()) { const config = (0, config_1.readConfig)(); const { confirm } = await inquirer_1.default.prompt([ { type: "confirm", name: "confirm", message: `Already logged in to ${config.apiUrl}. Login again?`, default: false, }, ]); if (!confirm) { console.log(chalk_1.default.yellow("Login cancelled.")); return; } } // URL is now required via requiredOption const apiUrl = options.url; // Get API token let apiToken = options.token; if (!options.token) { const tokenAnswer = await inquirer_1.default.prompt([ { type: "password", name: "apiToken", message: "Enter API token:", mask: "*", }, ]); apiToken = tokenAnswer.apiToken; } if (!apiToken) { console.log(chalk_1.default.red("āŒ API token is required")); return; } // Validate token format if (!apiToken.startsWith("mcp_")) { console.log(chalk_1.default.red("āŒ Invalid token format. Token should start with 'mcp_'")); console.log(chalk_1.default.yellow("\nāš ļø Make sure you copied the full token from the Settings page")); console.log(chalk_1.default.gray(" The token is only shown once after generation")); return; } // Verify token const spinner = (0, ora_1.default)("Verifying token...").start(); const client = (0, client_1.getApiClient)(); const result = await client.login(apiToken, apiUrl); if (!result.success) { spinner.fail("Authentication failed"); console.log(chalk_1.default.red(`\nāŒ ${result.error}`)); return; } spinner.succeed("Authentication successful"); // Save configuration (0, config_1.writeConfig)({ apiUrl, apiToken, }); console.log(chalk_1.default.green("\nāœ… Successfully logged in!")); console.log(chalk_1.default.gray(` API URL: ${apiUrl}`)); console.log(chalk_1.default.gray(` Config saved to: ${require("os").homedir()}/.fusion-mcp/config.json`)); console.log(chalk_1.default.cyan("\nšŸ’” Tip: Generate API tokens from the web UI Settings page")); } catch (error) { console.log(chalk_1.default.red(`\nāŒ Error: ${error.message}`)); process.exit(1); } }); /** * Logout command */ exports.authCommand .command("logout") .description("Logout from Fusion MCP") .action(async () => { try { if (!(0, config_1.isAuthenticated)()) { console.log(chalk_1.default.yellow("Not logged in.")); return; } const { confirm } = await inquirer_1.default.prompt([ { type: "confirm", name: "confirm", message: "Are you sure you want to logout?", default: false, }, ]); if (!confirm) { console.log(chalk_1.default.yellow("Logout cancelled.")); return; } (0, config_1.clearConfig)(); console.log(chalk_1.default.green("āœ… Successfully logged out!")); } catch (error) { console.log(chalk_1.default.red(`āŒ Error: ${error.message}`)); process.exit(1); } }); /** * Status command */ exports.authCommand .command("status") .description("Check authentication status") .action(async () => { try { if (!(0, config_1.isAuthenticated)()) { console.log(chalk_1.default.yellow("āŒ Not authenticated")); console.log(chalk_1.default.gray("\nRun 'fmcp auth login' to login")); return; } const config = (0, config_1.readConfig)(); console.log(chalk_1.default.green("āœ… Authenticated")); console.log(chalk_1.default.gray(`\n API URL: ${config.apiUrl}`)); console.log(chalk_1.default.gray(` Token: ${config.apiToken?.substring(0, 10)}...`)); // Verify token is still valid const spinner = (0, ora_1.default)("Verifying token...").start(); const client = (0, client_1.getApiClient)(); const isValid = await client.verifyToken(); if (isValid) { spinner.succeed("Token is valid"); } else { spinner.fail("Token is invalid or expired"); console.log(chalk_1.default.yellow("\nāš ļø Please login again")); } } catch (error) { console.log(chalk_1.default.red(`āŒ Error: ${error.message}`)); process.exit(1); } }); //# sourceMappingURL=auth.js.map