farseer-cli 1.0.8 → 1.0.10
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/dist/commands/app.js +377 -0
- package/dist/commands/apps.js +91 -0
- package/dist/commands/checkout.js +164 -0
- package/dist/commands/config.js +141 -0
- package/dist/commands/diff.js +210 -0
- package/dist/commands/dimensions.js +130 -0
- package/dist/commands/files.js +88 -0
- package/dist/commands/install.js +82 -0
- package/dist/commands/list.js +77 -0
- package/dist/commands/login.js +109 -0
- package/dist/commands/logout.js +44 -0
- package/dist/commands/mcp-server.js +26 -0
- package/dist/commands/model.js +181 -0
- package/dist/commands/pull.js +286 -0
- package/dist/commands/push.js +235 -0
- package/dist/commands/run.js +336 -0
- package/dist/commands/status.js +178 -0
- package/dist/commands/variables.js +200 -0
- package/dist/commands/whoami.js +47 -0
- package/dist/index.js +163 -0
- package/dist/mcp/index.js +19 -0
- package/dist/mcp/prompts/workflows.js +403 -0
- package/dist/mcp/resources/documentation.js +158 -0
- package/dist/mcp/server.js +36 -0
- package/dist/mcp/tools/appTools.js +348 -0
- package/dist/mcp/tools/authTools.js +152 -0
- package/dist/mcp/tools/dataTools.js +358 -0
- package/dist/mcp/tools/modelTools.js +293 -0
- package/dist/mcp/tools/runTools.js +239 -0
- package/dist/mcp/tools/syncTools.js +383 -0
- package/dist/mcp/utils/helpers.js +142 -0
- package/dist/services/appSyncService.js +458 -0
- package/dist/services/configService.js +186 -0
- package/dist/services/farseerApi.js +426 -0
- package/dist/services/farseerFactory.js +297 -0
- package/dist/services/farseerService.js +647 -0
- package/dist/services/syncService.js +764 -0
- package/dist/utils/constants.js +21 -0
- package/dist/utils/helpers.js +446 -0
- package/dist/utils/logger.js +45 -0
- package/package.json +8 -1
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* App Management Tools
|
|
4
|
+
*
|
|
5
|
+
* Tools for managing Farseer apps (Remote Jobs).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.registerAppTools = registerAppTools;
|
|
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
|
|
13
|
+
const listAppsSchema = {
|
|
14
|
+
organisation: zod_1.z
|
|
15
|
+
.string()
|
|
16
|
+
.optional()
|
|
17
|
+
.describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
|
|
18
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
|
|
19
|
+
details: zod_1.z.boolean().optional().describe('Include full details for each app'),
|
|
20
|
+
};
|
|
21
|
+
const getAppSchema = {
|
|
22
|
+
organisation: zod_1.z
|
|
23
|
+
.string()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
|
|
26
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
|
|
27
|
+
appName: zod_1.z.string().describe('Name of the app (can include spaces)'),
|
|
28
|
+
};
|
|
29
|
+
const createAppSchema = {
|
|
30
|
+
organisation: zod_1.z
|
|
31
|
+
.string()
|
|
32
|
+
.optional()
|
|
33
|
+
.describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
|
|
34
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
|
|
35
|
+
appName: zod_1.z.string().describe('Name for the new app'),
|
|
36
|
+
};
|
|
37
|
+
const argumentSchema = zod_1.z.object({
|
|
38
|
+
name: zod_1.z.string(),
|
|
39
|
+
defaultValue: zod_1.z.string(),
|
|
40
|
+
});
|
|
41
|
+
const configureAppSchema = {
|
|
42
|
+
organisation: zod_1.z
|
|
43
|
+
.string()
|
|
44
|
+
.optional()
|
|
45
|
+
.describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
|
|
46
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
|
|
47
|
+
appName: zod_1.z.string().describe('Name of the app to configure'),
|
|
48
|
+
entrypoint: zod_1.z.string().optional().describe('Main script filename (e.g., "index.ts")'),
|
|
49
|
+
scripts: zod_1.z.array(zod_1.z.string()).optional().describe('List of script filenames to include'),
|
|
50
|
+
description: zod_1.z.string().optional().describe('App description'),
|
|
51
|
+
arguments: zod_1.z.array(argumentSchema).optional().describe('App arguments with default values'),
|
|
52
|
+
newName: zod_1.z.string().optional().describe('Rename the app'),
|
|
53
|
+
};
|
|
54
|
+
const deleteAppSchema = {
|
|
55
|
+
organisation: zod_1.z
|
|
56
|
+
.string()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
|
|
59
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
|
|
60
|
+
appName: zod_1.z.string().describe('Name of the app to delete'),
|
|
61
|
+
};
|
|
62
|
+
function registerAppTools(server) {
|
|
63
|
+
// Cast to avoid TS2589 deep type instantiation with MCP SDK + Zod generics
|
|
64
|
+
const s = server;
|
|
65
|
+
// farseer_list_apps - List all apps
|
|
66
|
+
s.tool('farseer_list_apps', `List all apps (Remote Jobs) configured on a Farseer tenant.
|
|
67
|
+
|
|
68
|
+
Apps are executable script configurations that include:
|
|
69
|
+
- Entry point script
|
|
70
|
+
- List of included scripts
|
|
71
|
+
- Expected arguments with default values
|
|
72
|
+
|
|
73
|
+
Use details=true to include full information for each app.
|
|
74
|
+
|
|
75
|
+
If no tenant is specified, uses the currently checked-out tenant.`, listAppsSchema, async (params) => {
|
|
76
|
+
const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
|
|
77
|
+
if (!resolved) {
|
|
78
|
+
return (0, helpers_1.tenantRequiredResponse)();
|
|
79
|
+
}
|
|
80
|
+
const { organisation, tenant } = resolved;
|
|
81
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
82
|
+
if (!clientResult) {
|
|
83
|
+
return (0, helpers_1.authRequiredResponse)(tenant);
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const appList = await clientResult.client.listApps();
|
|
87
|
+
if (!params.details) {
|
|
88
|
+
return (0, helpers_1.successResponse)({
|
|
89
|
+
tenant,
|
|
90
|
+
totalApps: appList.length,
|
|
91
|
+
apps: appList.map((a) => ({
|
|
92
|
+
name: a.name,
|
|
93
|
+
id: a.id,
|
|
94
|
+
reference: a.reference,
|
|
95
|
+
})),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// Get full details for each app
|
|
99
|
+
const appsWithDetails = [];
|
|
100
|
+
for (const item of appList) {
|
|
101
|
+
const app = await clientResult.client.getApp(item.reference);
|
|
102
|
+
if (app) {
|
|
103
|
+
const appScripts = app.scriptFiles ?? [];
|
|
104
|
+
const mainScript = appScripts.find((s) => s.id === app.mainScriptFileId);
|
|
105
|
+
appsWithDetails.push({
|
|
106
|
+
name: app.name,
|
|
107
|
+
id: app.id,
|
|
108
|
+
description: app.description || '',
|
|
109
|
+
entrypoint: mainScript?.name || null,
|
|
110
|
+
scripts: appScripts.map((s) => s.name),
|
|
111
|
+
arguments: app.expectedArguments.map((a) => ({
|
|
112
|
+
name: a.name,
|
|
113
|
+
defaultValue: a.defaultValue,
|
|
114
|
+
})),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return (0, helpers_1.successResponse)({
|
|
119
|
+
tenant,
|
|
120
|
+
totalApps: appsWithDetails.length,
|
|
121
|
+
apps: appsWithDetails,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
return (0, helpers_1.errorResponse)(`List apps failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
// farseer_get_app - Get app details
|
|
129
|
+
s.tool('farseer_get_app', `Get detailed information about a specific Farseer app.
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
- App name and description
|
|
133
|
+
- Entry point script (main script that runs)
|
|
134
|
+
- List of all included scripts
|
|
135
|
+
- Expected arguments with their default values
|
|
136
|
+
|
|
137
|
+
If no tenant is specified, uses the currently checked-out tenant.`, getAppSchema, async (params) => {
|
|
138
|
+
const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
|
|
139
|
+
if (!resolved) {
|
|
140
|
+
return (0, helpers_1.tenantRequiredResponse)();
|
|
141
|
+
}
|
|
142
|
+
const { organisation, tenant } = resolved;
|
|
143
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
144
|
+
if (!clientResult) {
|
|
145
|
+
return (0, helpers_1.authRequiredResponse)(tenant);
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const app = await clientResult.client.getAppByName(params.appName);
|
|
149
|
+
if (!app) {
|
|
150
|
+
return (0, helpers_1.errorResponse)(`App "${params.appName}" not found`, 'NOT_FOUND');
|
|
151
|
+
}
|
|
152
|
+
const getAppScripts = app.scriptFiles ?? [];
|
|
153
|
+
const mainScript = getAppScripts.find((s) => s.id === app.mainScriptFileId);
|
|
154
|
+
return (0, helpers_1.successResponse)({
|
|
155
|
+
tenant,
|
|
156
|
+
app: {
|
|
157
|
+
id: app.id,
|
|
158
|
+
name: app.name,
|
|
159
|
+
description: app.description || '',
|
|
160
|
+
entrypoint: mainScript?.name || null,
|
|
161
|
+
scripts: getAppScripts.map((s) => ({
|
|
162
|
+
id: s.id,
|
|
163
|
+
name: s.name,
|
|
164
|
+
isEntrypoint: s.id === app.mainScriptFileId,
|
|
165
|
+
})),
|
|
166
|
+
arguments: app.expectedArguments.map((a) => ({
|
|
167
|
+
name: a.name,
|
|
168
|
+
type: a.type,
|
|
169
|
+
defaultValue: a.defaultValue,
|
|
170
|
+
})),
|
|
171
|
+
status: app.status,
|
|
172
|
+
lastHeartbeat: app.lastHeartbeat,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
return (0, helpers_1.errorResponse)(`Get app failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
// farseer_create_app - Create new app
|
|
181
|
+
s.tool('farseer_create_app', `Create a new Farseer app.
|
|
182
|
+
|
|
183
|
+
A Farseer App is a named configuration that points to a TypeScript script and defines its arguments.
|
|
184
|
+
The script uses farseer-client to interact with the Farseer API (import data, export reports, etc.).
|
|
185
|
+
|
|
186
|
+
Workflow to create a new app:
|
|
187
|
+
1. Write the script at farseer-apps/<tenant>/files/Scripts/<name>.ts
|
|
188
|
+
2. Push the script to remote with farseer_push (scripts must exist on remote first)
|
|
189
|
+
3. Create the app with this tool (farseer_create_app)
|
|
190
|
+
4. Configure it with farseer_configure_app (set entrypoint, scripts, arguments)
|
|
191
|
+
5. Run it with farseer_run_app (CLI injects auth credentials automatically)
|
|
192
|
+
|
|
193
|
+
Scripts should use \`new FarseerClient()\` with no arguments - credentials are injected via environment variables by the CLI at runtime.
|
|
194
|
+
|
|
195
|
+
If no tenant is specified, uses the currently checked-out tenant.`, createAppSchema, async (params) => {
|
|
196
|
+
const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
|
|
197
|
+
if (!resolved) {
|
|
198
|
+
return (0, helpers_1.tenantRequiredResponse)();
|
|
199
|
+
}
|
|
200
|
+
const { organisation, tenant } = resolved;
|
|
201
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
202
|
+
if (!clientResult) {
|
|
203
|
+
return (0, helpers_1.authRequiredResponse)(tenant);
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
// Check if app already exists
|
|
207
|
+
const existing = await clientResult.client.getAppByName(params.appName);
|
|
208
|
+
if (existing) {
|
|
209
|
+
return (0, helpers_1.errorResponse)(`App "${params.appName}" already exists`, 'VALIDATION_ERROR');
|
|
210
|
+
}
|
|
211
|
+
const app = await clientResult.client.createApp(params.appName);
|
|
212
|
+
return (0, helpers_1.successResponse)({
|
|
213
|
+
tenant,
|
|
214
|
+
app: {
|
|
215
|
+
id: app.id,
|
|
216
|
+
name: app.name,
|
|
217
|
+
},
|
|
218
|
+
message: `App "${params.appName}" created. Use farseer_configure_app to set entrypoint, scripts, and arguments.`,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
return (0, helpers_1.errorResponse)(`Create app failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
// farseer_configure_app - Configure app settings
|
|
226
|
+
s.tool('farseer_configure_app', `Configure an existing Farseer app.
|
|
227
|
+
|
|
228
|
+
You can set:
|
|
229
|
+
- entrypoint: Main script to execute (e.g., "index.ts")
|
|
230
|
+
- scripts: List of scripts to include in the app
|
|
231
|
+
- description: App description
|
|
232
|
+
- arguments: List of expected arguments with default values
|
|
233
|
+
- newName: Rename the app
|
|
234
|
+
|
|
235
|
+
Important:
|
|
236
|
+
- Scripts must exist on the remote (push them first)
|
|
237
|
+
- If you set scripts but not entrypoint, the first script becomes entrypoint
|
|
238
|
+
- Arguments are passed to the script via command line
|
|
239
|
+
|
|
240
|
+
If no tenant is specified, uses the currently checked-out tenant.`, configureAppSchema, async (params) => {
|
|
241
|
+
const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
|
|
242
|
+
if (!resolved) {
|
|
243
|
+
return (0, helpers_1.tenantRequiredResponse)();
|
|
244
|
+
}
|
|
245
|
+
const { organisation, tenant } = resolved;
|
|
246
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
247
|
+
if (!clientResult) {
|
|
248
|
+
return (0, helpers_1.authRequiredResponse)(tenant);
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
const app = await clientResult.client.getAppByName(params.appName);
|
|
252
|
+
if (!app) {
|
|
253
|
+
return (0, helpers_1.errorResponse)(`App "${params.appName}" not found`, 'NOT_FOUND');
|
|
254
|
+
}
|
|
255
|
+
// Get available scripts for ID lookup
|
|
256
|
+
const availableScripts = await clientResult.client.getScriptFiles();
|
|
257
|
+
const scriptIdMap = new Map(availableScripts.map((s) => [s.name.toLowerCase(), s.id]));
|
|
258
|
+
// Build update payload
|
|
259
|
+
const update = {};
|
|
260
|
+
if (params.newName) {
|
|
261
|
+
update.name = params.newName;
|
|
262
|
+
}
|
|
263
|
+
if (params.description !== undefined) {
|
|
264
|
+
update.description = params.description;
|
|
265
|
+
}
|
|
266
|
+
if (params.arguments) {
|
|
267
|
+
update.expectedArguments = params.arguments.map((a) => ({
|
|
268
|
+
name: a.name,
|
|
269
|
+
type: 'variable',
|
|
270
|
+
defaultValue: a.defaultValue,
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
if (params.scripts && params.scripts.length > 0) {
|
|
274
|
+
const scriptIds = [];
|
|
275
|
+
const notFound = [];
|
|
276
|
+
for (const scriptName of params.scripts) {
|
|
277
|
+
const id = scriptIdMap.get(scriptName.toLowerCase());
|
|
278
|
+
if (id) {
|
|
279
|
+
scriptIds.push(id);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
notFound.push(scriptName);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (notFound.length > 0) {
|
|
286
|
+
return (0, helpers_1.errorResponse)(`Scripts not found on remote: ${notFound.join(', ')}. Push them first.`, 'VALIDATION_ERROR');
|
|
287
|
+
}
|
|
288
|
+
update.scriptFileIds = scriptIds;
|
|
289
|
+
// Set entrypoint to first script if not explicitly specified
|
|
290
|
+
if (!params.entrypoint && scriptIds.length > 0) {
|
|
291
|
+
update.mainScriptFileId = scriptIds[0];
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (params.entrypoint) {
|
|
295
|
+
const entrypointId = scriptIdMap.get(params.entrypoint.toLowerCase());
|
|
296
|
+
if (!entrypointId) {
|
|
297
|
+
return (0, helpers_1.errorResponse)(`Entrypoint script "${params.entrypoint}" not found on remote. Push it first.`, 'VALIDATION_ERROR');
|
|
298
|
+
}
|
|
299
|
+
update.mainScriptFileId = entrypointId;
|
|
300
|
+
}
|
|
301
|
+
// Apply update
|
|
302
|
+
const reference = app.id.toString();
|
|
303
|
+
await clientResult.client.updateApp(reference, update);
|
|
304
|
+
return (0, helpers_1.successResponse)({
|
|
305
|
+
tenant,
|
|
306
|
+
appName: params.newName || params.appName,
|
|
307
|
+
updated: Object.keys(update),
|
|
308
|
+
message: `App "${params.appName}" configured successfully`,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
return (0, helpers_1.errorResponse)(`Configure app failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
// farseer_delete_app - Delete app
|
|
316
|
+
s.tool('farseer_delete_app', `Delete an app from a Farseer tenant.
|
|
317
|
+
|
|
318
|
+
WARNING: This is irreversible - the app will be permanently removed from the remote instance.
|
|
319
|
+
|
|
320
|
+
This does NOT delete the script files, only the app configuration.
|
|
321
|
+
|
|
322
|
+
If no tenant is specified, uses the currently checked-out tenant.`, deleteAppSchema, async (params) => {
|
|
323
|
+
const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
|
|
324
|
+
if (!resolved) {
|
|
325
|
+
return (0, helpers_1.tenantRequiredResponse)();
|
|
326
|
+
}
|
|
327
|
+
const { organisation, tenant } = resolved;
|
|
328
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
329
|
+
if (!clientResult) {
|
|
330
|
+
return (0, helpers_1.authRequiredResponse)(tenant);
|
|
331
|
+
}
|
|
332
|
+
try {
|
|
333
|
+
const app = await clientResult.client.getAppByName(params.appName);
|
|
334
|
+
if (!app) {
|
|
335
|
+
return (0, helpers_1.errorResponse)(`App "${params.appName}" not found`, 'NOT_FOUND');
|
|
336
|
+
}
|
|
337
|
+
await clientResult.client.deleteApp(app.id.toString());
|
|
338
|
+
return (0, helpers_1.successResponse)({
|
|
339
|
+
tenant,
|
|
340
|
+
deletedApp: params.appName,
|
|
341
|
+
message: `App "${params.appName}" has been deleted`,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
return (0, helpers_1.errorResponse)(`Delete app failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication and Configuration Tools
|
|
4
|
+
*
|
|
5
|
+
* Tools for checking auth status and managing tenant checkout.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.registerAuthTools = registerAuthTools;
|
|
9
|
+
const zod_1 = require("zod");
|
|
10
|
+
const configService_1 = require("../../services/configService");
|
|
11
|
+
const farseerFactory_1 = require("../../services/farseerFactory");
|
|
12
|
+
const syncService_1 = require("../../services/syncService");
|
|
13
|
+
const appSyncService_1 = require("../../services/appSyncService");
|
|
14
|
+
const helpers_1 = require("../utils/helpers");
|
|
15
|
+
// Define schemas outside of tool registration to avoid deep type instantiation
|
|
16
|
+
const checkoutSchema = {
|
|
17
|
+
organisation: zod_1.z
|
|
18
|
+
.string()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('Farseer organisation (subdomain). If omitted with tenant, assumes org=tenant.'),
|
|
21
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. If omitted, returns current checkout status.'),
|
|
22
|
+
skipPull: zod_1.z.boolean().optional().describe('Skip automatic pull after checkout (default: false)'),
|
|
23
|
+
};
|
|
24
|
+
function registerAuthTools(server) {
|
|
25
|
+
// farseer_whoami - Check authentication status
|
|
26
|
+
server.tool('farseer_whoami', `Check Farseer authentication status.
|
|
27
|
+
|
|
28
|
+
Returns information about:
|
|
29
|
+
- Whether a JWT token is valid (from browser login)
|
|
30
|
+
- JWT token expiration time
|
|
31
|
+
- Currently checked-out tenant and organisation
|
|
32
|
+
- List of tenants with API keys configured
|
|
33
|
+
|
|
34
|
+
Use this before any operation to verify you have valid credentials.
|
|
35
|
+
If not authenticated, run "farseer login" in terminal.`, {}, async () => {
|
|
36
|
+
const status = (0, helpers_1.getAuthStatus)();
|
|
37
|
+
return (0, helpers_1.successResponse)({
|
|
38
|
+
jwtValid: status.jwtValid,
|
|
39
|
+
jwtExpiresAt: status.jwtExpiresAt,
|
|
40
|
+
currentCheckout: status.currentCheckout,
|
|
41
|
+
configuredTenants: status.configuredTenants,
|
|
42
|
+
message: status.jwtValid
|
|
43
|
+
? 'Authenticated via browser login (JWT)'
|
|
44
|
+
: status.configuredTenants.length > 0
|
|
45
|
+
? 'Not authenticated via browser, but API keys are configured'
|
|
46
|
+
: 'Not authenticated. Run "farseer login" to authenticate.',
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
// farseer_checkout - Set or get default tenant
|
|
50
|
+
server.tool('farseer_checkout', `Set a default tenant for all subsequent Farseer operations, or get the current checkout status.
|
|
51
|
+
|
|
52
|
+
When setting a tenant:
|
|
53
|
+
- Verifies authentication works for that tenant
|
|
54
|
+
- Optionally pulls files and apps from remote
|
|
55
|
+
- Sets the tenant as default for all future commands
|
|
56
|
+
|
|
57
|
+
Organisation and tenant terminology:
|
|
58
|
+
- Organisation: subdomain of Farseer instance (e.g., "fs-personal" for fs-personal.farseer.io)
|
|
59
|
+
- Tenant: workspace ID sent as X-TENANT-ID header
|
|
60
|
+
|
|
61
|
+
Often org and tenant are the same (e.g., "tthotels"), but they can differ
|
|
62
|
+
(e.g., org="fs-personal", tenant="john-doe").
|
|
63
|
+
|
|
64
|
+
If you only provide tenant without organisation, it assumes org=tenant.`, checkoutSchema,
|
|
65
|
+
// @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
|
|
66
|
+
async (params) => {
|
|
67
|
+
const { organisation, tenant, skipPull } = params;
|
|
68
|
+
// If no tenant provided, return current checkout status
|
|
69
|
+
if (!tenant) {
|
|
70
|
+
const current = (0, configService_1.getCurrentCheckout)();
|
|
71
|
+
if (current) {
|
|
72
|
+
return (0, helpers_1.successResponse)({
|
|
73
|
+
currentCheckout: current,
|
|
74
|
+
message: `Currently checked out: ${current.tenant} (org: ${current.organisation})`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return (0, helpers_1.successResponse)({
|
|
79
|
+
currentCheckout: null,
|
|
80
|
+
message: 'No tenant currently checked out. Use tenant parameter to checkout.',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Resolve organisation (default to tenant if not specified)
|
|
85
|
+
const org = organisation || tenant;
|
|
86
|
+
// Test connection before setting checkout
|
|
87
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(org, tenant);
|
|
88
|
+
if (!clientResult) {
|
|
89
|
+
return (0, helpers_1.authRequiredResponse)(tenant);
|
|
90
|
+
}
|
|
91
|
+
// Set checkout and save org-tenant mapping
|
|
92
|
+
if (org === tenant) {
|
|
93
|
+
(0, configService_1.setCurrentTenant)(tenant);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
(0, configService_1.setCurrentCheckout)(org, tenant);
|
|
97
|
+
}
|
|
98
|
+
(0, configService_1.saveTenantOrgMapping)(tenant, org);
|
|
99
|
+
let pullResult = null;
|
|
100
|
+
let appPullResult = null;
|
|
101
|
+
// Pull files and apps unless skipped
|
|
102
|
+
if (!skipPull) {
|
|
103
|
+
try {
|
|
104
|
+
const syncService = new syncService_1.SyncService(tenant, clientResult.client);
|
|
105
|
+
pullResult = await syncService.pull();
|
|
106
|
+
// Pull apps if using JWT auth (API key doesn't support apps)
|
|
107
|
+
if (clientResult.authType === 'jwt') {
|
|
108
|
+
const appSyncService = new appSyncService_1.AppSyncService(tenant, clientResult.client);
|
|
109
|
+
appPullResult = await appSyncService.pull();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// Pull failed but checkout succeeded
|
|
114
|
+
return (0, helpers_1.successResponse)({
|
|
115
|
+
currentCheckout: { organisation: org, tenant },
|
|
116
|
+
message: `Checked out ${tenant}, but pull failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
117
|
+
pullError: true,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return (0, helpers_1.successResponse)({
|
|
122
|
+
currentCheckout: { organisation: org, tenant },
|
|
123
|
+
message: `Successfully checked out ${tenant}${skipPull ? '' : ' and pulled latest files'}`,
|
|
124
|
+
files: pullResult
|
|
125
|
+
? {
|
|
126
|
+
downloaded: pullResult.downloaded,
|
|
127
|
+
deleted: pullResult.deleted,
|
|
128
|
+
unchanged: pullResult.unchanged.length,
|
|
129
|
+
}
|
|
130
|
+
: undefined,
|
|
131
|
+
apps: appPullResult
|
|
132
|
+
? {
|
|
133
|
+
created: appPullResult.created,
|
|
134
|
+
updated: appPullResult.updated,
|
|
135
|
+
deleted: appPullResult.deleted,
|
|
136
|
+
unchanged: appPullResult.unchanged.length,
|
|
137
|
+
}
|
|
138
|
+
: undefined,
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
// farseer_checkout_clear - Clear current checkout
|
|
142
|
+
server.tool('farseer_checkout_clear', `Clear the current tenant checkout.
|
|
143
|
+
|
|
144
|
+
After clearing, you'll need to specify tenant explicitly for all commands.`, {}, async () => {
|
|
145
|
+
const current = (0, configService_1.getCurrentCheckout)();
|
|
146
|
+
(0, configService_1.clearCurrentTenant)();
|
|
147
|
+
return (0, helpers_1.successResponse)({
|
|
148
|
+
previousCheckout: current,
|
|
149
|
+
message: current ? `Cleared checkout for ${current.tenant}` : 'No tenant was checked out',
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|