farseer-cli 1.8.5 → 1.9.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 +7 -6
- package/dist/commands/mcp-server.js +8 -2
- package/dist/commands/mcp-server.js.map +2 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +2 -2
- package/dist/mcp/index.js +10 -1
- package/dist/mcp/index.js.map +2 -2
- package/dist/mcp/prompts/workflows.js +8 -7
- package/dist/mcp/prompts/workflows.js.map +2 -2
- package/dist/mcp/server.js +12 -4
- package/dist/mcp/server.js.map +2 -2
- package/dist/mcp/tools/appTools.js +10 -30
- package/dist/mcp/tools/appTools.js.map +2 -2
- package/dist/mcp/tools/authTools.js +50 -100
- package/dist/mcp/tools/authTools.js.map +2 -2
- package/dist/mcp/tools/cellTools.js +2 -6
- package/dist/mcp/tools/cellTools.js.map +2 -2
- package/dist/mcp/tools/dashboardTools.js +22 -66
- package/dist/mcp/tools/dashboardTools.js.map +2 -2
- package/dist/mcp/tools/dataTools.js +8 -24
- package/dist/mcp/tools/dataTools.js.map +2 -2
- package/dist/mcp/tools/folderTools.js +4 -12
- package/dist/mcp/tools/folderTools.js.map +2 -2
- package/dist/mcp/tools/modelTools.js +30 -84
- package/dist/mcp/tools/modelTools.js.map +2 -2
- package/dist/mcp/tools/runTools.js +5 -13
- package/dist/mcp/tools/runTools.js.map +2 -2
- package/dist/mcp/tools/sheetTools.js +20 -60
- package/dist/mcp/tools/sheetTools.js.map +2 -2
- package/dist/mcp/tools/syncTools.js +8 -30
- package/dist/mcp/tools/syncTools.js.map +2 -2
- package/dist/mcp/utils/helpers.js +18 -44
- package/dist/mcp/utils/helpers.js.map +2 -2
- package/dist/mcp/utils/launchPin.js +44 -0
- package/dist/mcp/utils/launchPin.js.map +7 -0
- package/dist/mcp/utils/tenantPin.js +58 -0
- package/dist/mcp/utils/tenantPin.js.map +7 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/mcp/tools/appTools.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * App Management Tools\n *\n * Tools for managing Farseer apps (Remote Jobs).\n */\n\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport { getFarseerClientWithFallback } from '../../services/farseerFactory';\nimport { AppArgument, AppUpdateChanges, applySourceFolderChange } from '../../services/farseerApi';\nimport {\n resolveOrgAndTenant,\n successResponse,\n errorResponse,\n authRequiredResponse,\n tenantRequiredResponse,\n} from '../utils/helpers';\nimport { formatClientError } from '../../utils/errorFormatter';\n\n// Define schemas outside of tool registration to avoid deep type instantiation\nconst listAppsSchema = {\n organisation: z\n .string()\n .optional()\n .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),\n tenant: z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),\n details: z.boolean().optional().describe('Include full details for each app'),\n};\n\nconst getAppSchema = {\n organisation: z\n .string()\n .optional()\n .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),\n tenant: z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),\n appName: z.string().describe('Name of the app (can include spaces)'),\n};\n\nconst createAppSchema = {\n organisation: z\n .string()\n .optional()\n .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),\n tenant: z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),\n appName: z.string().describe('Name for the new app'),\n};\n\nexport const argumentSchema = z\n .object({\n name: z.string(),\n dataType: z.enum(['string', 'boolean']).optional().describe('Data type. Defaults to \"string\" if omitted.'),\n fixed: z\n .boolean()\n .optional()\n .describe('Lock the value at run time so users cannot override it (admin sets, user reads only).'),\n options: z\n .array(z.string())\n .optional()\n .describe('Closed allowed-value set. Only meaningful for string dataType.'),\n defaultValue: z.string().optional(),\n secret: z.boolean().optional().describe('Mask the value in inputs and logs.'),\n })\n // Cross-axis checks mirror the backend's `validateExpectedArguments` so an\n // LLM caller gets pre-request feedback. Backend stays authoritative \u2014 these\n // catch the same shapes earlier, they don't replace the validator.\n .refine(\n (a) => a.dataType !== 'boolean' || a.defaultValue === undefined || ['true', 'false'].includes(a.defaultValue),\n {\n message: 'Boolean argument defaultValue must be \"true\" or \"false\"',\n path: ['defaultValue'],\n },\n )\n .refine((a) => !a.options || a.defaultValue === undefined || a.options.includes(a.defaultValue), {\n message: 'defaultValue must be one of the options',\n path: ['defaultValue'],\n });\n\nconst configureAppSchema = {\n organisation: z\n .string()\n .optional()\n .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),\n tenant: z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),\n appName: z.string().describe('Name of the app to configure'),\n entrypoint: z\n .string()\n .optional()\n .describe('Main script filename \u2014 must be a file in the app\\'s source folder (e.g., \"index.ts\")'),\n sourceFolder: z\n .string()\n .optional()\n .describe('Source folder the app\\'s scripts come from (path under Files/, e.g. \"Scripts/MyApp\")'),\n description: z.string().optional().describe('App description'),\n arguments: z.array(argumentSchema).optional().describe('App arguments with default values'),\n newName: z.string().optional().describe('Rename the app'),\n};\n\nconst deleteAppSchema = {\n organisation: z\n .string()\n .optional()\n .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),\n tenant: z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),\n appName: z.string().describe('Name of the app to delete'),\n};\n\nexport function registerAppTools(server: McpServer): void {\n // Cast to avoid TS2589 deep type instantiation with MCP SDK + Zod generics\n const s: any = server;\n\n // farseer_list_apps - List all apps\n s.tool(\n 'farseer_list_apps',\n `List all apps (Remote Jobs) configured on a Farseer tenant.\n\nApps are executable script configurations that include:\n- Entry point script\n- List of included scripts\n- Expected arguments with default values\n\nUse details=true to include full information for each app.\n\nIf no tenant is specified, uses the currently checked-out tenant.`,\n listAppsSchema,\n async (params: { organisation?: string; tenant?: string; details?: boolean }) => {\n const resolved = resolveOrgAndTenant(params);\n if (!resolved) {\n return tenantRequiredResponse();\n }\n const { organisation, tenant } = resolved;\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n const appList = await clientResult.client.listApps();\n\n if (!params.details) {\n return successResponse({\n tenant,\n totalApps: appList.length,\n apps: appList.map((a) => ({\n name: a.name,\n id: a.id,\n reference: a.reference,\n })),\n });\n }\n\n // Get full details for each app\n const appsWithDetails = [];\n for (const item of appList) {\n const app = await clientResult.client.getApp(item.reference);\n if (app) {\n const appScripts = app.scriptFiles ?? [];\n const mainScript = appScripts.find((s) => s.id === app.mainScriptFileId);\n appsWithDetails.push({\n name: app.name,\n id: app.id,\n description: app.description || '',\n entrypoint: mainScript?.name || null,\n scripts: appScripts.map((s) => s.name),\n arguments: app.expectedArguments.map((a) => ({\n name: a.name,\n dataType: a.dataType,\n ...(a.fixed !== undefined ? { fixed: a.fixed } : {}),\n ...(a.options !== undefined ? { options: a.options } : {}),\n ...(a.defaultValue !== undefined ? { defaultValue: a.defaultValue } : {}),\n ...(a.secret !== undefined ? { secret: a.secret } : {}),\n })),\n });\n }\n }\n\n return successResponse({\n tenant,\n totalApps: appsWithDetails.length,\n apps: appsWithDetails,\n });\n } catch (error) {\n return errorResponse(`List apps failed: ${await formatClientError(error)}`, 'NETWORK_ERROR');\n }\n },\n );\n\n // farseer_get_app - Get app details\n s.tool(\n 'farseer_get_app',\n `Get detailed information about a specific Farseer app.\n\nReturns:\n- App name and description\n- Entry point script (main script that runs)\n- List of all included scripts\n- Expected arguments with their default values\n\nIf no tenant is specified, uses the currently checked-out tenant.`,\n getAppSchema,\n async (params: { organisation?: string; tenant?: string; appName: string }) => {\n const resolved = resolveOrgAndTenant(params);\n if (!resolved) {\n return tenantRequiredResponse();\n }\n const { organisation, tenant } = resolved;\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n const app = await clientResult.client.getAppByName(params.appName);\n\n if (!app) {\n return errorResponse(`App \"${params.appName}\" not found`, 'NOT_FOUND');\n }\n\n const getAppScripts = app.scriptFiles ?? [];\n const mainScript = getAppScripts.find((s) => s.id === app.mainScriptFileId);\n\n return successResponse({\n tenant,\n app: {\n id: app.id,\n name: app.name,\n description: app.description || '',\n entrypoint: mainScript?.name || null,\n scripts: getAppScripts.map((s) => ({\n id: s.id,\n name: s.name,\n isEntrypoint: s.id === app.mainScriptFileId,\n })),\n arguments: app.expectedArguments.map((a) => ({\n name: a.name,\n dataType: a.dataType,\n ...(a.fixed !== undefined ? { fixed: a.fixed } : {}),\n ...(a.options !== undefined ? { options: a.options } : {}),\n ...(a.defaultValue !== undefined ? { defaultValue: a.defaultValue } : {}),\n ...(a.secret !== undefined ? { secret: a.secret } : {}),\n })),\n status: app.status,\n lastHeartbeat: app.lastHeartbeat,\n },\n });\n } catch (error) {\n return errorResponse(`Get app failed: ${await formatClientError(error)}`, 'NETWORK_ERROR');\n }\n },\n );\n\n // farseer_create_app - Create new app\n s.tool(\n 'farseer_create_app',\n `Create a new Farseer app.\n\nA Farseer App is a named configuration that points to a TypeScript script and defines its arguments.\nThe script uses farseer-client to interact with the Farseer API (import data, export reports, etc.).\n\nWorkflow to create a new app:\n1. Write the script at farseer-apps/<tenant>/files/Scripts/<name>.ts\n2. Push the script to remote with farseer_push (scripts must exist on remote first)\n3. Create the app with this tool (farseer_create_app)\n4. Configure it with farseer_configure_app (set entrypoint, scripts, arguments)\n5. Run it with farseer_run_app (CLI injects auth credentials automatically)\n\nScripts should use \\`new FarseerClient()\\` with no arguments - credentials are injected via environment variables by the CLI at runtime.\n\nIf no tenant is specified, uses the currently checked-out tenant.`,\n createAppSchema,\n async (params: { organisation?: string; tenant?: string; appName: string }) => {\n const resolved = resolveOrgAndTenant(params);\n if (!resolved) {\n return tenantRequiredResponse();\n }\n const { organisation, tenant } = resolved;\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n // Check if app already exists\n const existing = await clientResult.client.getAppByName(params.appName);\n if (existing) {\n return errorResponse(`App \"${params.appName}\" already exists`, 'VALIDATION_ERROR');\n }\n\n const app = await clientResult.client.createApp(params.appName);\n\n return successResponse({\n tenant,\n app: {\n id: app.id,\n name: app.name,\n },\n message: `App \"${params.appName}\" created. Use farseer_configure_app to set entrypoint, scripts, and arguments.`,\n });\n } catch (error) {\n return errorResponse(`Create app failed: ${await formatClientError(error)}`, 'NETWORK_ERROR');\n }\n },\n );\n\n // farseer_configure_app - Configure app settings\n s.tool(\n 'farseer_configure_app',\n `Configure an existing Farseer app.\n\nYou can set:\n- sourceFolder: Folder under Files/ the app's scripts come from (e.g. \"Scripts/MyApp\")\n- entrypoint: Main script to execute \u2014 must be a file in the source folder (e.g., \"index.ts\")\n- description: App description\n- arguments: List of expected arguments. Each has a name, optional dataType\n ('string' | 'boolean' \u2014 defaults to 'string'), optional fixed (locks the\n value at run time), optional options (closed allowed-value set, string\n dataType only), optional defaultValue, and optional secret.\n- newName: Rename the app\n\nImportant:\n- The app's scripts are derived from its source folder; the entrypoint must be\n one of those files. To use a script from another folder, set sourceFolder first.\n- Changing sourceFolder to a folder that doesn't contain the current entrypoint\n requires passing entrypoint in the same call.\n- Settings you don't pass are preserved (this only changes what you specify).\n- Arguments are passed to the script as a JSON-encoded FARSEER_ARGS env var\n- Boolean dataType requires defaultValue \u2208 { \"true\", \"false\" }; defaultValue\n must be one of options when options is set\n\nIf no tenant is specified, uses the currently checked-out tenant.`,\n configureAppSchema,\n async (params: {\n organisation?: string;\n tenant?: string;\n appName: string;\n entrypoint?: string;\n sourceFolder?: string;\n description?: string;\n arguments?: Array<{\n name: string;\n dataType?: 'string' | 'boolean';\n fixed?: boolean;\n options?: string[];\n defaultValue?: string;\n secret?: boolean;\n }>;\n newName?: string;\n }) => {\n const resolved = resolveOrgAndTenant(params);\n if (!resolved) {\n return tenantRequiredResponse();\n }\n const { organisation, tenant } = resolved;\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n const app = await clientResult.client.getAppByName(params.appName);\n if (!app) {\n return errorResponse(`App \"${params.appName}\" not found`, 'NOT_FOUND');\n }\n\n // The set of changes. updateApp merges these onto the app's\n // current state, so anything left out here is preserved.\n const changes: AppUpdateChanges = {};\n\n if (params.newName) {\n changes.name = params.newName;\n }\n\n if (params.description !== undefined) {\n changes.description = params.description;\n }\n\n if (params.arguments) {\n // PUT semantics on the backend: this `expectedArguments`\n // array replaces the existing one wholesale. So if the\n // caller supplies a name but omits axes (dataType, fixed,\n // options, secret), we look up the existing arg by name\n // and carry those fields over. Without this merge, a\n // configure_app call that only re-sets defaultValue would\n // silently clear the secret flag or demote a dropdown\n // back to a plain string variable.\n //\n // Lookup is case-insensitive for convenience (caller\n // shouldn't have to remember exact casing to update an\n // existing arg), but on the write we keep the backend's\n // stored casing: validateExpectedArguments on the server\n // is case-sensitive (seen.has(arg.name)), so writing\n // back caller-supplied case would silently rename the\n // arg (e.g. jobName \u2192 JOBNAME) and break the next push.\n const existingByName = new Map(app.expectedArguments.map((e) => [e.name.toLowerCase(), e]));\n changes.expectedArguments = params.arguments.map((a) => {\n const existing = existingByName.get(a.name.toLowerCase());\n const arg: AppArgument = {\n name: existing?.name ?? a.name,\n dataType: a.dataType ?? existing?.dataType ?? 'string',\n };\n const fixed = a.fixed ?? existing?.fixed;\n if (fixed !== undefined) arg.fixed = fixed;\n const options = a.options ?? existing?.options;\n if (options !== undefined) arg.options = options;\n const defaultValue = a.defaultValue ?? existing?.defaultValue;\n if (defaultValue !== undefined) arg.defaultValue = defaultValue;\n const secret = a.secret ?? existing?.secret;\n if (secret !== undefined) arg.secret = secret;\n return arg;\n });\n }\n\n // Source folder + entrypoint. An app's scripts derive from its\n // source folder, and the entrypoint must be one of those files.\n // The decision lives in applySourceFolderChange (shared with the\n // CLI `app configure` command); the 'mcp' caller gets a plain,\n // param-worded error string.\n const sourceFolderError = await applySourceFolderChange(\n clientResult.client,\n app,\n changes,\n { sourceFolder: params.sourceFolder, entrypoint: params.entrypoint },\n 'mcp',\n );\n if (sourceFolderError) {\n return errorResponse(sourceFolderError, 'VALIDATION_ERROR');\n }\n\n const reference = app.id.toString();\n await clientResult.client.updateApp(reference, changes, app);\n\n return successResponse({\n tenant,\n appName: params.newName || params.appName,\n updated: Object.keys(changes),\n message: `App \"${params.appName}\" configured successfully`,\n });\n } catch (error) {\n return errorResponse(`Configure app failed: ${await formatClientError(error)}`, 'NETWORK_ERROR');\n }\n },\n );\n\n // farseer_delete_app - Delete app\n s.tool(\n 'farseer_delete_app',\n `Delete an app from a Farseer tenant.\n\nWARNING: This is irreversible - the app will be permanently removed from the remote instance.\n\nThis does NOT delete the script files, only the app configuration.\n\nIf no tenant is specified, uses the currently checked-out tenant.`,\n deleteAppSchema,\n async (params: { organisation?: string; tenant?: string; appName: string }) => {\n const resolved = resolveOrgAndTenant(params);\n if (!resolved) {\n return tenantRequiredResponse();\n }\n const { organisation, tenant } = resolved;\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n // Find the app in the folder listing to get the folder item_node ID\n // (getAppByName returns remoteJob ID which differs from folder item ID)\n const allApps = await clientResult.client.listApps();\n const appItem = allApps.find((a) => a.name.toLowerCase() === params.appName.toLowerCase());\n if (!appItem) {\n return errorResponse(`App \"${params.appName}\" not found`, 'NOT_FOUND');\n }\n\n await clientResult.client.deleteApp(appItem.id);\n\n // The folder API 200s even when nothing was deleted; confirm.\n const remaining = await clientResult.client.listApps();\n if (remaining.some((a) => a.id === appItem.id)) {\n return errorResponse(\n `Delete reported success but \"${params.appName}\" is still present`,\n 'NETWORK_ERROR',\n );\n }\n\n return successResponse({\n tenant,\n deletedApp: params.appName,\n message: `App \"${params.appName}\" has been deleted`,\n });\n } catch (error) {\n return errorResponse(`Delete app failed: ${await formatClientError(error)}`, 'NETWORK_ERROR');\n }\n },\n );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iBAAkB;AAClB,4BAA6C;AAC7C,wBAAuE;AACvE,qBAMO;AACP,4BAAkC;AAGlC,MAAM,iBAAiB;AAAA,EACnB,
|
|
4
|
+
"sourcesContent": ["/**\n * App Management Tools\n *\n * Tools for managing Farseer apps (Remote Jobs).\n */\n\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport { getFarseerClientWithFallback } from '../../services/farseerFactory';\nimport { AppArgument, AppUpdateChanges, applySourceFolderChange } from '../../services/farseerApi';\nimport {\n getSessionTenant,\n successResponse,\n errorResponse,\n authRequiredResponse,\n tenantRequiredResponse,\n} from '../utils/helpers';\nimport { formatClientError } from '../../utils/errorFormatter';\n\n// Define schemas outside of tool registration to avoid deep type instantiation\nconst listAppsSchema = {\n details: z.boolean().optional().describe('Include full details for each app'),\n};\n\nconst getAppSchema = {\n appName: z.string().describe('Name of the app (can include spaces)'),\n};\n\nconst createAppSchema = {\n appName: z.string().describe('Name for the new app'),\n};\n\nexport const argumentSchema = z\n .object({\n name: z.string(),\n dataType: z.enum(['string', 'boolean']).optional().describe('Data type. Defaults to \"string\" if omitted.'),\n fixed: z\n .boolean()\n .optional()\n .describe('Lock the value at run time so users cannot override it (admin sets, user reads only).'),\n options: z\n .array(z.string())\n .optional()\n .describe('Closed allowed-value set. Only meaningful for string dataType.'),\n defaultValue: z.string().optional(),\n secret: z.boolean().optional().describe('Mask the value in inputs and logs.'),\n })\n // Cross-axis checks mirror the backend's `validateExpectedArguments` so an\n // LLM caller gets pre-request feedback. Backend stays authoritative \u2014 these\n // catch the same shapes earlier, they don't replace the validator.\n .refine(\n (a) => a.dataType !== 'boolean' || a.defaultValue === undefined || ['true', 'false'].includes(a.defaultValue),\n {\n message: 'Boolean argument defaultValue must be \"true\" or \"false\"',\n path: ['defaultValue'],\n },\n )\n .refine((a) => !a.options || a.defaultValue === undefined || a.options.includes(a.defaultValue), {\n message: 'defaultValue must be one of the options',\n path: ['defaultValue'],\n });\n\nconst configureAppSchema = {\n appName: z.string().describe('Name of the app to configure'),\n entrypoint: z\n .string()\n .optional()\n .describe('Main script filename \u2014 must be a file in the app\\'s source folder (e.g., \"index.ts\")'),\n sourceFolder: z\n .string()\n .optional()\n .describe('Source folder the app\\'s scripts come from (path under Files/, e.g. \"Scripts/MyApp\")'),\n description: z.string().optional().describe('App description'),\n arguments: z.array(argumentSchema).optional().describe('App arguments with default values'),\n newName: z.string().optional().describe('Rename the app'),\n};\n\nconst deleteAppSchema = {\n appName: z.string().describe('Name of the app to delete'),\n};\n\nexport function registerAppTools(server: McpServer): void {\n // Cast to avoid TS2589 deep type instantiation with MCP SDK + Zod generics\n const s: any = server;\n\n // farseer_list_apps - List all apps\n s.tool(\n 'farseer_list_apps',\n `List all apps (Remote Jobs) configured on a Farseer tenant.\n\nApps are executable script configurations that include:\n- Entry point script\n- List of included scripts\n- Expected arguments with default values\n\nUse details=true to include full information for each app.`,\n listAppsSchema,\n async (params: { details?: boolean }) => {\n const resolved = getSessionTenant();\n if (!resolved) {\n return tenantRequiredResponse();\n }\n const { organisation, tenant } = resolved;\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n const appList = await clientResult.client.listApps();\n\n if (!params.details) {\n return successResponse({\n tenant,\n totalApps: appList.length,\n apps: appList.map((a) => ({\n name: a.name,\n id: a.id,\n reference: a.reference,\n })),\n });\n }\n\n // Get full details for each app\n const appsWithDetails = [];\n for (const item of appList) {\n const app = await clientResult.client.getApp(item.reference);\n if (app) {\n const appScripts = app.scriptFiles ?? [];\n const mainScript = appScripts.find((s) => s.id === app.mainScriptFileId);\n appsWithDetails.push({\n name: app.name,\n id: app.id,\n description: app.description || '',\n entrypoint: mainScript?.name || null,\n scripts: appScripts.map((s) => s.name),\n arguments: app.expectedArguments.map((a) => ({\n name: a.name,\n dataType: a.dataType,\n ...(a.fixed !== undefined ? { fixed: a.fixed } : {}),\n ...(a.options !== undefined ? { options: a.options } : {}),\n ...(a.defaultValue !== undefined ? { defaultValue: a.defaultValue } : {}),\n ...(a.secret !== undefined ? { secret: a.secret } : {}),\n })),\n });\n }\n }\n\n return successResponse({\n tenant,\n totalApps: appsWithDetails.length,\n apps: appsWithDetails,\n });\n } catch (error) {\n return errorResponse(`List apps failed: ${await formatClientError(error)}`, 'NETWORK_ERROR');\n }\n },\n );\n\n // farseer_get_app - Get app details\n s.tool(\n 'farseer_get_app',\n `Get detailed information about a specific Farseer app.\n\nReturns:\n- App name and description\n- Entry point script (main script that runs)\n- List of all included scripts\n- Expected arguments with their default values`,\n getAppSchema,\n async (params: { appName: string }) => {\n const resolved = getSessionTenant();\n if (!resolved) {\n return tenantRequiredResponse();\n }\n const { organisation, tenant } = resolved;\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n const app = await clientResult.client.getAppByName(params.appName);\n\n if (!app) {\n return errorResponse(`App \"${params.appName}\" not found`, 'NOT_FOUND');\n }\n\n const getAppScripts = app.scriptFiles ?? [];\n const mainScript = getAppScripts.find((s) => s.id === app.mainScriptFileId);\n\n return successResponse({\n tenant,\n app: {\n id: app.id,\n name: app.name,\n description: app.description || '',\n entrypoint: mainScript?.name || null,\n scripts: getAppScripts.map((s) => ({\n id: s.id,\n name: s.name,\n isEntrypoint: s.id === app.mainScriptFileId,\n })),\n arguments: app.expectedArguments.map((a) => ({\n name: a.name,\n dataType: a.dataType,\n ...(a.fixed !== undefined ? { fixed: a.fixed } : {}),\n ...(a.options !== undefined ? { options: a.options } : {}),\n ...(a.defaultValue !== undefined ? { defaultValue: a.defaultValue } : {}),\n ...(a.secret !== undefined ? { secret: a.secret } : {}),\n })),\n status: app.status,\n lastHeartbeat: app.lastHeartbeat,\n },\n });\n } catch (error) {\n return errorResponse(`Get app failed: ${await formatClientError(error)}`, 'NETWORK_ERROR');\n }\n },\n );\n\n // farseer_create_app - Create new app\n s.tool(\n 'farseer_create_app',\n `Create a new Farseer app.\n\nA Farseer App is a named configuration that points to a TypeScript script and defines its arguments.\nThe script uses farseer-client to interact with the Farseer API (import data, export reports, etc.).\n\nWorkflow to create a new app:\n1. Write the script at farseer-apps/<tenant>/files/Scripts/<name>.ts\n2. Push the script to remote with farseer_push (scripts must exist on remote first)\n3. Create the app with this tool (farseer_create_app)\n4. Configure it with farseer_configure_app (set entrypoint, scripts, arguments)\n5. Run it with farseer_run_app (CLI injects auth credentials automatically)\n\nScripts should use \\`new FarseerClient()\\` with no arguments - credentials are injected via environment variables by the CLI at runtime.`,\n createAppSchema,\n async (params: { appName: string }) => {\n const resolved = getSessionTenant();\n if (!resolved) {\n return tenantRequiredResponse();\n }\n const { organisation, tenant } = resolved;\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n // Check if app already exists\n const existing = await clientResult.client.getAppByName(params.appName);\n if (existing) {\n return errorResponse(`App \"${params.appName}\" already exists`, 'VALIDATION_ERROR');\n }\n\n const app = await clientResult.client.createApp(params.appName);\n\n return successResponse({\n tenant,\n app: {\n id: app.id,\n name: app.name,\n },\n message: `App \"${params.appName}\" created. Use farseer_configure_app to set entrypoint, scripts, and arguments.`,\n });\n } catch (error) {\n return errorResponse(`Create app failed: ${await formatClientError(error)}`, 'NETWORK_ERROR');\n }\n },\n );\n\n // farseer_configure_app - Configure app settings\n s.tool(\n 'farseer_configure_app',\n `Configure an existing Farseer app.\n\nYou can set:\n- sourceFolder: Folder under Files/ the app's scripts come from (e.g. \"Scripts/MyApp\")\n- entrypoint: Main script to execute \u2014 must be a file in the source folder (e.g., \"index.ts\")\n- description: App description\n- arguments: List of expected arguments. Each has a name, optional dataType\n ('string' | 'boolean' \u2014 defaults to 'string'), optional fixed (locks the\n value at run time), optional options (closed allowed-value set, string\n dataType only), optional defaultValue, and optional secret.\n- newName: Rename the app\n\nImportant:\n- The app's scripts are derived from its source folder; the entrypoint must be\n one of those files. To use a script from another folder, set sourceFolder first.\n- Changing sourceFolder to a folder that doesn't contain the current entrypoint\n requires passing entrypoint in the same call.\n- Settings you don't pass are preserved (this only changes what you specify).\n- Arguments are passed to the script as a JSON-encoded FARSEER_ARGS env var\n- Boolean dataType requires defaultValue \u2208 { \"true\", \"false\" }; defaultValue\n must be one of options when options is set`,\n configureAppSchema,\n async (params: {\n appName: string;\n entrypoint?: string;\n sourceFolder?: string;\n description?: string;\n arguments?: Array<{\n name: string;\n dataType?: 'string' | 'boolean';\n fixed?: boolean;\n options?: string[];\n defaultValue?: string;\n secret?: boolean;\n }>;\n newName?: string;\n }) => {\n const resolved = getSessionTenant();\n if (!resolved) {\n return tenantRequiredResponse();\n }\n const { organisation, tenant } = resolved;\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n const app = await clientResult.client.getAppByName(params.appName);\n if (!app) {\n return errorResponse(`App \"${params.appName}\" not found`, 'NOT_FOUND');\n }\n\n // The set of changes. updateApp merges these onto the app's\n // current state, so anything left out here is preserved.\n const changes: AppUpdateChanges = {};\n\n if (params.newName) {\n changes.name = params.newName;\n }\n\n if (params.description !== undefined) {\n changes.description = params.description;\n }\n\n if (params.arguments) {\n // PUT semantics on the backend: this `expectedArguments`\n // array replaces the existing one wholesale. So if the\n // caller supplies a name but omits axes (dataType, fixed,\n // options, secret), we look up the existing arg by name\n // and carry those fields over. Without this merge, a\n // configure_app call that only re-sets defaultValue would\n // silently clear the secret flag or demote a dropdown\n // back to a plain string variable.\n //\n // Lookup is case-insensitive for convenience (caller\n // shouldn't have to remember exact casing to update an\n // existing arg), but on the write we keep the backend's\n // stored casing: validateExpectedArguments on the server\n // is case-sensitive (seen.has(arg.name)), so writing\n // back caller-supplied case would silently rename the\n // arg (e.g. jobName \u2192 JOBNAME) and break the next push.\n const existingByName = new Map(app.expectedArguments.map((e) => [e.name.toLowerCase(), e]));\n changes.expectedArguments = params.arguments.map((a) => {\n const existing = existingByName.get(a.name.toLowerCase());\n const arg: AppArgument = {\n name: existing?.name ?? a.name,\n dataType: a.dataType ?? existing?.dataType ?? 'string',\n };\n const fixed = a.fixed ?? existing?.fixed;\n if (fixed !== undefined) arg.fixed = fixed;\n const options = a.options ?? existing?.options;\n if (options !== undefined) arg.options = options;\n const defaultValue = a.defaultValue ?? existing?.defaultValue;\n if (defaultValue !== undefined) arg.defaultValue = defaultValue;\n const secret = a.secret ?? existing?.secret;\n if (secret !== undefined) arg.secret = secret;\n return arg;\n });\n }\n\n // Source folder + entrypoint. An app's scripts derive from its\n // source folder, and the entrypoint must be one of those files.\n // The decision lives in applySourceFolderChange (shared with the\n // CLI `app configure` command); the 'mcp' caller gets a plain,\n // param-worded error string.\n const sourceFolderError = await applySourceFolderChange(\n clientResult.client,\n app,\n changes,\n { sourceFolder: params.sourceFolder, entrypoint: params.entrypoint },\n 'mcp',\n );\n if (sourceFolderError) {\n return errorResponse(sourceFolderError, 'VALIDATION_ERROR');\n }\n\n const reference = app.id.toString();\n await clientResult.client.updateApp(reference, changes, app);\n\n return successResponse({\n tenant,\n appName: params.newName || params.appName,\n updated: Object.keys(changes),\n message: `App \"${params.appName}\" configured successfully`,\n });\n } catch (error) {\n return errorResponse(`Configure app failed: ${await formatClientError(error)}`, 'NETWORK_ERROR');\n }\n },\n );\n\n // farseer_delete_app - Delete app\n s.tool(\n 'farseer_delete_app',\n `Delete an app from a Farseer tenant.\n\nWARNING: This is irreversible - the app will be permanently removed from the remote instance.\n\nThis does NOT delete the script files, only the app configuration.`,\n deleteAppSchema,\n async (params: { appName: string }) => {\n const resolved = getSessionTenant();\n if (!resolved) {\n return tenantRequiredResponse();\n }\n const { organisation, tenant } = resolved;\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n // Find the app in the folder listing to get the folder item_node ID\n // (getAppByName returns remoteJob ID which differs from folder item ID)\n const allApps = await clientResult.client.listApps();\n const appItem = allApps.find((a) => a.name.toLowerCase() === params.appName.toLowerCase());\n if (!appItem) {\n return errorResponse(`App \"${params.appName}\" not found`, 'NOT_FOUND');\n }\n\n await clientResult.client.deleteApp(appItem.id);\n\n // The folder API 200s even when nothing was deleted; confirm.\n const remaining = await clientResult.client.listApps();\n if (remaining.some((a) => a.id === appItem.id)) {\n return errorResponse(\n `Delete reported success but \"${params.appName}\" is still present`,\n 'NETWORK_ERROR',\n );\n }\n\n return successResponse({\n tenant,\n deletedApp: params.appName,\n message: `App \"${params.appName}\" has been deleted`,\n });\n } catch (error) {\n return errorResponse(`Delete app failed: ${await formatClientError(error)}`, 'NETWORK_ERROR');\n }\n },\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iBAAkB;AAClB,4BAA6C;AAC7C,wBAAuE;AACvE,qBAMO;AACP,4BAAkC;AAGlC,MAAM,iBAAiB;AAAA,EACnB,SAAS,aAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,mCAAmC;AAChF;AAEA,MAAM,eAAe;AAAA,EACjB,SAAS,aAAE,OAAO,EAAE,SAAS,sCAAsC;AACvE;AAEA,MAAM,kBAAkB;AAAA,EACpB,SAAS,aAAE,OAAO,EAAE,SAAS,sBAAsB;AACvD;AAEO,MAAM,iBAAiB,aACzB,OAAO;AAAA,EACJ,MAAM,aAAE,OAAO;AAAA,EACf,UAAU,aAAE,KAAK,CAAC,UAAU,SAAS,CAAC,EAAE,SAAS,EAAE,SAAS,6CAA6C;AAAA,EACzG,OAAO,aACF,QAAQ,EACR,SAAS,EACT,SAAS,uFAAuF;AAAA,EACrG,SAAS,aACJ,MAAM,aAAE,OAAO,CAAC,EAChB,SA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,cAAc,MAAM;AAC5E,UAAI,CAAC,cAAc;AACf,mBAAO,qCAAqB,MAAM;AAAA,MACtC;AAEA,UAAI;AAGA,cAAM,UAAU,MAAM,aAAa,OAAO,SAAS;AACnD,cAAM,UAAU,QAAQ,KAAK,CAAC,MAAM,EAAE,KAAK,YAAY,MAAM,OAAO,QAAQ,YAAY,CAAC;AACzF,YAAI,CAAC,SAAS;AACV,qBAAO,8BAAc,QAAQ,OAAO,OAAO,eAAe,WAAW;AAAA,QACzE;AAEA,cAAM,aAAa,OAAO,UAAU,QAAQ,EAAE;AAG9C,cAAM,YAAY,MAAM,aAAa,OAAO,SAAS;AACrD,YAAI,UAAU,KAAK,CAAC,MAAM,EAAE,OAAO,QAAQ,EAAE,GAAG;AAC5C,qBAAO;AAAA,YACH,gCAAgC,OAAO,OAAO;AAAA,YAC9C;AAAA,UACJ;AAAA,QACJ;AAEA,mBAAO,gCAAgB;AAAA,UACnB;AAAA,UACA,YAAY,OAAO;AAAA,UACnB,SAAS,QAAQ,OAAO,OAAO;AAAA,QACnC,CAAC;AAAA,MACL,SAAS,OAAO;AACZ,mBAAO,8BAAc,sBAAsB,UAAM,yCAAkB,KAAK,CAAC,IAAI,eAAe;AAAA,MAChG;AAAA,IACJ;AAAA,EACJ;AACJ;",
|
|
6
6
|
"names": ["s"]
|
|
7
7
|
}
|
|
@@ -24,133 +24,83 @@ module.exports = __toCommonJS(authTools_exports);
|
|
|
24
24
|
var import_zod = require("zod");
|
|
25
25
|
var import_configService = require("../../services/configService");
|
|
26
26
|
var import_farseerFactory = require("../../services/farseerFactory");
|
|
27
|
-
var import_syncService = require("../../services/syncService");
|
|
28
|
-
var import_appSyncService = require("../../services/appSyncService");
|
|
29
27
|
var import_helpers = require("../utils/helpers");
|
|
30
|
-
var
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
skipPull: import_zod.z.boolean().optional().describe("Skip automatic pull after checkout (default: false)")
|
|
28
|
+
var import_tenantPin = require("../utils/tenantPin");
|
|
29
|
+
const selectTenantSchema = {
|
|
30
|
+
tenant: import_zod.z.string().describe(`Tenant to bind this session to (e.g. "salvus-prodaja"), from the user's request.`),
|
|
31
|
+
organisation: import_zod.z.string().optional().describe("Organisation subdomain. Defaults to the saved mapping for the tenant, else the tenant name.")
|
|
35
32
|
};
|
|
36
33
|
function registerAuthTools(server) {
|
|
37
34
|
server.tool(
|
|
38
35
|
"farseer_whoami",
|
|
39
|
-
`Check Farseer authentication status.
|
|
36
|
+
`Check Farseer authentication status and the tenant this session is bound to.
|
|
40
37
|
|
|
41
|
-
Returns
|
|
42
|
-
- Whether a JWT
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
- List of tenants with API keys configured
|
|
38
|
+
Returns:
|
|
39
|
+
- Whether a JWT (browser login) is valid and when it expires
|
|
40
|
+
- The tenant this session operates on, and whether it is locked
|
|
41
|
+
- Tenants with API keys configured
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
If not authenticated, run "farseer login" in terminal.`,
|
|
43
|
+
If not authenticated, run "farseer login" in a terminal.`,
|
|
49
44
|
{},
|
|
50
45
|
async () => {
|
|
51
46
|
const status = (0, import_helpers.getAuthStatus)();
|
|
47
|
+
const pin = status.tenant;
|
|
48
|
+
const message = !pin ? "No tenant selected yet. Tell me which tenant/client to work on and I will call farseer_select_tenant to connect (once per session)." : status.launchPinned ? `This session is locked to tenant "${pin.tenant}" (org: ${pin.organisation}), fixed at launch.` : `This session is working on tenant "${pin.tenant}" (org: ${pin.organisation}), selected and locked for the session.`;
|
|
52
49
|
return (0, import_helpers.successResponse)({
|
|
53
50
|
jwtValid: status.jwtValid,
|
|
54
51
|
jwtExpiresAt: status.jwtExpiresAt,
|
|
55
|
-
|
|
52
|
+
tenant: pin,
|
|
53
|
+
tenantLocked: !!pin,
|
|
56
54
|
configuredTenants: status.configuredTenants,
|
|
57
|
-
message
|
|
55
|
+
message
|
|
58
56
|
});
|
|
59
57
|
}
|
|
60
58
|
);
|
|
61
59
|
server.tool(
|
|
62
|
-
"
|
|
63
|
-
`
|
|
60
|
+
"farseer_select_tenant",
|
|
61
|
+
`Bind this MCP session to a Farseer tenant. Call this once when the user says which tenant/client to work on.
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
63
|
+
Rules:
|
|
64
|
+
- Works only if the server was launched without --tenant. If it was launched with --tenant, it is already locked and this returns an error.
|
|
65
|
+
- Can be called only ONCE. After the first selection the tenant is locked for the session and cannot be changed. To work on a different tenant, start a new session.
|
|
66
|
+
- The tenant must be reachable (you must be logged in). If it can't be connected \u2014 wrong name or not logged in \u2014 selection fails WITHOUT locking, so you can correct it and call again.
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
- Tenant: workspace ID sent as X-TENANT-ID header
|
|
73
|
-
|
|
74
|
-
Often org and tenant are the same (e.g., "tthotels"), but they can differ
|
|
75
|
-
(e.g., org="fs-personal", tenant="john-doe").
|
|
76
|
-
|
|
77
|
-
If you only provide tenant without organisation, it assumes org=tenant.`,
|
|
78
|
-
checkoutSchema,
|
|
68
|
+
Use this before any other farseer tool when no tenant is set yet (farseer_whoami tells you).`,
|
|
69
|
+
selectTenantSchema,
|
|
79
70
|
// @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
|
|
80
71
|
async (params) => {
|
|
81
|
-
const {
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
message: `Currently checked out: ${current.tenant} (org: ${current.organisation})`
|
|
88
|
-
});
|
|
89
|
-
} else {
|
|
90
|
-
return (0, import_helpers.successResponse)({
|
|
91
|
-
currentCheckout: null,
|
|
92
|
-
message: "No tenant currently checked out. Use tenant parameter to checkout."
|
|
93
|
-
});
|
|
94
|
-
}
|
|
72
|
+
const { tenant, organisation } = params;
|
|
73
|
+
if ((0, import_tenantPin.isLaunchPinned)()) {
|
|
74
|
+
return (0, import_helpers.errorResponse)(
|
|
75
|
+
`This server is pinned to tenant "${(0, import_tenantPin.getTenantPin)().tenant}" via --tenant; the tenant cannot be changed from here.`,
|
|
76
|
+
"VALIDATION_ERROR"
|
|
77
|
+
);
|
|
95
78
|
}
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
79
|
+
const bound = (0, import_tenantPin.getTenantPin)();
|
|
80
|
+
if (bound) {
|
|
81
|
+
return (0, import_helpers.errorResponse)(
|
|
82
|
+
`This session is already working on tenant "${bound.tenant}" and the tenant cannot be changed. Start a new session to use a different tenant.`,
|
|
83
|
+
"VALIDATION_ERROR"
|
|
84
|
+
);
|
|
100
85
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
(0,
|
|
86
|
+
const org = organisation || (0, import_configService.getTenantOrg)(tenant) || tenant;
|
|
87
|
+
const client = await (0, import_farseerFactory.getFarseerClientWithFallback)(org, tenant);
|
|
88
|
+
if (!client) {
|
|
89
|
+
return (0, import_helpers.errorResponse)(
|
|
90
|
+
`Could not connect to tenant "${tenant}" (org: "${org}"). Check the tenant name and that you're logged in ("farseer login"), then call farseer_select_tenant again.`,
|
|
91
|
+
"AUTH_REQUIRED"
|
|
92
|
+
);
|
|
105
93
|
}
|
|
106
|
-
(0,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
pullResult = await syncService.pull();
|
|
113
|
-
if (clientResult.authType === "jwt") {
|
|
114
|
-
const appSyncService = new import_appSyncService.AppSyncService(tenant, clientResult.client);
|
|
115
|
-
appPullResult = await appSyncService.pull();
|
|
116
|
-
}
|
|
117
|
-
} catch (error) {
|
|
118
|
-
return (0, import_helpers.successResponse)({
|
|
119
|
-
currentCheckout: { organisation: org, tenant },
|
|
120
|
-
message: `Checked out ${tenant}, but pull failed: ${await (0, import_errorFormatter.formatClientError)(error)}`,
|
|
121
|
-
pullError: true
|
|
122
|
-
});
|
|
123
|
-
}
|
|
94
|
+
const result = (0, import_tenantPin.selectTenant)({ organisation: org, tenant });
|
|
95
|
+
if (!result.ok) {
|
|
96
|
+
return (0, import_helpers.errorResponse)(
|
|
97
|
+
`This session is already working on tenant "${result.current.tenant}" and the tenant cannot be changed. Start a new session to use a different tenant.`,
|
|
98
|
+
"VALIDATION_ERROR"
|
|
99
|
+
);
|
|
124
100
|
}
|
|
125
101
|
return (0, import_helpers.successResponse)({
|
|
126
|
-
|
|
127
|
-
message: `
|
|
128
|
-
files: pullResult ? {
|
|
129
|
-
downloaded: pullResult.downloaded,
|
|
130
|
-
deleted: pullResult.deleted,
|
|
131
|
-
unchanged: pullResult.unchanged.length
|
|
132
|
-
} : void 0,
|
|
133
|
-
apps: appPullResult ? {
|
|
134
|
-
created: appPullResult.created,
|
|
135
|
-
updated: appPullResult.updated,
|
|
136
|
-
deleted: appPullResult.deleted,
|
|
137
|
-
unchanged: appPullResult.unchanged.length
|
|
138
|
-
} : void 0
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
server.tool(
|
|
143
|
-
"farseer_checkout_clear",
|
|
144
|
-
`Clear the current tenant checkout.
|
|
145
|
-
|
|
146
|
-
After clearing, you'll need to specify tenant explicitly for all commands.`,
|
|
147
|
-
{},
|
|
148
|
-
async () => {
|
|
149
|
-
const current = (0, import_configService.getCurrentCheckout)();
|
|
150
|
-
(0, import_configService.clearCurrentTenant)();
|
|
151
|
-
return (0, import_helpers.successResponse)({
|
|
152
|
-
previousCheckout: current,
|
|
153
|
-
message: current ? `Cleared checkout for ${current.tenant}` : "No tenant was checked out"
|
|
102
|
+
tenant: result.checkout,
|
|
103
|
+
message: `Selected tenant "${result.checkout.tenant}" (org: ${result.checkout.organisation}). This session is now locked to it for its lifetime.`
|
|
154
104
|
});
|
|
155
105
|
}
|
|
156
106
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/mcp/tools/authTools.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Authentication
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * Authentication + tenant-binding tools.\n *\n * A server operates on one tenant per session. It is bound either at launch\n * (`mcp-server --tenant`) or once at runtime via `farseer_select_tenant`, then\n * locked. Binding never touches `~/.farseer/config.json` \u2014 it is in-memory and\n * per-process, so concurrent sessions can hold different tenants without\n * colliding.\n */\n\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport { getTenantOrg } from '../../services/configService';\nimport { getFarseerClientWithFallback } from '../../services/farseerFactory';\nimport { getAuthStatus, successResponse, errorResponse } from '../utils/helpers';\nimport { selectTenant, getTenantPin, isLaunchPinned } from '../utils/tenantPin';\n\n// Defined outside registration to avoid deep zod type instantiation.\nconst selectTenantSchema = {\n tenant: z.string().describe('Tenant to bind this session to (e.g. \"salvus-prodaja\"), from the user\\'s request.'),\n organisation: z\n .string()\n .optional()\n .describe('Organisation subdomain. Defaults to the saved mapping for the tenant, else the tenant name.'),\n};\n\nexport function registerAuthTools(server: McpServer): void {\n // farseer_whoami - Auth status + the tenant this session is bound to\n server.tool(\n 'farseer_whoami',\n `Check Farseer authentication status and the tenant this session is bound to.\n\nReturns:\n- Whether a JWT (browser login) is valid and when it expires\n- The tenant this session operates on, and whether it is locked\n- Tenants with API keys configured\n\nIf not authenticated, run \"farseer login\" in a terminal.`,\n {},\n async () => {\n const status = getAuthStatus();\n const pin = status.tenant;\n const message = !pin\n ? 'No tenant selected yet. Tell me which tenant/client to work on and I will call farseer_select_tenant to connect (once per session).'\n : status.launchPinned\n ? `This session is locked to tenant \"${pin.tenant}\" (org: ${pin.organisation}), fixed at launch.`\n : `This session is working on tenant \"${pin.tenant}\" (org: ${pin.organisation}), selected and locked for the session.`;\n return successResponse({\n jwtValid: status.jwtValid,\n jwtExpiresAt: status.jwtExpiresAt,\n tenant: pin,\n tenantLocked: !!pin,\n configuredTenants: status.configuredTenants,\n message,\n });\n },\n );\n\n // farseer_select_tenant - Bind this session to a tenant, once\n server.tool(\n 'farseer_select_tenant',\n `Bind this MCP session to a Farseer tenant. Call this once when the user says which tenant/client to work on.\n\nRules:\n- Works only if the server was launched without --tenant. If it was launched with --tenant, it is already locked and this returns an error.\n- Can be called only ONCE. After the first selection the tenant is locked for the session and cannot be changed. To work on a different tenant, start a new session.\n- The tenant must be reachable (you must be logged in). If it can't be connected \u2014 wrong name or not logged in \u2014 selection fails WITHOUT locking, so you can correct it and call again.\n\nUse this before any other farseer tool when no tenant is set yet (farseer_whoami tells you).`,\n selectTenantSchema,\n // @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas\n async (params: { tenant: string; organisation?: string }) => {\n const { tenant, organisation } = params;\n\n // A locked session can't change tenant. Reject before any network\n // call, and don't verify a tenant we won't bind to.\n if (isLaunchPinned()) {\n return errorResponse(\n `This server is pinned to tenant \"${getTenantPin()!.tenant}\" via --tenant; the tenant cannot be changed from here.`,\n 'VALIDATION_ERROR',\n );\n }\n const bound = getTenantPin();\n if (bound) {\n return errorResponse(\n `This session is already working on tenant \"${bound.tenant}\" and the tenant cannot be changed. Start a new session to use a different tenant.`,\n 'VALIDATION_ERROR',\n );\n }\n\n const org = organisation || getTenantOrg(tenant) || tenant;\n\n // Verify the tenant is reachable BEFORE locking. Selection is\n // one-shot, so without this a typo'd or unauthenticated tenant would\n // pin the session to a dead tenant for its whole lifetime, fixable\n // only by restarting the server.\n const client = await getFarseerClientWithFallback(org, tenant);\n if (!client) {\n return errorResponse(\n `Could not connect to tenant \"${tenant}\" (org: \"${org}\"). Check the tenant name and that you're logged in (\"farseer login\"), then call farseer_select_tenant again.`,\n 'AUTH_REQUIRED',\n );\n }\n\n const result = selectTenant({ organisation: org, tenant });\n if (!result.ok) {\n // Lost a race to a concurrent selection between the check above\n // and here \u2014 treat as already-bound.\n return errorResponse(\n `This session is already working on tenant \"${result.current.tenant}\" and the tenant cannot be changed. Start a new session to use a different tenant.`,\n 'VALIDATION_ERROR',\n );\n }\n return successResponse({\n tenant: result.checkout,\n message: `Selected tenant \"${result.checkout.tenant}\" (org: ${result.checkout.organisation}). This session is now locked to it for its lifetime.`,\n });\n },\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,iBAAkB;AAClB,2BAA6B;AAC7B,4BAA6C;AAC7C,qBAA8D;AAC9D,uBAA2D;AAG3D,MAAM,qBAAqB;AAAA,EACvB,QAAQ,aAAE,OAAO,EAAE,SAAS,kFAAmF;AAAA,EAC/G,cAAc,aACT,OAAO,EACP,SAAS,EACT,SAAS,6FAA6F;AAC/G;AAEO,SAAS,kBAAkB,QAAyB;AAEvD,SAAO;AAAA,IACH;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQA,CAAC;AAAA,IACD,YAAY;AACR,YAAM,aAAS,8BAAc;AAC7B,YAAM,MAAM,OAAO;AACnB,YAAM,UAAU,CAAC,MACX,wIACA,OAAO,eACL,qCAAqC,IAAI,MAAM,WAAW,IAAI,YAAY,wBAC1E,sCAAsC,IAAI,MAAM,WAAW,IAAI,YAAY;AACnF,iBAAO,gCAAgB;AAAA,QACnB,UAAU,OAAO;AAAA,QACjB,cAAc,OAAO;AAAA,QACrB,QAAQ;AAAA,QACR,cAAc,CAAC,CAAC;AAAA,QAChB,mBAAmB,OAAO;AAAA,QAC1B;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ;AAGA,SAAO;AAAA,IACH;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQA;AAAA;AAAA,IAEA,OAAO,WAAsD;AACzD,YAAM,EAAE,QAAQ,aAAa,IAAI;AAIjC,cAAI,iCAAe,GAAG;AAClB,mBAAO;AAAA,UACH,wCAAoC,+BAAa,EAAG,MAAM;AAAA,UAC1D;AAAA,QACJ;AAAA,MACJ;AACA,YAAM,YAAQ,+BAAa;AAC3B,UAAI,OAAO;AACP,mBAAO;AAAA,UACH,8CAA8C,MAAM,MAAM;AAAA,UAC1D;AAAA,QACJ;AAAA,MACJ;AAEA,YAAM,MAAM,oBAAgB,mCAAa,MAAM,KAAK;AAMpD,YAAM,SAAS,UAAM,oDAA6B,KAAK,MAAM;AAC7D,UAAI,CAAC,QAAQ;AACT,mBAAO;AAAA,UACH,gCAAgC,MAAM,YAAY,GAAG;AAAA,UACrD;AAAA,QACJ;AAAA,MACJ;AAEA,YAAM,aAAS,+BAAa,EAAE,cAAc,KAAK,OAAO,CAAC;AACzD,UAAI,CAAC,OAAO,IAAI;AAGZ,mBAAO;AAAA,UACH,8CAA8C,OAAO,QAAQ,MAAM;AAAA,UACnE;AAAA,QACJ;AAAA,MACJ;AACA,iBAAO,gCAAgB;AAAA,QACnB,QAAQ,OAAO;AAAA,QACf,SAAS,oBAAoB,OAAO,SAAS,MAAM,WAAW,OAAO,SAAS,YAAY;AAAA,MAC9F,CAAC;AAAA,IACL;AAAA,EACJ;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -30,8 +30,6 @@ const dimensionSchema = import_zod.z.object({
|
|
|
30
30
|
dimensionValue: import_zod.z.string().describe('Dimension member value (e.g., "2024", "Widget A")')
|
|
31
31
|
});
|
|
32
32
|
const queryCellsSchema = {
|
|
33
|
-
organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
|
|
34
|
-
tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
|
|
35
33
|
queries: import_zod.z.array(
|
|
36
34
|
import_zod.z.object({
|
|
37
35
|
variable: import_zod.z.string().describe("Variable name"),
|
|
@@ -58,13 +56,11 @@ Example query:
|
|
|
58
56
|
|
|
59
57
|
Returns the value for each queried cell along with its dimension coordinates.
|
|
60
58
|
|
|
61
|
-
To write data, use farseer_create_import_job instead \u2014 it provides audit trail and undo support
|
|
62
|
-
|
|
63
|
-
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
59
|
+
To write data, use farseer_create_import_job instead \u2014 it provides audit trail and undo support.`,
|
|
64
60
|
queryCellsSchema,
|
|
65
61
|
// @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
|
|
66
62
|
async (params) => {
|
|
67
|
-
const resolved = (0, import_helpers.
|
|
63
|
+
const resolved = (0, import_helpers.getSessionTenant)();
|
|
68
64
|
if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
|
|
69
65
|
const { organisation, tenant } = resolved;
|
|
70
66
|
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/mcp/tools/cellTools.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Cell Tools\n *\n * MCP tools for querying cell values in Farseer.\n * For writing data, use farseer_create_import_job which provides audit trail and undo support.\n */\n\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport { getNativeFarseerClient } from '../../services/farseerFactory';\nimport {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,iBAAkB;AAClB,4BAAuC;AACvC,qBAMO;AACP,4BAAkC;AAGlC,MAAM,kBAAkB,aAAE,OAAO;AAAA,EAC7B,gBAAgB,aAAE,OAAO,EAAE,SAAS,iDAAiD;AAAA,EACrF,gBAAgB,aAAE,OAAO,EAAE,SAAS,mDAAmD;AAC3F,CAAC;AAGD,MAAM,mBAAmB;AAAA,EACrB,
|
|
4
|
+
"sourcesContent": ["/**\n * Cell Tools\n *\n * MCP tools for querying cell values in Farseer.\n * For writing data, use farseer_create_import_job which provides audit trail and undo support.\n */\n\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport { getNativeFarseerClient } from '../../services/farseerFactory';\nimport {\n getSessionTenant,\n successResponse,\n errorResponse,\n authRequiredResponse,\n tenantRequiredResponse,\n} from '../utils/helpers';\nimport { formatClientError } from '../../utils/errorFormatter';\n\n// Shared dimension schema\nconst dimensionSchema = z.object({\n dimensionTable: z.string().describe('Dimension table name (e.g., \"Years\", \"Product\")'),\n dimensionValue: z.string().describe('Dimension member value (e.g., \"2024\", \"Widget A\")'),\n});\n\n// Define schemas outside of tool registration to avoid TS2589\nconst queryCellsSchema = {\n queries: z\n .array(\n z.object({\n variable: z.string().describe('Variable name'),\n dimensions: z.array(dimensionSchema).describe('Dimension filters'),\n }),\n )\n .describe('Array of cell queries to execute'),\n};\n\nexport function registerCellTools(server: McpServer): void {\n // farseer_query_cells\n server.tool(\n 'farseer_query_cells',\n `Query cell values from a Farseer tenant.\n\nEach query specifies a variable name and dimension filters to locate specific cells.\nMultiple queries can be batched in a single call.\n\nExample query:\n{\n \"variable\": \"Revenue\",\n \"dimensions\": [\n { \"dimensionTable\": \"Years\", \"dimensionValue\": \"Y2025\" },\n { \"dimensionTable\": \"Product\", \"dimensionValue\": \"Widget A\" }\n ]\n}\n\nReturns the value for each queried cell along with its dimension coordinates.\n\nTo write data, use farseer_create_import_job instead \u2014 it provides audit trail and undo support.`,\n queryCellsSchema,\n // @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas\n async (params: {\n queries: Array<{\n variable: string;\n dimensions: Array<{ dimensionTable: string; dimensionValue: string }>;\n }>;\n }) => {\n const resolved = getSessionTenant();\n if (!resolved) return tenantRequiredResponse();\n const { organisation, tenant } = resolved;\n\n const nativeClient = await getNativeFarseerClient(organisation, tenant);\n if (!nativeClient) return authRequiredResponse(tenant);\n\n try {\n const results = await nativeClient.cells.query(params.queries);\n\n return successResponse({\n tenant,\n queryCount: params.queries.length,\n results,\n });\n } catch (error) {\n return errorResponse(`Query cells failed: ${await formatClientError(error)}`, 'NETWORK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