farseer-cli 1.0.10 → 1.1.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.
Files changed (98) hide show
  1. package/README.md +19 -0
  2. package/dist/commands/app.js +348 -344
  3. package/dist/commands/app.js.map +7 -0
  4. package/dist/commands/apps.js +110 -82
  5. package/dist/commands/apps.js.map +7 -0
  6. package/dist/commands/cells.js +161 -0
  7. package/dist/commands/cells.js.map +7 -0
  8. package/dist/commands/checkout.js +140 -155
  9. package/dist/commands/checkout.js.map +7 -0
  10. package/dist/commands/config.js +128 -126
  11. package/dist/commands/config.js.map +7 -0
  12. package/dist/commands/dashboards.js +130 -0
  13. package/dist/commands/dashboards.js.map +7 -0
  14. package/dist/commands/diff.js +171 -193
  15. package/dist/commands/diff.js.map +7 -0
  16. package/dist/commands/dimensions.js +222 -119
  17. package/dist/commands/dimensions.js.map +7 -0
  18. package/dist/commands/files.js +96 -77
  19. package/dist/commands/files.js.map +7 -0
  20. package/dist/commands/formula.js +116 -0
  21. package/dist/commands/formula.js.map +7 -0
  22. package/dist/commands/install.js +74 -76
  23. package/dist/commands/install.js.map +7 -0
  24. package/dist/commands/list.js +91 -73
  25. package/dist/commands/list.js.map +7 -0
  26. package/dist/commands/login.js +137 -98
  27. package/dist/commands/login.js.map +7 -0
  28. package/dist/commands/logout.js +59 -41
  29. package/dist/commands/logout.js.map +7 -0
  30. package/dist/commands/mcp-server.js +36 -23
  31. package/dist/commands/mcp-server.js.map +7 -0
  32. package/dist/commands/model.js +186 -175
  33. package/dist/commands/model.js.map +7 -0
  34. package/dist/commands/pull.js +264 -274
  35. package/dist/commands/pull.js.map +7 -0
  36. package/dist/commands/push.js +209 -221
  37. package/dist/commands/push.js.map +7 -0
  38. package/dist/commands/run.js +276 -321
  39. package/dist/commands/run.js.map +7 -0
  40. package/dist/commands/sheets.js +200 -0
  41. package/dist/commands/sheets.js.map +7 -0
  42. package/dist/commands/status.js +149 -169
  43. package/dist/commands/status.js.map +7 -0
  44. package/dist/commands/variables.js +247 -188
  45. package/dist/commands/variables.js.map +7 -0
  46. package/dist/commands/whoami.js +65 -44
  47. package/dist/commands/whoami.js.map +7 -0
  48. package/dist/index.js +179 -115
  49. package/dist/index.js.map +7 -0
  50. package/dist/mcp/index.js +33 -16
  51. package/dist/mcp/index.js.map +7 -0
  52. package/dist/mcp/prompts/workflows.js +191 -145
  53. package/dist/mcp/prompts/workflows.js.map +7 -0
  54. package/dist/mcp/resources/documentation.js +158 -148
  55. package/dist/mcp/resources/documentation.js.map +7 -0
  56. package/dist/mcp/server.js +56 -33
  57. package/dist/mcp/server.js.map +7 -0
  58. package/dist/mcp/tools/appTools.js +309 -277
  59. package/dist/mcp/tools/appTools.js.map +7 -0
  60. package/dist/mcp/tools/authTools.js +130 -121
  61. package/dist/mcp/tools/authTools.js.map +7 -0
  62. package/dist/mcp/tools/cellTools.js +148 -0
  63. package/dist/mcp/tools/cellTools.js.map +7 -0
  64. package/dist/mcp/tools/dashboardTools.js +133 -0
  65. package/dist/mcp/tools/dashboardTools.js.map +7 -0
  66. package/dist/mcp/tools/dataTools.js +270 -267
  67. package/dist/mcp/tools/dataTools.js.map +7 -0
  68. package/dist/mcp/tools/modelTools.js +575 -229
  69. package/dist/mcp/tools/modelTools.js.map +7 -0
  70. package/dist/mcp/tools/runTools.js +201 -203
  71. package/dist/mcp/tools/runTools.js.map +7 -0
  72. package/dist/mcp/tools/sheetTools.js +240 -0
  73. package/dist/mcp/tools/sheetTools.js.map +7 -0
  74. package/dist/mcp/tools/syncTools.js +335 -314
  75. package/dist/mcp/tools/syncTools.js.map +7 -0
  76. package/dist/mcp/utils/helpers.js +117 -123
  77. package/dist/mcp/utils/helpers.js.map +7 -0
  78. package/dist/services/appSyncService.js +381 -437
  79. package/dist/services/appSyncService.js.map +7 -0
  80. package/dist/services/configService.js +154 -143
  81. package/dist/services/configService.js.map +7 -0
  82. package/dist/services/farseerApi.js +422 -399
  83. package/dist/services/farseerApi.js.map +7 -0
  84. package/dist/services/farseerFactory.js +208 -273
  85. package/dist/services/farseerFactory.js.map +7 -0
  86. package/dist/services/farseerService.js +467 -486
  87. package/dist/services/farseerService.js.map +7 -0
  88. package/dist/services/syncService.js +661 -731
  89. package/dist/services/syncService.js.map +7 -0
  90. package/dist/utils/constants.js +52 -19
  91. package/dist/utils/constants.js.map +7 -0
  92. package/dist/utils/entityResolver.js +78 -0
  93. package/dist/utils/entityResolver.js.map +7 -0
  94. package/dist/utils/helpers.js +331 -365
  95. package/dist/utils/helpers.js.map +7 -0
  96. package/dist/utils/logger.js +74 -42
  97. package/dist/utils/logger.js.map +7 -0
  98. package/package.json +3 -2
@@ -1,55 +1,105 @@
1
1
  "use strict";
2
- /**
3
- * Model Inspection Tools
4
- *
5
- * Tools for exploring Farseer data models (dimensions, variables, formulas).
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.registerModelTools = registerModelTools;
9
- const zod_1 = require("zod");
10
- const farseerFactory_1 = require("../../services/farseerFactory");
11
- const helpers_1 = require("../utils/helpers");
12
- // Define schemas outside of tool registration to avoid deep type instantiation
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var modelTools_exports = {};
20
+ __export(modelTools_exports, {
21
+ registerModelTools: () => registerModelTools
22
+ });
23
+ module.exports = __toCommonJS(modelTools_exports);
24
+ var import_zod = require("zod");
25
+ var import_farseerFactory = require("../../services/farseerFactory");
26
+ var import_helpers = require("../utils/helpers");
27
+ var import_farseer_client = require("farseer-client");
28
+ async function extractErrorMessage(error) {
29
+ if (error instanceof Error) return error.message;
30
+ if (error && typeof error === "object" && "status" in error && "statusText" in error) {
31
+ const resp = error;
32
+ const body = resp.text ? await resp.text() : "";
33
+ return `HTTP ${resp.status} ${resp.statusText}${body ? ": " + body : ""}`;
34
+ }
35
+ return String(error);
36
+ }
37
+ const evaluateFormulaSchema = {
38
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
39
+ tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
40
+ formula: import_zod.z.string().describe("Formula expression to evaluate (e.g., variable name or calculation)"),
41
+ filters: import_zod.z.array(import_zod.z.array(import_zod.z.string()).length(2)).optional().describe('Dimension filters as [tableName, memberName] pairs (e.g., [["Years","2024"],["Months","Jan"]])')
42
+ };
43
+ const listDimensionMembersSchema = {
44
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
45
+ tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
46
+ tableName: import_zod.z.string().describe("Dimension table name"),
47
+ limit: import_zod.z.number().optional().describe("Maximum number of members to return")
48
+ };
49
+ const manageDimensionMembersSchema = {
50
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
51
+ tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
52
+ action: import_zod.z.enum(["create", "delete"]).describe("Action to perform"),
53
+ tableName: import_zod.z.string().describe("Dimension table name"),
54
+ memberName: import_zod.z.string().describe("Member name to create or delete"),
55
+ parentMemberName: import_zod.z.string().optional().describe("Parent member name (for create with hierarchy)")
56
+ };
57
+ const createVariableSchema = {
58
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
59
+ tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
60
+ name: import_zod.z.string().describe("Variable name"),
61
+ dimensions: import_zod.z.array(import_zod.z.string()).optional().describe("Dimension table names this variable spans"),
62
+ formula: import_zod.z.string().optional().describe("Formula expression"),
63
+ rollupType: import_zod.z.string().optional().describe("Rollup type (Sum, Average, Min, Max, Last, First, Count)"),
64
+ dataType: import_zod.z.string().optional().describe("Data type (Decimal, Integer, Text)"),
65
+ description: import_zod.z.string().optional().describe("Variable description"),
66
+ readonly: import_zod.z.boolean().optional().describe("Whether the variable is read-only")
67
+ };
68
+ const updateVariableSchema = {
69
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
70
+ tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
71
+ name: import_zod.z.string().describe("Variable name to update"),
72
+ formula: import_zod.z.string().optional().describe("New formula expression"),
73
+ rollupType: import_zod.z.string().optional().describe("New rollup type"),
74
+ description: import_zod.z.string().optional().describe("New description"),
75
+ readonly: import_zod.z.boolean().optional().describe("Set read-only status")
76
+ };
13
77
  const exportModelSchema = {
14
- tenant: zod_1.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
15
- organisation: zod_1.z
16
- .string()
17
- .optional()
18
- .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
78
+ tenant: import_zod.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
79
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.")
19
80
  };
20
81
  const listTablesSchema = {
21
- tenant: zod_1.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
22
- organisation: zod_1.z
23
- .string()
24
- .optional()
25
- .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
82
+ tenant: import_zod.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
83
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.")
26
84
  };
27
85
  const listVariablesSchema = {
28
- tenant: zod_1.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
29
- organisation: zod_1.z
30
- .string()
31
- .optional()
32
- .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
86
+ tenant: import_zod.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
87
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.")
33
88
  };
34
89
  const getTableSchema = {
35
- organisation: zod_1.z
36
- .string()
37
- .optional()
38
- .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
39
- tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
40
- tableName: zod_1.z.string().describe('Name of the dimension table'),
90
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
91
+ tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
92
+ tableName: import_zod.z.string().describe("Name of the dimension table")
41
93
  };
42
94
  const getVariableSchema = {
43
- organisation: zod_1.z
44
- .string()
45
- .optional()
46
- .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
47
- tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
48
- variableName: zod_1.z.string().describe('Name of the variable'),
95
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
96
+ tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
97
+ variableName: import_zod.z.string().describe("Name of the variable")
49
98
  };
50
99
  function registerModelTools(server) {
51
- // farseer_export_model - Export complete model
52
- server.tool('farseer_export_model', `Export the complete data model structure from a Farseer tenant.
100
+ server.tool(
101
+ "farseer_export_model",
102
+ `Export the complete data model structure from a Farseer tenant.
53
103
 
54
104
  Returns:
55
105
  - All dimension tables with member counts and foreign key relationships
@@ -60,57 +110,61 @@ This is essential for understanding a tenant's data structure before writing imp
60
110
  The model export can be large for complex tenants. Use farseer_list_tables or
61
111
  farseer_list_variables for a summary view.
62
112
 
63
- If no tenant is specified, uses the currently checked-out tenant.`, exportModelSchema, async (params) => {
64
- const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
65
- if (!resolved) {
66
- return (0, helpers_1.tenantRequiredResponse)();
67
- }
68
- const { organisation, tenant } = resolved;
69
- const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
70
- if (!clientResult) {
71
- return (0, helpers_1.authRequiredResponse)(tenant);
72
- }
73
- try {
74
- const model = await clientResult.client.exportModel();
75
- // Process tables
76
- const tables = model.tables.map((t) => ({
77
- name: t.name,
78
- memberCount: t.rows?.length || 0,
79
- columns: t.columns.map((c) => ({
80
- type: c.type,
81
- name: c.name,
82
- foreignKeyTable: c.foreignKeyTableName,
83
- })),
84
- foreignKeys: t.columns.filter((c) => c.type === 'FOREIGN_KEY').map((c) => c.foreignKeyTableName),
85
- folderPath: t.folderPath,
86
- }));
87
- // Process variables
88
- const variables = model.variables.map((v) => ({
89
- name: v.name,
90
- dimensions: v.tables || [],
91
- formula: v.formula || undefined,
92
- rollupType: v.rollupType,
93
- numberFormat: v.numberFormat,
94
- readonly: v.readonly,
95
- calculateOnDemand: v.calculateOnDemand,
96
- folderPath: v.folderPath,
97
- }));
98
- return (0, helpers_1.successResponse)({
99
- tenant,
100
- summary: {
101
- tableCount: tables.length,
102
- variableCount: variables.length,
103
- },
104
- tables,
105
- variables,
106
- });
107
- }
108
- catch (error) {
109
- return (0, helpers_1.errorResponse)(`Export model failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
110
- }
111
- });
112
- // farseer_list_tables - List dimension tables
113
- server.tool('farseer_list_tables', `List all dimension tables in a Farseer tenant model.
113
+ If no tenant is specified, uses the currently checked-out tenant.`,
114
+ exportModelSchema,
115
+ async (params) => {
116
+ const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
117
+ if (!resolved) {
118
+ return (0, import_helpers.tenantRequiredResponse)();
119
+ }
120
+ const { organisation, tenant } = resolved;
121
+ const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
122
+ if (!clientResult) {
123
+ return (0, import_helpers.authRequiredResponse)(tenant);
124
+ }
125
+ try {
126
+ const model = await clientResult.client.exportModel();
127
+ const tables = model.tables.map((t) => ({
128
+ name: t.name,
129
+ memberCount: t.rows?.length || 0,
130
+ columns: t.columns.map((c) => ({
131
+ type: c.type,
132
+ name: c.name,
133
+ foreignKeyTable: c.foreignKeyTableName
134
+ })),
135
+ foreignKeys: t.columns.filter((c) => c.type === "FOREIGN_KEY").map((c) => c.foreignKeyTableName),
136
+ folderPath: t.folderPath
137
+ }));
138
+ const variables = model.variables.map((v) => ({
139
+ name: v.name,
140
+ dimensions: v.tables || [],
141
+ formula: v.formula || void 0,
142
+ rollupType: v.rollupType,
143
+ numberFormat: v.numberFormat,
144
+ readonly: v.readonly,
145
+ calculateOnDemand: v.calculateOnDemand,
146
+ folderPath: v.folderPath
147
+ }));
148
+ return (0, import_helpers.successResponse)({
149
+ tenant,
150
+ summary: {
151
+ tableCount: tables.length,
152
+ variableCount: variables.length
153
+ },
154
+ tables,
155
+ variables
156
+ });
157
+ } catch (error) {
158
+ return (0, import_helpers.errorResponse)(
159
+ `Export model failed: ${error instanceof Error ? error.message : "Unknown error"}`,
160
+ "NETWORK_ERROR"
161
+ );
162
+ }
163
+ }
164
+ );
165
+ server.tool(
166
+ "farseer_list_tables",
167
+ `List all dimension tables in a Farseer tenant model.
114
168
 
115
169
  Dimension tables define the structure of data:
116
170
  - Product, Region, Customer (business dimensions)
@@ -119,37 +173,42 @@ Dimension tables define the structure of data:
119
173
 
120
174
  Returns table names, member counts, and foreign key relationships.
121
175
 
122
- If no tenant is specified, uses the currently checked-out tenant.`, listTablesSchema, async (params) => {
123
- const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
124
- if (!resolved) {
125
- return (0, helpers_1.tenantRequiredResponse)();
126
- }
127
- const { organisation, tenant } = resolved;
128
- const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
129
- if (!clientResult) {
130
- return (0, helpers_1.authRequiredResponse)(tenant);
131
- }
132
- try {
133
- const model = await clientResult.client.exportModel();
134
- const tables = model.tables.map((t) => ({
135
- name: t.name,
136
- memberCount: t.rows?.length || 0,
137
- foreignKeys: t.columns.filter((c) => c.type === 'FOREIGN_KEY').map((c) => c.foreignKeyTableName),
138
- }));
139
- // Sort by name
140
- tables.sort((a, b) => a.name.localeCompare(b.name));
141
- return (0, helpers_1.successResponse)({
142
- tenant,
143
- totalTables: tables.length,
144
- tables,
145
- });
146
- }
147
- catch (error) {
148
- return (0, helpers_1.errorResponse)(`List tables failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
149
- }
150
- });
151
- // farseer_list_variables - List variables
152
- server.tool('farseer_list_variables', `List all variables defined in a Farseer tenant model.
176
+ If no tenant is specified, uses the currently checked-out tenant.`,
177
+ listTablesSchema,
178
+ async (params) => {
179
+ const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
180
+ if (!resolved) {
181
+ return (0, import_helpers.tenantRequiredResponse)();
182
+ }
183
+ const { organisation, tenant } = resolved;
184
+ const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
185
+ if (!clientResult) {
186
+ return (0, import_helpers.authRequiredResponse)(tenant);
187
+ }
188
+ try {
189
+ const model = await clientResult.client.exportModel();
190
+ const tables = model.tables.map((t) => ({
191
+ name: t.name,
192
+ memberCount: t.rows?.length || 0,
193
+ foreignKeys: t.columns.filter((c) => c.type === "FOREIGN_KEY").map((c) => c.foreignKeyTableName)
194
+ }));
195
+ tables.sort((a, b) => a.name.localeCompare(b.name));
196
+ return (0, import_helpers.successResponse)({
197
+ tenant,
198
+ totalTables: tables.length,
199
+ tables
200
+ });
201
+ } catch (error) {
202
+ return (0, import_helpers.errorResponse)(
203
+ `List tables failed: ${error instanceof Error ? error.message : "Unknown error"}`,
204
+ "NETWORK_ERROR"
205
+ );
206
+ }
207
+ }
208
+ );
209
+ server.tool(
210
+ "farseer_list_variables",
211
+ `List all variables defined in a Farseer tenant model.
153
212
 
154
213
  Variables store data and calculations - they are the core of the data model.
155
214
 
@@ -158,39 +217,44 @@ Each variable has:
158
217
  - Optional formula for calculated values
159
218
  - Roll-up type (how values aggregate up hierarchies)
160
219
 
161
- If no tenant is specified, uses the currently checked-out tenant.`, listVariablesSchema, async (params) => {
162
- const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
163
- if (!resolved) {
164
- return (0, helpers_1.tenantRequiredResponse)();
165
- }
166
- const { organisation, tenant } = resolved;
167
- const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
168
- if (!clientResult) {
169
- return (0, helpers_1.authRequiredResponse)(tenant);
170
- }
171
- try {
172
- const model = await clientResult.client.exportModel();
173
- const variables = model.variables.map((v) => ({
174
- name: v.name,
175
- dimensions: v.tables || [],
176
- hasFormula: !!v.formula,
177
- rollupType: v.rollupType,
178
- readonly: v.readonly,
179
- }));
180
- // Sort by name
181
- variables.sort((a, b) => a.name.localeCompare(b.name));
182
- return (0, helpers_1.successResponse)({
183
- tenant,
184
- totalVariables: variables.length,
185
- variables,
186
- });
187
- }
188
- catch (error) {
189
- return (0, helpers_1.errorResponse)(`List variables failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
190
- }
191
- });
192
- // farseer_get_table - Get dimension table details
193
- server.tool('farseer_get_table', `Get detailed information about a specific dimension table.
220
+ If no tenant is specified, uses the currently checked-out tenant.`,
221
+ listVariablesSchema,
222
+ async (params) => {
223
+ const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
224
+ if (!resolved) {
225
+ return (0, import_helpers.tenantRequiredResponse)();
226
+ }
227
+ const { organisation, tenant } = resolved;
228
+ const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
229
+ if (!clientResult) {
230
+ return (0, import_helpers.authRequiredResponse)(tenant);
231
+ }
232
+ try {
233
+ const model = await clientResult.client.exportModel();
234
+ const variables = model.variables.map((v) => ({
235
+ name: v.name,
236
+ dimensions: v.tables || [],
237
+ hasFormula: !!v.formula,
238
+ rollupType: v.rollupType,
239
+ readonly: v.readonly
240
+ }));
241
+ variables.sort((a, b) => a.name.localeCompare(b.name));
242
+ return (0, import_helpers.successResponse)({
243
+ tenant,
244
+ totalVariables: variables.length,
245
+ variables
246
+ });
247
+ } catch (error) {
248
+ return (0, import_helpers.errorResponse)(
249
+ `List variables failed: ${error instanceof Error ? error.message : "Unknown error"}`,
250
+ "NETWORK_ERROR"
251
+ );
252
+ }
253
+ }
254
+ );
255
+ server.tool(
256
+ "farseer_get_table",
257
+ `Get detailed information about a specific dimension table.
194
258
 
195
259
  Returns:
196
260
  - Table columns with their types
@@ -200,50 +264,55 @@ Returns:
200
264
 
201
265
  This helps understand the structure needed for import scripts.
202
266
 
203
- If no tenant is specified, uses the currently checked-out tenant.`, getTableSchema, async (params) => {
204
- const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
205
- if (!resolved) {
206
- return (0, helpers_1.tenantRequiredResponse)();
207
- }
208
- const { organisation, tenant } = resolved;
209
- const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
210
- if (!clientResult) {
211
- return (0, helpers_1.authRequiredResponse)(tenant);
267
+ If no tenant is specified, uses the currently checked-out tenant.`,
268
+ getTableSchema,
269
+ async (params) => {
270
+ const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
271
+ if (!resolved) {
272
+ return (0, import_helpers.tenantRequiredResponse)();
273
+ }
274
+ const { organisation, tenant } = resolved;
275
+ const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
276
+ if (!clientResult) {
277
+ return (0, import_helpers.authRequiredResponse)(tenant);
278
+ }
279
+ try {
280
+ const model = await clientResult.client.exportModel();
281
+ const table = model.tables.find((t) => t.name.toLowerCase() === params.tableName.toLowerCase());
282
+ if (!table) {
283
+ return (0, import_helpers.errorResponse)(`Table "${params.tableName}" not found`, "NOT_FOUND");
212
284
  }
213
- try {
214
- const model = await clientResult.client.exportModel();
215
- const table = model.tables.find((t) => t.name.toLowerCase() === params.tableName.toLowerCase());
216
- if (!table) {
217
- return (0, helpers_1.errorResponse)(`Table "${params.tableName}" not found`, 'NOT_FOUND');
218
- }
219
- // Get sample members (first column is usually the primary key / name)
220
- const primaryKeyColumn = table.columns.find((c) => c.type === 'PRIMARY_KEY');
221
- let sampleMembers = [];
222
- if (table.rows && table.rows.length > 0) {
223
- const pkIndex = primaryKeyColumn ? table.columns.indexOf(primaryKeyColumn) : 0;
224
- sampleMembers = table.rows.slice(0, 20).map((row) => String(row[pkIndex]));
225
- }
226
- return (0, helpers_1.successResponse)({
227
- tenant,
228
- table: {
229
- name: table.name,
230
- columns: table.columns.map((c) => ({
231
- type: c.type,
232
- name: c.name,
233
- foreignKeyTable: c.foreignKeyTableName,
234
- })),
235
- memberCount: table.rows?.length || 0,
236
- sampleMembers,
237
- folderPath: table.folderPath,
238
- },
239
- });
285
+ const primaryKeyColumn = table.columns.find((c) => c.type === "PRIMARY_KEY");
286
+ let sampleMembers = [];
287
+ if (table.rows && table.rows.length > 0) {
288
+ const pkIndex = primaryKeyColumn ? table.columns.indexOf(primaryKeyColumn) : 0;
289
+ sampleMembers = table.rows.slice(0, 20).map((row) => String(row[pkIndex]));
240
290
  }
241
- catch (error) {
242
- return (0, helpers_1.errorResponse)(`Get table failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
243
- }
244
- });
245
- // farseer_get_variable - Get variable details
246
- server.tool('farseer_get_variable', `Get detailed information about a specific variable.
291
+ return (0, import_helpers.successResponse)({
292
+ tenant,
293
+ table: {
294
+ name: table.name,
295
+ columns: table.columns.map((c) => ({
296
+ type: c.type,
297
+ name: c.name,
298
+ foreignKeyTable: c.foreignKeyTableName
299
+ })),
300
+ memberCount: table.rows?.length || 0,
301
+ sampleMembers,
302
+ folderPath: table.folderPath
303
+ }
304
+ });
305
+ } catch (error) {
306
+ return (0, import_helpers.errorResponse)(
307
+ `Get table failed: ${error instanceof Error ? error.message : "Unknown error"}`,
308
+ "NETWORK_ERROR"
309
+ );
310
+ }
311
+ }
312
+ );
313
+ server.tool(
314
+ "farseer_get_variable",
315
+ `Get detailed information about a specific variable.
247
316
 
248
317
  Returns:
249
318
  - Dimensions the variable spans
@@ -254,40 +323,317 @@ Returns:
254
323
 
255
324
  This is essential for understanding what dimensions and values are needed for imports.
256
325
 
257
- If no tenant is specified, uses the currently checked-out tenant.`, getVariableSchema, async (params) => {
258
- const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
259
- if (!resolved) {
260
- return (0, helpers_1.tenantRequiredResponse)();
261
- }
262
- const { organisation, tenant } = resolved;
263
- const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
264
- if (!clientResult) {
265
- return (0, helpers_1.authRequiredResponse)(tenant);
326
+ If no tenant is specified, uses the currently checked-out tenant.`,
327
+ getVariableSchema,
328
+ async (params) => {
329
+ const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
330
+ if (!resolved) {
331
+ return (0, import_helpers.tenantRequiredResponse)();
332
+ }
333
+ const { organisation, tenant } = resolved;
334
+ const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
335
+ if (!clientResult) {
336
+ return (0, import_helpers.authRequiredResponse)(tenant);
337
+ }
338
+ try {
339
+ const model = await clientResult.client.exportModel();
340
+ const variable = model.variables.find(
341
+ (v) => v.name.toLowerCase() === params.variableName.toLowerCase()
342
+ );
343
+ if (!variable) {
344
+ return (0, import_helpers.errorResponse)(`Variable "${params.variableName}" not found`, "NOT_FOUND");
266
345
  }
267
- try {
268
- const model = await clientResult.client.exportModel();
269
- const variable = model.variables.find((v) => v.name.toLowerCase() === params.variableName.toLowerCase());
270
- if (!variable) {
271
- return (0, helpers_1.errorResponse)(`Variable "${params.variableName}" not found`, 'NOT_FOUND');
346
+ return (0, import_helpers.successResponse)({
347
+ tenant,
348
+ variable: {
349
+ name: variable.name,
350
+ description: variable.description,
351
+ formula: variable.formula,
352
+ dimensions: variable.tables || [],
353
+ rollupType: variable.rollupType,
354
+ dataType: variable.dataType,
355
+ numberFormat: variable.numberFormat,
356
+ readonly: variable.readonly,
357
+ calculateOnDemand: variable.calculateOnDemand,
358
+ folderPath: variable.folderPath
359
+ }
360
+ });
361
+ } catch (error) {
362
+ return (0, import_helpers.errorResponse)(
363
+ `Get variable failed: ${error instanceof Error ? error.message : "Unknown error"}`,
364
+ "NETWORK_ERROR"
365
+ );
366
+ }
367
+ }
368
+ );
369
+ server.tool(
370
+ "farseer_evaluate_formula",
371
+ `Evaluate a formula expression in a Farseer tenant.
372
+
373
+ The formula can be a variable name or a calculation expression.
374
+ Filters narrow the evaluation to specific dimension members.
375
+
376
+ Example: evaluate "Revenue" with filters [["Years","2024"],["Months","Jan"]]
377
+
378
+ Returns the computed value along with cell metadata (readonly, calculated, frozen).
379
+
380
+ If no tenant is specified, uses the currently checked-out tenant.`,
381
+ evaluateFormulaSchema,
382
+ // @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
383
+ async (params) => {
384
+ const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
385
+ if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
386
+ const { organisation, tenant } = resolved;
387
+ const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
388
+ if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
389
+ try {
390
+ const evaluateRequest = {
391
+ filters: params.filters || [],
392
+ cellQueries: [{ type: "VARIABLE", formula: params.formula }]
393
+ };
394
+ const results = await nativeClient.evaluator.evaluate(evaluateRequest);
395
+ return (0, import_helpers.successResponse)({
396
+ tenant,
397
+ formula: params.formula,
398
+ filters: params.filters || [],
399
+ results: results.map((r) => ({
400
+ value: r.value,
401
+ readonly: r.readonly,
402
+ calculated: r.calculated,
403
+ frozen: r.frozen,
404
+ goal: r.goal
405
+ }))
406
+ });
407
+ } catch (error) {
408
+ return (0, import_helpers.errorResponse)(`Evaluate formula failed: ${await extractErrorMessage(error)}`, "NETWORK_ERROR");
409
+ }
410
+ }
411
+ );
412
+ server.tool(
413
+ "farseer_list_dimension_members",
414
+ `List all members of a specific dimension table.
415
+
416
+ Uses initTagMap() to load the model's tag map, then retrieves members for the specified table.
417
+ Returns member IDs, names, and parent relationships.
418
+
419
+ If no tenant is specified, uses the currently checked-out tenant.`,
420
+ listDimensionMembersSchema,
421
+ async (params) => {
422
+ const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
423
+ if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
424
+ const { organisation, tenant } = resolved;
425
+ const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
426
+ if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
427
+ try {
428
+ await nativeClient.initTagMap();
429
+ const members = await nativeClient.getDimensionMembersForTable(params.tableName);
430
+ const limit = params.limit || members.length;
431
+ const result = members.slice(0, limit).map((m) => ({
432
+ id: m.id,
433
+ name: m.name,
434
+ parentId: m.ParentId
435
+ }));
436
+ return (0, import_helpers.successResponse)({
437
+ tenant,
438
+ tableName: params.tableName,
439
+ totalMembers: members.length,
440
+ returned: result.length,
441
+ members: result
442
+ });
443
+ } catch (error) {
444
+ return (0, import_helpers.errorResponse)(
445
+ `List dimension members failed: ${await extractErrorMessage(error)}`,
446
+ "NETWORK_ERROR"
447
+ );
448
+ }
449
+ }
450
+ );
451
+ server.tool(
452
+ "farseer_manage_dimension_members",
453
+ `Create or delete a dimension member in a Farseer tenant.
454
+
455
+ Actions:
456
+ - "create": Creates a new member in the specified dimension table.
457
+ Optionally set a parent member for hierarchical tables.
458
+ - "delete": Deletes an existing member by name from the specified table.
459
+
460
+ WARNING: Delete is destructive and may affect data. Use with caution.
461
+
462
+ If no tenant is specified, uses the currently checked-out tenant.`,
463
+ manageDimensionMembersSchema,
464
+ async (params) => {
465
+ const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
466
+ if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
467
+ const { organisation, tenant } = resolved;
468
+ const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
469
+ if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
470
+ try {
471
+ await nativeClient.initTagMap();
472
+ if (params.action === "create") {
473
+ const table = await nativeClient.getDimensionTable(params.tableName);
474
+ const createEntity = {
475
+ type: import_farseer_client.EntityType.DimensionMember,
476
+ meta: { name: params.memberName },
477
+ relations: {
478
+ parent: { id: table.id }
272
479
  }
273
- return (0, helpers_1.successResponse)({
274
- tenant,
275
- variable: {
276
- name: variable.name,
277
- description: variable.description,
278
- formula: variable.formula,
279
- dimensions: variable.tables || [],
280
- rollupType: variable.rollupType,
281
- dataType: variable.dataType,
282
- numberFormat: variable.numberFormat,
283
- readonly: variable.readonly,
284
- calculateOnDemand: variable.calculateOnDemand,
285
- folderPath: variable.folderPath,
286
- },
287
- });
480
+ };
481
+ if (params.parentMemberName) {
482
+ const parentMember = await nativeClient.getDimensionMember(
483
+ params.tableName,
484
+ params.parentMemberName
485
+ );
486
+ createEntity.relations.parent = { id: parentMember.id };
487
+ }
488
+ const result = await nativeClient.entities.mutate({ created: [createEntity] });
489
+ return (0, import_helpers.successResponse)({
490
+ tenant,
491
+ action: "created",
492
+ tableName: params.tableName,
493
+ memberName: params.memberName,
494
+ parentMemberName: params.parentMemberName || null,
495
+ result
496
+ });
497
+ } else {
498
+ const member = await nativeClient.getDimensionMember(params.tableName, params.memberName);
499
+ await nativeClient.entities.mutate({
500
+ deleted: [{ id: member.id, type: import_farseer_client.EntityType.DimensionMember }]
501
+ });
502
+ return (0, import_helpers.successResponse)({
503
+ tenant,
504
+ action: "deleted",
505
+ tableName: params.tableName,
506
+ memberName: params.memberName,
507
+ memberId: member.id
508
+ });
509
+ }
510
+ } catch (error) {
511
+ return (0, import_helpers.errorResponse)(
512
+ `Manage dimension member failed: ${await extractErrorMessage(error)}`,
513
+ "NETWORK_ERROR"
514
+ );
515
+ }
516
+ }
517
+ );
518
+ server.tool(
519
+ "farseer_create_variable",
520
+ `Create a new variable in a Farseer tenant.
521
+
522
+ Creates a variable with the specified name, dimension tables, formula, rollup type, and data type.
523
+ Dimension table names are resolved to their internal IDs automatically.
524
+
525
+ Example:
526
+ {
527
+ "name": "Revenue Forecast",
528
+ "dimensions": ["Product", "Years", "Months"],
529
+ "formula": "Revenue * 1.1",
530
+ "rollupType": "Sum",
531
+ "dataType": "Decimal"
532
+ }
533
+
534
+ If no tenant is specified, uses the currently checked-out tenant.`,
535
+ createVariableSchema,
536
+ // @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
537
+ async (params) => {
538
+ const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
539
+ if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
540
+ const { organisation, tenant } = resolved;
541
+ const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
542
+ if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
543
+ try {
544
+ await nativeClient.initTagMap();
545
+ const tableGids = [];
546
+ if (params.dimensions) {
547
+ for (const tableName of params.dimensions) {
548
+ const table = await nativeClient.getDimensionTable(tableName);
549
+ tableGids.push(table.id);
550
+ }
551
+ }
552
+ const createEntity = {
553
+ type: import_farseer_client.EntityType.Variable,
554
+ meta: {
555
+ name: params.name,
556
+ description: params.description || null
557
+ },
558
+ variable: {
559
+ tableGids,
560
+ rollupType: params.rollupType || "Sum",
561
+ dataType: params.dataType || "Decimal",
562
+ readonly: params.readonly || false
563
+ }
564
+ };
565
+ if (params.formula) {
566
+ createEntity.calculation = { formula: params.formula };
567
+ }
568
+ const result = await nativeClient.entities.mutate({ created: [createEntity] });
569
+ return (0, import_helpers.successResponse)({
570
+ tenant,
571
+ action: "created",
572
+ variable: params.name,
573
+ dimensions: params.dimensions || [],
574
+ result
575
+ });
576
+ } catch (error) {
577
+ return (0, import_helpers.errorResponse)(`Create variable failed: ${await extractErrorMessage(error)}`, "NETWORK_ERROR");
578
+ }
579
+ }
580
+ );
581
+ server.tool(
582
+ "farseer_update_variable",
583
+ `Update an existing variable in a Farseer tenant.
584
+
585
+ Resolves the variable by name and updates the specified fields.
586
+ Only provided fields are updated; omitted fields remain unchanged.
587
+
588
+ Updatable fields:
589
+ - formula: Change the calculation formula
590
+ - rollupType: Change aggregation method (Sum, Average, Min, Max, etc.)
591
+ - description: Change the variable description
592
+ - readonly: Set or clear read-only status
593
+
594
+ If no tenant is specified, uses the currently checked-out tenant.`,
595
+ updateVariableSchema,
596
+ async (params) => {
597
+ const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
598
+ if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
599
+ const { organisation, tenant } = resolved;
600
+ const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
601
+ if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
602
+ try {
603
+ await nativeClient.initTagMap();
604
+ const variable = await nativeClient.getVariable(params.name);
605
+ const updateEntity = {
606
+ id: variable.id,
607
+ type: import_farseer_client.EntityType.Variable
608
+ };
609
+ if (params.description !== void 0) {
610
+ updateEntity.meta = { name: variable.name, description: params.description };
611
+ }
612
+ const variableUpdate = {};
613
+ if (params.rollupType) variableUpdate.rollupType = params.rollupType;
614
+ if (params.readonly !== void 0) variableUpdate.readonly = params.readonly;
615
+ if (Object.keys(variableUpdate).length > 0) {
616
+ updateEntity.variable = variableUpdate;
288
617
  }
289
- catch (error) {
290
- return (0, helpers_1.errorResponse)(`Get variable failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
618
+ if (params.formula !== void 0) {
619
+ updateEntity.calculation = { formula: params.formula };
291
620
  }
292
- });
621
+ const result = await nativeClient.entities.mutate({ updated: [updateEntity] });
622
+ return (0, import_helpers.successResponse)({
623
+ tenant,
624
+ action: "updated",
625
+ variable: params.name,
626
+ variableId: variable.id,
627
+ result
628
+ });
629
+ } catch (error) {
630
+ return (0, import_helpers.errorResponse)(`Update variable failed: ${await extractErrorMessage(error)}`, "NETWORK_ERROR");
631
+ }
632
+ }
633
+ );
293
634
  }
635
+ // Annotate the CommonJS export names for ESM import in node:
636
+ 0 && (module.exports = {
637
+ registerModelTools
638
+ });
639
+ //# sourceMappingURL=modelTools.js.map