farseer-cli 1.1.2 → 1.2.1
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.
- package/README.md +21 -10
- package/dist/commands/dimensions.js +10 -3
- package/dist/commands/dimensions.js.map +2 -2
- package/dist/commands/install.js +5 -6
- package/dist/commands/install.js.map +2 -2
- package/dist/commands/pull.js +7 -1
- package/dist/commands/pull.js.map +2 -2
- package/dist/commands/push.js +12 -1
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/run.js +96 -0
- package/dist/commands/run.js.map +2 -2
- package/dist/index.js +3 -0
- package/dist/index.js.map +2 -2
- package/dist/mcp/index.js +6 -0
- package/dist/mcp/index.js.map +2 -2
- package/dist/mcp/server.js +2 -0
- package/dist/mcp/server.js.map +2 -2
- package/dist/mcp/tools/appTools.js +22 -6
- package/dist/mcp/tools/appTools.js.map +2 -2
- package/dist/mcp/tools/cellTools.js +3 -54
- package/dist/mcp/tools/cellTools.js.map +2 -2
- package/dist/mcp/tools/dashboardTools.js +646 -9
- package/dist/mcp/tools/dashboardTools.js.map +3 -3
- package/dist/mcp/tools/folderTools.js +154 -0
- package/dist/mcp/tools/folderTools.js.map +7 -0
- package/dist/mcp/tools/modelTools.js +356 -30
- package/dist/mcp/tools/modelTools.js.map +2 -2
- package/dist/mcp/tools/runTools.js +182 -3
- package/dist/mcp/tools/runTools.js.map +2 -2
- package/dist/mcp/tools/sheetTools.js +419 -11
- package/dist/mcp/tools/sheetTools.js.map +2 -2
- package/dist/mcp/utils/helpers.js +2 -0
- package/dist/mcp/utils/helpers.js.map +2 -2
- package/dist/services/appSyncService.js +4 -2
- package/dist/services/appSyncService.js.map +2 -2
- package/dist/services/farseerApi.js +46 -12
- package/dist/services/farseerApi.js.map +2 -2
- package/dist/services/farseerService.js +28 -5
- package/dist/services/farseerService.js.map +2 -2
- package/dist/services/syncService.js +4 -2
- package/dist/services/syncService.js.map +2 -2
- package/dist/utils/entityResolver.js +6 -8
- package/dist/utils/entityResolver.js.map +2 -2
- package/dist/utils/fileLogger.js +225 -0
- package/dist/utils/fileLogger.js.map +7 -0
- package/dist/utils/logger.js +18 -11
- package/dist/utils/logger.js.map +2 -2
- package/dist/utils/packageManager.js +78 -0
- package/dist/utils/packageManager.js.map +7 -0
- package/docs/cli-guide.md +2 -0
- package/docs/model-export.md +1 -1
- package/package.json +7 -4
|
@@ -37,7 +37,31 @@ var path = __toESM(require("path"));
|
|
|
37
37
|
var os = __toESM(require("os"));
|
|
38
38
|
var import_farseerFactory = require("../../services/farseerFactory");
|
|
39
39
|
var import_helpers = require("../utils/helpers");
|
|
40
|
+
var farseer = __toESM(require("farseer-client"));
|
|
40
41
|
var import_farseer_client = require("farseer-client");
|
|
42
|
+
const ROLLUP_TYPE_MAP = {
|
|
43
|
+
sum: "SUM",
|
|
44
|
+
average: "AVERAGE",
|
|
45
|
+
avg: "AVERAGE",
|
|
46
|
+
min: "MIN",
|
|
47
|
+
max: "MAX",
|
|
48
|
+
none: "NONE",
|
|
49
|
+
formula: "FORMULA",
|
|
50
|
+
closingstate: "CLOSING STATE",
|
|
51
|
+
"closing state": "CLOSING STATE",
|
|
52
|
+
"closing-state": "CLOSING STATE",
|
|
53
|
+
beginningstate: "BEGINNING STATE",
|
|
54
|
+
"beginning state": "BEGINNING STATE",
|
|
55
|
+
"beginning-state": "BEGINNING STATE"
|
|
56
|
+
};
|
|
57
|
+
function normalizeRollupType(value) {
|
|
58
|
+
const normalized = ROLLUP_TYPE_MAP[value.toLowerCase()];
|
|
59
|
+
if (!normalized) {
|
|
60
|
+
const validTypes = [...new Set(Object.values(ROLLUP_TYPE_MAP))].join(", ");
|
|
61
|
+
throw new Error(`Invalid rollupType "${value}". Valid types: ${validTypes}`);
|
|
62
|
+
}
|
|
63
|
+
return normalized;
|
|
64
|
+
}
|
|
41
65
|
async function extractErrorMessage(error) {
|
|
42
66
|
if (error instanceof Error) return error.message;
|
|
43
67
|
if (error && typeof error === "object" && "status" in error && "statusText" in error) {
|
|
@@ -65,7 +89,9 @@ const manageDimensionMembersSchema = {
|
|
|
65
89
|
action: import_zod.z.enum(["create", "delete"]).describe("Action to perform"),
|
|
66
90
|
tableName: import_zod.z.string().describe("Dimension table name"),
|
|
67
91
|
memberName: import_zod.z.string().describe("Member name to create or delete"),
|
|
68
|
-
parentMemberName: import_zod.z.string().optional().describe("Parent member name (for create with hierarchy)")
|
|
92
|
+
parentMemberName: import_zod.z.string().optional().describe("Parent member name (for create with hierarchy)"),
|
|
93
|
+
compound: import_zod.z.boolean().optional().describe("Set to true to create a compound (calculated) member. Use with formula param."),
|
|
94
|
+
formula: import_zod.z.string().optional().describe('Formula for compound members (e.g., "$M1+$M2"). Only used with compound=true.')
|
|
69
95
|
};
|
|
70
96
|
const createVariableSchema = {
|
|
71
97
|
organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
|
|
@@ -73,20 +99,40 @@ const createVariableSchema = {
|
|
|
73
99
|
name: import_zod.z.string().describe("Variable name"),
|
|
74
100
|
dimensions: import_zod.z.array(import_zod.z.string()).optional().describe("Dimension table names this variable spans"),
|
|
75
101
|
formula: import_zod.z.string().optional().describe("Formula expression"),
|
|
76
|
-
rollupType: import_zod.z.string().optional().describe("Rollup type (Sum, Average, Min, Max,
|
|
102
|
+
rollupType: import_zod.z.string().optional().describe("Rollup type (Sum, Average, Min, Max, None, Formula, Closing State, Beginning State)"),
|
|
77
103
|
dataType: import_zod.z.string().optional().describe("Data type (Decimal, Integer, Text)"),
|
|
78
104
|
description: import_zod.z.string().optional().describe("Variable description"),
|
|
79
|
-
readonly: import_zod.z.boolean().optional().describe("Whether the variable is read-only")
|
|
105
|
+
readonly: import_zod.z.boolean().optional().describe("Whether the variable is read-only"),
|
|
106
|
+
measure: import_zod.z.boolean().optional().describe("Set to true for dimensionless formula variables (measure mode)"),
|
|
107
|
+
numberFormat: import_zod.z.record(import_zod.z.any()).optional().describe('Number format config (e.g., { type: "PERCENTAGE", decimals: 1 }). Saves a separate update call.'),
|
|
108
|
+
folderPath: import_zod.z.array(import_zod.z.string()).optional().describe('Folder path to place the variable in (e.g., ["Variables", "Revenue"]). Uses create + move.')
|
|
80
109
|
};
|
|
81
110
|
const updateVariableSchema = {
|
|
82
111
|
organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
|
|
83
112
|
tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
|
|
84
|
-
name: import_zod.z.string().describe("Variable name to update"),
|
|
113
|
+
name: import_zod.z.string().describe("Variable name to update (used for lookup)"),
|
|
114
|
+
newName: import_zod.z.string().optional().describe("Rename the variable to this name"),
|
|
85
115
|
dimensions: import_zod.z.array(import_zod.z.string()).optional().describe("New dimension table names (replaces all existing dimensions)"),
|
|
86
|
-
formula: import_zod.z.string().optional().describe(
|
|
116
|
+
formula: import_zod.z.string().optional().describe(
|
|
117
|
+
'New formula expression. Supports $GID syntax for direct references (e.g., "$155-$297"). Pass the formula string as-is.'
|
|
118
|
+
),
|
|
87
119
|
rollupType: import_zod.z.string().optional().describe("New rollup type"),
|
|
88
120
|
description: import_zod.z.string().optional().describe("New description"),
|
|
89
|
-
readonly: import_zod.z.boolean().optional().describe("Set read-only status")
|
|
121
|
+
readonly: import_zod.z.boolean().optional().describe("Set read-only status"),
|
|
122
|
+
polarity: import_zod.z.enum(["POSITIVE", "NEGATIVE"]).optional().describe("Number format polarity (POSITIVE or NEGATIVE)"),
|
|
123
|
+
numberFormat: import_zod.z.record(import_zod.z.any()).optional().describe(
|
|
124
|
+
"Full number format configuration object. Fields: type, custom, formatString, decimals, polarity, negatives, unit, currency. Use this for fine-grained control over number formatting."
|
|
125
|
+
)
|
|
126
|
+
};
|
|
127
|
+
const deleteVariableSchema = {
|
|
128
|
+
organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
|
|
129
|
+
tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
|
|
130
|
+
variableName: import_zod.z.string().describe("Variable name to delete")
|
|
131
|
+
};
|
|
132
|
+
const deleteVariableDataSchema = {
|
|
133
|
+
organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
|
|
134
|
+
tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
|
|
135
|
+
variableName: import_zod.z.string().describe("Variable name whose data to delete")
|
|
90
136
|
};
|
|
91
137
|
const exportModelSchema = {
|
|
92
138
|
tenant: import_zod.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
|
|
@@ -121,8 +167,9 @@ Returns:
|
|
|
121
167
|
|
|
122
168
|
This is essential for understanding a tenant's data structure before writing import scripts.
|
|
123
169
|
|
|
124
|
-
|
|
125
|
-
|
|
170
|
+
For large models (20KB+), the full result is automatically saved to a temp JSON file
|
|
171
|
+
and only a summary is returned. Use the Read tool to inspect the file if needed.
|
|
172
|
+
For a quick overview without the full export, use farseer_list_tables or farseer_list_variables.
|
|
126
173
|
|
|
127
174
|
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
128
175
|
exportModelSchema,
|
|
@@ -159,7 +206,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
159
206
|
calculateOnDemand: v.calculateOnDemand,
|
|
160
207
|
folderPath: v.folderPath
|
|
161
208
|
}));
|
|
162
|
-
|
|
209
|
+
const result = {
|
|
163
210
|
tenant,
|
|
164
211
|
summary: {
|
|
165
212
|
tableCount: tables.length,
|
|
@@ -167,7 +214,26 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
167
214
|
},
|
|
168
215
|
tables,
|
|
169
216
|
variables
|
|
170
|
-
}
|
|
217
|
+
};
|
|
218
|
+
const jsonStr = JSON.stringify(result, null, 2);
|
|
219
|
+
const JSON_SIZE_THRESHOLD = 2e4;
|
|
220
|
+
if (jsonStr.length > JSON_SIZE_THRESHOLD) {
|
|
221
|
+
const tmpDir = os.tmpdir();
|
|
222
|
+
const filePath = path.join(tmpDir, `farseer_${tenant}_model.json`);
|
|
223
|
+
fs.writeFileSync(filePath, jsonStr, "utf-8");
|
|
224
|
+
return (0, import_helpers.successResponse)({
|
|
225
|
+
tenant,
|
|
226
|
+
summary: {
|
|
227
|
+
tableCount: tables.length,
|
|
228
|
+
variableCount: variables.length
|
|
229
|
+
},
|
|
230
|
+
exportedToFile: filePath,
|
|
231
|
+
message: `Model has ${tables.length} tables and ${variables.length} variables (${Math.round(jsonStr.length / 1024)}KB) \u2014 exported to file. Use Read tool to inspect.`,
|
|
232
|
+
tableSummary: tables.map((t) => `${t.name} (${t.memberCount} members)`),
|
|
233
|
+
variableSummary: variables.map((v) => `${v.name} [${v.dimensions.join(", ")}]`)
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
return (0, import_helpers.successResponse)(result);
|
|
171
237
|
} catch (error) {
|
|
172
238
|
return (0, import_helpers.errorResponse)(
|
|
173
239
|
`Export model failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
@@ -245,8 +311,21 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
245
311
|
}
|
|
246
312
|
try {
|
|
247
313
|
const model = await clientResult.client.exportModel();
|
|
314
|
+
const gidMap = /* @__PURE__ */ new Map();
|
|
315
|
+
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
316
|
+
if (nativeClient) {
|
|
317
|
+
try {
|
|
318
|
+
await nativeClient.initTagMap();
|
|
319
|
+
for (const v of model.variables) {
|
|
320
|
+
const tag = await nativeClient.getVariable(v.name);
|
|
321
|
+
gidMap.set(v.name, tag.id);
|
|
322
|
+
}
|
|
323
|
+
} catch {
|
|
324
|
+
}
|
|
325
|
+
}
|
|
248
326
|
const variables = model.variables.map((v) => ({
|
|
249
327
|
name: v.name,
|
|
328
|
+
entityGid: gidMap.get(v.name) || null,
|
|
250
329
|
dimensions: v.tables || [],
|
|
251
330
|
hasFormula: !!v.formula,
|
|
252
331
|
rollupType: v.rollupType,
|
|
@@ -357,10 +436,21 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
357
436
|
if (!variable) {
|
|
358
437
|
return (0, import_helpers.errorResponse)(`Variable "${params.variableName}" not found`, "NOT_FOUND");
|
|
359
438
|
}
|
|
439
|
+
let entityGid = null;
|
|
440
|
+
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
441
|
+
if (nativeClient) {
|
|
442
|
+
try {
|
|
443
|
+
await nativeClient.initTagMap();
|
|
444
|
+
const tag = await nativeClient.getVariable(variable.name);
|
|
445
|
+
entityGid = tag.id;
|
|
446
|
+
} catch {
|
|
447
|
+
}
|
|
448
|
+
}
|
|
360
449
|
return (0, import_helpers.successResponse)({
|
|
361
450
|
tenant,
|
|
362
451
|
variable: {
|
|
363
452
|
name: variable.name,
|
|
453
|
+
entityGid,
|
|
364
454
|
description: variable.description,
|
|
365
455
|
formula: variable.formula,
|
|
366
456
|
dimensions: variable.tables || [],
|
|
@@ -385,9 +475,11 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
385
475
|
`Evaluate a formula expression in a Farseer tenant.
|
|
386
476
|
|
|
387
477
|
The formula can be a variable name or a calculation expression.
|
|
478
|
+
Variable names with spaces or special characters (e.g., "P&L", "New Variable2") are
|
|
479
|
+
automatically quoted for the backend formula parser \u2014 just pass the plain name.
|
|
388
480
|
Filters narrow the evaluation to specific dimension members.
|
|
389
481
|
|
|
390
|
-
Example: evaluate "Revenue" with filters [["Years","
|
|
482
|
+
Example: evaluate "Revenue" with filters [["Years","Y2025"],["Months","M1"]]
|
|
391
483
|
|
|
392
484
|
Returns the computed value along with cell metadata (readonly, calculated, frozen).
|
|
393
485
|
|
|
@@ -401,9 +493,14 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
401
493
|
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
402
494
|
if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
|
|
403
495
|
try {
|
|
496
|
+
let formula = params.formula;
|
|
497
|
+
const isSimpleIdentifier = !formula.startsWith('"') && !/[+\-*/()>,<!=]/.test(formula);
|
|
498
|
+
if (isSimpleIdentifier && /[\s&]/.test(formula)) {
|
|
499
|
+
formula = `"${formula}"`;
|
|
500
|
+
}
|
|
404
501
|
const evaluateRequest = {
|
|
405
502
|
filters: params.filters || [],
|
|
406
|
-
cellQueries: [{ type: "VARIABLE", formula
|
|
503
|
+
cellQueries: [{ type: "VARIABLE", formula }]
|
|
407
504
|
};
|
|
408
505
|
const results = await nativeClient.evaluator.evaluate(evaluateRequest);
|
|
409
506
|
return (0, import_helpers.successResponse)({
|
|
@@ -498,6 +595,8 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
498
595
|
Actions:
|
|
499
596
|
- "create": Creates a new member in the specified dimension table.
|
|
500
597
|
Optionally set a parent member for hierarchical tables.
|
|
598
|
+
Set compound=true with a formula to create a compound (calculated) member
|
|
599
|
+
(e.g., for AC Period / FC Period filters on variance rows).
|
|
501
600
|
- "delete": Deletes an existing member by name from the specified table.
|
|
502
601
|
|
|
503
602
|
WARNING: Delete is destructive and may affect data. Use with caution.
|
|
@@ -518,15 +617,28 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
518
617
|
type: import_farseer_client.EntityType.DimensionMember,
|
|
519
618
|
meta: { name: params.memberName },
|
|
520
619
|
relations: {
|
|
521
|
-
parent: {
|
|
522
|
-
|
|
620
|
+
parent: {
|
|
621
|
+
key: { id: table.id, type: import_farseer_client.EntityType.DimensionTable },
|
|
622
|
+
order: 0
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
dimensionMember: { data: {} }
|
|
523
626
|
};
|
|
524
627
|
if (params.parentMemberName) {
|
|
525
628
|
const parentMember = await nativeClient.getDimensionMember(
|
|
526
629
|
params.tableName,
|
|
527
630
|
params.parentMemberName
|
|
528
631
|
);
|
|
529
|
-
createEntity.relations.parent = {
|
|
632
|
+
createEntity.relations.parent = {
|
|
633
|
+
key: { id: parentMember.id, type: import_farseer_client.EntityType.DimensionMember },
|
|
634
|
+
order: 0
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
if (params.compound) {
|
|
638
|
+
createEntity.calculation = {
|
|
639
|
+
type: "COMPOUND",
|
|
640
|
+
formula: params.formula || ""
|
|
641
|
+
};
|
|
530
642
|
}
|
|
531
643
|
const result = await nativeClient.entities.mutate({ created: [createEntity] });
|
|
532
644
|
return (0, import_helpers.successResponse)({
|
|
@@ -558,6 +670,76 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
558
670
|
}
|
|
559
671
|
}
|
|
560
672
|
);
|
|
673
|
+
server.tool(
|
|
674
|
+
"farseer_create_table",
|
|
675
|
+
`Create a new dimension table in a Farseer tenant.
|
|
676
|
+
|
|
677
|
+
Dimension tables define the structure of data (e.g., Product, Region, Compound Members).
|
|
678
|
+
Creates an empty table that you can then add members to with farseer_manage_dimension_members.
|
|
679
|
+
|
|
680
|
+
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
681
|
+
{
|
|
682
|
+
organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
|
|
683
|
+
tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
|
|
684
|
+
name: import_zod.z.string().describe("Dimension table name"),
|
|
685
|
+
folderPath: import_zod.z.array(import_zod.z.string()).optional().describe('Folder path (e.g., ["Dimensions"]). Uses create + move.')
|
|
686
|
+
},
|
|
687
|
+
// @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
|
|
688
|
+
async (params) => {
|
|
689
|
+
const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
|
|
690
|
+
if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
|
|
691
|
+
const { organisation, tenant } = resolved;
|
|
692
|
+
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
693
|
+
if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
|
|
694
|
+
try {
|
|
695
|
+
await nativeClient.initTagMap();
|
|
696
|
+
const createEntity = {
|
|
697
|
+
type: import_farseer_client.EntityType.DimensionTable,
|
|
698
|
+
meta: { name: params.name, description: null }
|
|
699
|
+
};
|
|
700
|
+
if (params.folderPath && params.folderPath.length > 0) {
|
|
701
|
+
try {
|
|
702
|
+
let currentFolderId = null;
|
|
703
|
+
for (const segment of params.folderPath) {
|
|
704
|
+
const parentItems = await nativeClient.folders.listItemsBatch([{ id: currentFolderId }]);
|
|
705
|
+
const existing = parentItems[0]?.items?.find(
|
|
706
|
+
(i) => i.type === farseer.FolderItemType.Folder && i.name.toLowerCase() === segment.toLowerCase()
|
|
707
|
+
);
|
|
708
|
+
if (existing) {
|
|
709
|
+
currentFolderId = existing.id;
|
|
710
|
+
} else {
|
|
711
|
+
const newFolder = await nativeClient.folders.create({
|
|
712
|
+
parentId: currentFolderId,
|
|
713
|
+
name: segment,
|
|
714
|
+
allowedTypes: null
|
|
715
|
+
});
|
|
716
|
+
currentFolderId = newFolder.id;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
if (currentFolderId) {
|
|
720
|
+
createEntity.relations = {
|
|
721
|
+
folder: { key: { id: currentFolderId, type: import_farseer_client.EntityType.Folder }, order: 0 }
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
} catch {
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
const result = await nativeClient.entities.mutate({ created: [createEntity] });
|
|
728
|
+
const created = result.created?.[0];
|
|
729
|
+
return (0, import_helpers.successResponse)({
|
|
730
|
+
tenant,
|
|
731
|
+
action: "created",
|
|
732
|
+
table: {
|
|
733
|
+
id: created?.id,
|
|
734
|
+
name: params.name
|
|
735
|
+
},
|
|
736
|
+
message: `Dimension table "${params.name}" created`
|
|
737
|
+
});
|
|
738
|
+
} catch (error) {
|
|
739
|
+
return (0, import_helpers.errorResponse)(`Create table failed: ${await extractErrorMessage(error)}`, "NETWORK_ERROR");
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
);
|
|
561
743
|
server.tool(
|
|
562
744
|
"farseer_create_variable",
|
|
563
745
|
`Create a new variable in a Farseer tenant.
|
|
@@ -592,6 +774,8 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
592
774
|
tableGids.push(table.id);
|
|
593
775
|
}
|
|
594
776
|
}
|
|
777
|
+
const rollupType = normalizeRollupType(params.rollupType || "SUM");
|
|
778
|
+
const dataType = (params.dataType || "DECIMAL").toUpperCase();
|
|
595
779
|
const createEntity = {
|
|
596
780
|
type: import_farseer_client.EntityType.Variable,
|
|
597
781
|
meta: {
|
|
@@ -600,14 +784,45 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
600
784
|
},
|
|
601
785
|
variable: {
|
|
602
786
|
tableGids,
|
|
603
|
-
rollupType
|
|
604
|
-
dataType
|
|
605
|
-
readonly: params.readonly || false
|
|
787
|
+
rollupType,
|
|
788
|
+
dataType,
|
|
789
|
+
readonly: params.readonly || false,
|
|
790
|
+
measure: params.measure || false
|
|
606
791
|
}
|
|
607
792
|
};
|
|
608
793
|
if (params.formula) {
|
|
609
794
|
createEntity.calculation = { formula: params.formula };
|
|
610
795
|
}
|
|
796
|
+
if (params.numberFormat) {
|
|
797
|
+
createEntity.numberFormat = params.numberFormat;
|
|
798
|
+
}
|
|
799
|
+
if (params.folderPath && params.folderPath.length > 0) {
|
|
800
|
+
try {
|
|
801
|
+
let currentFolderId = null;
|
|
802
|
+
for (const segment of params.folderPath) {
|
|
803
|
+
const parentItems = await nativeClient.folders.listItemsBatch([{ id: currentFolderId }]);
|
|
804
|
+
const existing = parentItems[0]?.items?.find(
|
|
805
|
+
(i) => i.type === farseer.FolderItemType.Folder && i.name.toLowerCase() === segment.toLowerCase()
|
|
806
|
+
);
|
|
807
|
+
if (existing) {
|
|
808
|
+
currentFolderId = existing.id;
|
|
809
|
+
} else {
|
|
810
|
+
const newFolder = await nativeClient.folders.create({
|
|
811
|
+
parentId: currentFolderId,
|
|
812
|
+
name: segment,
|
|
813
|
+
allowedTypes: null
|
|
814
|
+
});
|
|
815
|
+
currentFolderId = newFolder.id;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
if (currentFolderId) {
|
|
819
|
+
createEntity.relations = {
|
|
820
|
+
folder: { key: { id: currentFolderId, type: import_farseer_client.EntityType.Folder }, order: 0 }
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
} catch {
|
|
824
|
+
}
|
|
825
|
+
}
|
|
611
826
|
const result = await nativeClient.entities.mutate({ created: [createEntity] });
|
|
612
827
|
return (0, import_helpers.successResponse)({
|
|
613
828
|
tenant,
|
|
@@ -629,14 +844,18 @@ Resolves the variable by name and updates the specified fields.
|
|
|
629
844
|
Only provided fields are updated; omitted fields remain unchanged.
|
|
630
845
|
|
|
631
846
|
Updatable fields:
|
|
847
|
+
- newName: Rename the variable
|
|
632
848
|
- dimensions: Change which dimension tables the variable spans (replaces all existing dimensions)
|
|
633
|
-
- formula: Change the calculation formula
|
|
849
|
+
- formula: Change the calculation formula (supports $GID syntax like "$155-$297")
|
|
634
850
|
- rollupType: Change aggregation method (Sum, Average, Min, Max, etc.)
|
|
635
851
|
- description: Change the variable description
|
|
636
852
|
- readonly: Set or clear read-only status
|
|
853
|
+
- polarity: Set number polarity (POSITIVE or NEGATIVE)
|
|
854
|
+
- numberFormat: Full number format config (type, decimals, polarity, unit, currency, etc.)
|
|
637
855
|
|
|
638
856
|
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
639
857
|
updateVariableSchema,
|
|
858
|
+
// @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
|
|
640
859
|
async (params) => {
|
|
641
860
|
const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
|
|
642
861
|
if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
|
|
@@ -646,29 +865,63 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
646
865
|
try {
|
|
647
866
|
await nativeClient.initTagMap();
|
|
648
867
|
const variable = await nativeClient.getVariable(params.name);
|
|
868
|
+
const currentEntity = await nativeClient.entities.getSingle(variable.id, import_farseer_client.EntityType.Variable);
|
|
869
|
+
const current = currentEntity;
|
|
870
|
+
const currentVar = current.variable || {};
|
|
649
871
|
const updateEntity = {
|
|
650
872
|
id: variable.id,
|
|
651
|
-
type: import_farseer_client.EntityType.Variable
|
|
873
|
+
type: import_farseer_client.EntityType.Variable,
|
|
874
|
+
meta: {
|
|
875
|
+
name: params.newName || variable.name,
|
|
876
|
+
description: params.description !== void 0 ? params.description : current.meta?.description ?? null
|
|
877
|
+
},
|
|
878
|
+
variable: {
|
|
879
|
+
notes: currentVar.notes ?? null,
|
|
880
|
+
tableGids: currentVar.tableGids || [],
|
|
881
|
+
memberGids: currentVar.memberGids || [],
|
|
882
|
+
rollupType: currentVar.rollupType || "SUM",
|
|
883
|
+
dataType: currentVar.dataType || "DECIMAL",
|
|
884
|
+
topDownMapping: currentVar.topDownMapping ?? null,
|
|
885
|
+
measure: currentVar.measure || false,
|
|
886
|
+
readonly: currentVar.readonly || false,
|
|
887
|
+
calculateOnDemand: currentVar.calculateOnDemand || false,
|
|
888
|
+
zConstraint: currentVar.zConstraint || false,
|
|
889
|
+
optimizeCalculation: currentVar.optimizeCalculation ?? true
|
|
890
|
+
// referencedBy is readOnly - do NOT send in update requests
|
|
891
|
+
}
|
|
652
892
|
};
|
|
653
|
-
if (params.description !== void 0) {
|
|
654
|
-
updateEntity.meta = { name: variable.name, description: params.description };
|
|
655
|
-
}
|
|
656
|
-
const variableUpdate = {};
|
|
657
893
|
if (params.dimensions) {
|
|
658
894
|
const tableGids = [];
|
|
659
895
|
for (const tableName of params.dimensions) {
|
|
660
896
|
const table = await nativeClient.getDimensionTable(tableName);
|
|
661
897
|
tableGids.push(table.id);
|
|
662
898
|
}
|
|
663
|
-
|
|
899
|
+
updateEntity.variable.tableGids = tableGids;
|
|
900
|
+
}
|
|
901
|
+
if (params.rollupType) {
|
|
902
|
+
updateEntity.variable.rollupType = normalizeRollupType(params.rollupType);
|
|
664
903
|
}
|
|
665
|
-
if (params.
|
|
666
|
-
|
|
667
|
-
if (Object.keys(variableUpdate).length > 0) {
|
|
668
|
-
updateEntity.variable = variableUpdate;
|
|
904
|
+
if (params.readonly !== void 0) {
|
|
905
|
+
updateEntity.variable.readonly = params.readonly;
|
|
669
906
|
}
|
|
907
|
+
const currentCalc = current.calculation;
|
|
670
908
|
if (params.formula !== void 0) {
|
|
671
|
-
updateEntity.calculation = {
|
|
909
|
+
updateEntity.calculation = {
|
|
910
|
+
formula: params.formula,
|
|
911
|
+
type: currentCalc?.type || "VARIABLE"
|
|
912
|
+
};
|
|
913
|
+
} else if (currentCalc) {
|
|
914
|
+
updateEntity.calculation = currentCalc;
|
|
915
|
+
}
|
|
916
|
+
if (params.numberFormat || params.polarity) {
|
|
917
|
+
const currentFormat = current.numberFormat || {};
|
|
918
|
+
updateEntity.numberFormat = {
|
|
919
|
+
...currentFormat,
|
|
920
|
+
...params.numberFormat || {}
|
|
921
|
+
};
|
|
922
|
+
if (params.polarity) {
|
|
923
|
+
updateEntity.numberFormat.polarity = params.polarity;
|
|
924
|
+
}
|
|
672
925
|
}
|
|
673
926
|
const result = await nativeClient.entities.mutate({ updated: [updateEntity] });
|
|
674
927
|
return (0, import_helpers.successResponse)({
|
|
@@ -683,6 +936,79 @@ If no tenant is specified, uses the currently checked-out tenant.`,
|
|
|
683
936
|
}
|
|
684
937
|
}
|
|
685
938
|
);
|
|
939
|
+
server.tool(
|
|
940
|
+
"farseer_delete_variable_data",
|
|
941
|
+
`Delete ALL data for a variable in a Farseer tenant.
|
|
942
|
+
|
|
943
|
+
WARNING: This is destructive and cannot be undone. It removes all cell values
|
|
944
|
+
for the specified variable across all dimensions and time periods.
|
|
945
|
+
|
|
946
|
+
Use this to clear old template data or reset a variable before re-importing.
|
|
947
|
+
|
|
948
|
+
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
949
|
+
deleteVariableDataSchema,
|
|
950
|
+
async (params) => {
|
|
951
|
+
const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
|
|
952
|
+
if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
|
|
953
|
+
const { organisation, tenant } = resolved;
|
|
954
|
+
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
955
|
+
if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
|
|
956
|
+
try {
|
|
957
|
+
await nativeClient.initTagMap();
|
|
958
|
+
const variable = await nativeClient.getVariable(params.variableName);
|
|
959
|
+
await nativeClient.entities.deleteData({
|
|
960
|
+
id: variable.id,
|
|
961
|
+
type: import_farseer_client.EntityType.Variable
|
|
962
|
+
});
|
|
963
|
+
return (0, import_helpers.successResponse)({
|
|
964
|
+
tenant,
|
|
965
|
+
action: "deleted_data",
|
|
966
|
+
variable: params.variableName,
|
|
967
|
+
variableId: variable.id,
|
|
968
|
+
message: `All data deleted for variable "${params.variableName}"`
|
|
969
|
+
});
|
|
970
|
+
} catch (error) {
|
|
971
|
+
return (0, import_helpers.errorResponse)(
|
|
972
|
+
`Delete variable data failed: ${await extractErrorMessage(error)}`,
|
|
973
|
+
"NETWORK_ERROR"
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
);
|
|
978
|
+
server.tool(
|
|
979
|
+
"farseer_delete_variable",
|
|
980
|
+
`Delete a variable from a Farseer tenant.
|
|
981
|
+
|
|
982
|
+
Resolves the variable by name and permanently deletes it along with all its data.
|
|
983
|
+
|
|
984
|
+
WARNING: This is destructive and cannot be undone.
|
|
985
|
+
|
|
986
|
+
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
987
|
+
deleteVariableSchema,
|
|
988
|
+
async (params) => {
|
|
989
|
+
const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
|
|
990
|
+
if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
|
|
991
|
+
const { organisation, tenant } = resolved;
|
|
992
|
+
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
993
|
+
if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
|
|
994
|
+
try {
|
|
995
|
+
await nativeClient.initTagMap();
|
|
996
|
+
const variable = await nativeClient.getVariable(params.variableName);
|
|
997
|
+
await nativeClient.entities.mutate({
|
|
998
|
+
deleted: [{ id: variable.id, type: import_farseer_client.EntityType.Variable }]
|
|
999
|
+
});
|
|
1000
|
+
return (0, import_helpers.successResponse)({
|
|
1001
|
+
tenant,
|
|
1002
|
+
action: "deleted",
|
|
1003
|
+
variable: params.variableName,
|
|
1004
|
+
variableId: variable.id,
|
|
1005
|
+
message: `Variable "${params.variableName}" deleted`
|
|
1006
|
+
});
|
|
1007
|
+
} catch (error) {
|
|
1008
|
+
return (0, import_helpers.errorResponse)(`Delete variable failed: ${await extractErrorMessage(error)}`, "NETWORK_ERROR");
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
);
|
|
686
1012
|
}
|
|
687
1013
|
// Annotate the CommonJS export names for ESM import in node:
|
|
688
1014
|
0 && (module.exports = {
|