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)

242 lines 9.96 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.workspaceCommand = void 0; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const console_table_printer_1 = require("console-table-printer"); const config_1 = require("../utils/config"); const client_1 = require("../api/client"); exports.workspaceCommand = new commander_1.Command("workspace") .alias("workspaces") .description("Workspace management commands"); /** * List workspaces */ exports.workspaceCommand .command("list") .description("List all workspaces") .action(async () => { try { if (!(0, config_1.isAuthenticated)()) { console.log(chalk_1.default.red("❌ Not authenticated. Run 'fmcp auth login' first")); process.exit(1); } const spinner = (0, ora_1.default)("Fetching workspaces...").start(); const client = (0, client_1.getApiClient)(); const result = await client.listWorkspaces(); if (!result.success || !result.data) { spinner.fail("Failed to fetch workspaces"); console.log(chalk_1.default.red(`\n❌ ${result.error}`)); return; } spinner.succeed("Workspaces fetched"); const currentWorkspace = (0, config_1.getConfig)("currentWorkspace"); // Add Personal workspace (default) const personalWorkspace = { id: "personal", name: "Personal", description: "Your personal workspace (default)", createdAt: new Date().toISOString(), }; const allWorkspaces = [personalWorkspace, ...(result.data || [])]; if (allWorkspaces.length === 0) { console.log(chalk_1.default.yellow("\nNo workspaces found")); return; } // Display table const table = new console_table_printer_1.Table({ columns: [ { name: "current", title: "", alignment: "left" }, { name: "id", title: "ID", alignment: "left" }, { name: "name", title: "Name", alignment: "left" }, { name: "description", title: "Description", alignment: "left" }, ], }); allWorkspaces.forEach((workspace) => { const isCurrent = workspace.id === currentWorkspace || (!currentWorkspace && workspace.id === "personal"); table.addRow({ current: isCurrent ? "→" : " ", id: workspace.id, name: workspace.name, description: workspace.description || "-", }); }); console.log("\n"); table.printTable(); console.log(chalk_1.default.gray(`\nTotal: ${allWorkspaces.length} workspace(s)`)); if (!currentWorkspace) { console.log(chalk_1.default.gray("Using Personal workspace (default)")); } } catch (error) { console.log(chalk_1.default.red(`❌ Error: ${error.message}`)); process.exit(1); } }); /** * Use workspace */ exports.workspaceCommand .command("use <workspace-id>") .description("Switch to a workspace") .action(async (workspaceId) => { try { if (!(0, config_1.isAuthenticated)()) { console.log(chalk_1.default.red("❌ Not authenticated. Run 'fmcp auth login' first")); process.exit(1); } (0, config_1.updateConfig)("currentWorkspace", workspaceId); console.log(chalk_1.default.green(`✅ Switched to workspace: ${workspaceId}`)); } catch (error) { console.log(chalk_1.default.red(`❌ Error: ${error.message}`)); process.exit(1); } }); /** * Current workspace */ exports.workspaceCommand .command("current") .description("Show current workspace") .action(() => { try { const currentWorkspace = (0, config_1.getConfig)("currentWorkspace"); if (!currentWorkspace || currentWorkspace === "personal") { console.log(chalk_1.default.green("Current workspace: Personal (default)")); console.log(chalk_1.default.gray("\nUse 'fmcp workspace use <id>' to switch to a different workspace")); return; } console.log(chalk_1.default.green(`Current workspace: ${currentWorkspace}`)); } catch (error) { console.log(chalk_1.default.red(`❌ Error: ${error.message}`)); process.exit(1); } }); /** * Checkout workspace (switch back to personal) */ exports.workspaceCommand .command("checkout") .description("Switch back to personal workspace") .action(() => { try { if (!(0, config_1.isAuthenticated)()) { console.log(chalk_1.default.red("❌ Not authenticated. Run 'fmcp auth login' first")); process.exit(1); } const currentWorkspace = (0, config_1.getConfig)("currentWorkspace"); if (!currentWorkspace || currentWorkspace === "personal") { console.log(chalk_1.default.yellow("Already in Personal workspace")); return; } // Clear the current workspace to use personal (default) (0, config_1.updateConfig)("currentWorkspace", "personal"); console.log(chalk_1.default.green("✅ Switched to Personal workspace")); console.log(chalk_1.default.gray("\nThis is your default workspace for personal servers")); } catch (error) { console.log(chalk_1.default.red(`❌ Error: ${error.message}`)); process.exit(1); } }); /** * Workspace info */ exports.workspaceCommand .command("info [workspace-id]") .description("Show workspace details with servers and tool counts") .action(async (workspaceId) => { try { if (!(0, config_1.isAuthenticated)()) { console.log(chalk_1.default.red("❌ Not authenticated. Run 'fmcp auth login' first")); process.exit(1); } // Use provided workspace ID or current workspace const targetWorkspaceId = workspaceId || (0, config_1.getConfig)("currentWorkspace") || "personal"; console.log(chalk_1.default.cyan(`\n📊 Workspace Information\n`)); // Get workspace details let workspaceName = targetWorkspaceId; let workspaceDescription = "-"; if (targetWorkspaceId === "personal") { workspaceName = "Personal"; workspaceDescription = "Your personal workspace (default)"; } else { const spinner = (0, ora_1.default)("Fetching workspace details...").start(); const client = (0, client_1.getApiClient)(); const result = await client.listWorkspaces(); spinner.stop(); if (result.success && result.data) { const workspace = result.data.find((w) => w.id === targetWorkspaceId); if (workspace) { workspaceName = workspace.name; workspaceDescription = workspace.description || "-"; } } } console.log(chalk_1.default.gray(`ID: ${targetWorkspaceId}`)); console.log(chalk_1.default.gray(`Name: ${workspaceName}`)); console.log(chalk_1.default.gray(`Description: ${workspaceDescription}`)); // Fetch servers in this workspace const spinner = (0, ora_1.default)("Fetching servers...").start(); const client = (0, client_1.getApiClient)(); const serversResult = await client.listServers(targetWorkspaceId === "personal" ? undefined : targetWorkspaceId); if (!serversResult.success || !serversResult.data) { spinner.fail("Failed to fetch servers"); console.log(chalk_1.default.red(`\n❌ ${serversResult.error}`)); return; } spinner.succeed("Servers fetched"); const servers = serversResult.data; if (servers.length === 0) { console.log(chalk_1.default.yellow("\nNo servers in this workspace")); return; } // Calculate totals let totalTools = 0; servers.forEach((server) => { const serverTools = server.selectedServers?.reduce((count, srv) => { return count + (srv.tools?.length || 0); }, 0) || 0; totalTools += serverTools; }); console.log(chalk_1.default.gray(`\nServers: ${servers.length}`)); console.log(chalk_1.default.gray(`Total Tools: ${totalTools}`)); // Display servers table console.log(chalk_1.default.cyan("\n📦 Servers in Workspace:\n")); const table = new console_table_printer_1.Table({ columns: [ { name: "name", title: "Name", alignment: "left" }, { name: "version", title: "Version", alignment: "left" }, { name: "category", title: "Category", alignment: "left" }, { name: "status", title: "Status", alignment: "left" }, { name: "tools", title: "Tools", alignment: "right" }, ], }); servers.forEach((server) => { const serverTools = server.selectedServers?.reduce((count, srv) => { return count + (srv.tools?.length || 0); }, 0) || 0; table.addRow({ name: server.name, version: server.version || "1.0.0", category: server.category || "-", status: server.status || "active", tools: serverTools, }); }); table.printTable(); } catch (error) { console.log(chalk_1.default.red(`❌ Error: ${error.message}`)); process.exit(1); } }); //# sourceMappingURL=workspace.js.map