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
JavaScript
;
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