@mablhq/mabl-cli 2.72.15 → 2.72.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -87,7 +87,6 @@ async function startServer(parsed) {
87
87
  throw new Error(`Unknown prompt: ${name}`);
88
88
  });
89
89
  let mablApiClient;
90
- let workspaceId;
91
90
  server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
92
91
  const { name } = request.params;
93
92
  const tool = tools_1.default.find((t) => t.schema.name === name);
@@ -126,6 +125,7 @@ async function startServer(parsed) {
126
125
  },
127
126
  ],
128
127
  };
128
+ let workspaceId;
129
129
  try {
130
130
  workspaceId = await getWorkspaceId(parsed[constants_1.CommandArgWorkspaceId], parsed[constants_1.CommandArgApiKey], mablApiClient);
131
131
  if (!workspaceId) {
@@ -153,7 +153,14 @@ async function getWorkspaceId(workspaceId, apiKey, mablApiClient) {
153
153
  return workspaceId;
154
154
  }
155
155
  if (apiKey) {
156
- return (await mablApiClient.getApiKeyDetails()).workspace_id;
156
+ const apiKeyDetails = await mablApiClient.getApiKeyDetails();
157
+ return apiKeyDetails.workspace_id;
157
158
  }
158
- return (await cliConfigProvider_1.CliConfigProvider.getWorkspace()).id;
159
+ const currentWorkspace = await cliConfigProvider_1.CliConfigProvider.getWorkspace();
160
+ if (currentWorkspace?.id) {
161
+ return currentWorkspace.id;
162
+ }
163
+ await mablApiClient.getSelf();
164
+ const workspace = await cliConfigProvider_1.CliConfigProvider.getWorkspace();
165
+ return workspace?.id;
159
166
  }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mcpMablTool_1 = require("./mcpMablTool");
4
+ const zod_1 = require("zod");
5
+ const getWorkspaces = (0, mcpMablTool_1.defineTool)({
6
+ schema: {
7
+ name: 'get-workspaces',
8
+ title: 'Get all available workspaces',
9
+ description: 'Get all workspaces that the user has access to',
10
+ inputSchema: zod_1.z.object({
11
+ limit: zod_1.z
12
+ .number()
13
+ .optional()
14
+ .describe('The maximum number of workspaces to return (default: 50)'),
15
+ }),
16
+ outputSchema: zod_1.z.object({
17
+ workspaces: zod_1.z.array(zod_1.z.object({
18
+ id: zod_1.z.string().describe('The workspace ID'),
19
+ name: zod_1.z.string().describe('The workspace name'),
20
+ })),
21
+ currentWorkspaceId: zod_1.z
22
+ .string()
23
+ .describe('The currently active workspace ID'),
24
+ }),
25
+ type: 'readOnly',
26
+ },
27
+ handle: async (args, mablApiClient, _server, workspaceId) => {
28
+ const limit = args.limit || 50;
29
+ const workspaces = await mablApiClient.getWorkspaces(limit);
30
+ const workspaceList = workspaces.map((workspace) => ({
31
+ id: workspace.id,
32
+ name: workspace.name,
33
+ }));
34
+ return {
35
+ content: [
36
+ {
37
+ type: 'text',
38
+ text: JSON.stringify({
39
+ workspaces: workspaceList,
40
+ currentWorkspaceId: workspaceId,
41
+ }, undefined, 2),
42
+ },
43
+ ],
44
+ structuredContent: {
45
+ workspaces: workspaceList,
46
+ currentWorkspaceId: workspaceId,
47
+ },
48
+ };
49
+ },
50
+ });
51
+ exports.default = [getWorkspaces];
@@ -16,6 +16,8 @@ const createTest_1 = __importDefault(require("./createTest"));
16
16
  const getPlans_1 = __importDefault(require("./getPlans"));
17
17
  const getPlanRunResult_1 = __importDefault(require("./getPlanRunResult"));
18
18
  const getLatestPlanRuns_1 = __importDefault(require("./getLatestPlanRuns"));
19
+ const getWorkspaces_1 = __importDefault(require("./getWorkspaces"));
20
+ const switchWorkspace_1 = __importDefault(require("./switchWorkspace"));
19
21
  exports.default = [
20
22
  ...getApplications_1.default,
21
23
  ...getCredentials_1.default,
@@ -30,4 +32,6 @@ exports.default = [
30
32
  ...createTest_1.default,
31
33
  ...getPlanRunResult_1.default,
32
34
  ...getLatestPlanRuns_1.default,
35
+ ...getWorkspaces_1.default,
36
+ ...switchWorkspace_1.default,
33
37
  ];
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cliConfigProvider_1 = require("../../../../providers/cliConfigProvider");
4
+ const mcpMablTool_1 = require("./mcpMablTool");
5
+ const zod_1 = require("zod");
6
+ const switchWorkspace = (0, mcpMablTool_1.defineTool)({
7
+ schema: {
8
+ name: 'switch-workspace',
9
+ title: 'Switch the current workspace',
10
+ description: 'Switch to a different workspace by providing a workspace ID',
11
+ inputSchema: zod_1.z.object({
12
+ workspaceId: zod_1.z.string().describe('The ID of the workspace to switch to'),
13
+ }),
14
+ type: 'destructive',
15
+ },
16
+ handle: async (args, mablApiClient, _server, _currentWorkspaceId) => {
17
+ const { workspaceId: newWorkspaceId } = args;
18
+ try {
19
+ const workspace = await mablApiClient.getWorkspace(newWorkspaceId);
20
+ await cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
21
+ return {
22
+ content: [
23
+ {
24
+ type: 'text',
25
+ text: `Successfully switched workspace to "${workspace.name}" (${newWorkspaceId})`,
26
+ },
27
+ ],
28
+ };
29
+ }
30
+ catch (error) {
31
+ return {
32
+ content: [
33
+ {
34
+ type: 'text',
35
+ text: `Failed to switch workspace: ${error instanceof Error ? error.message : 'Unknown error'}`,
36
+ },
37
+ ],
38
+ };
39
+ }
40
+ },
41
+ });
42
+ exports.default = [switchWorkspace];