farseer-cli 1.11.1 → 1.11.2
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 +2 -2
- package/dist/commands/app.js.map +2 -2
- package/dist/commands/dashboards.js +16 -2
- package/dist/commands/dashboards.js.map +2 -2
- package/dist/commands/sheets.js +46 -34
- package/dist/commands/sheets.js.map +2 -2
- package/dist/commands/variables.js +7 -1
- package/dist/commands/variables.js.map +2 -2
- package/dist/mcp/tools/appTools.js +2 -2
- package/dist/mcp/tools/appTools.js.map +2 -2
- package/dist/mcp/tools/dashboardTools.js +79 -69
- package/dist/mcp/tools/dashboardTools.js.map +2 -2
- package/dist/mcp/tools/sheetTools.js +48 -59
- package/dist/mcp/tools/sheetTools.js.map +2 -2
- package/dist/mcp/utils/helpers.js +39 -5
- package/dist/mcp/utils/helpers.js.map +2 -2
- package/dist/services/modelExport.js +4 -2
- package/dist/services/modelExport.js.map +2 -2
- package/dist/utils/entityResolver.js +114 -28
- package/dist/utils/entityResolver.js.map +2 -2
- package/dist/utils/helpers.js +5 -5
- package/dist/utils/helpers.js.map +2 -2
- package/dist/utils/{appResolver.js → nameResolver.js} +23 -23
- package/dist/utils/nameResolver.js.map +7 -0
- package/package.json +1 -1
- package/dist/utils/appResolver.js.map +0 -7
|
@@ -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 { requireSession } from '../utils/session';\nimport { AppArgument, AppDeleteRefusedError, AppUpdateChanges, applySourceFolderChange } from '../../services/apps';\nimport { successResponse, errorResponse, resolveAppItemForMcp, resolveAppForMcp } from '../utils/helpers';\nimport { matchApps } from '../../utils/appResolver';\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().optional().describe('Name of the app (can include spaces). Omit if using appId.'),\n appId: z.string().optional().describe('Numeric app id \u2014 use instead of appName when names collide.'),\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().optional().describe('Name of the app to configure. Omit if using appId.'),\n appId: z.string().optional().describe('Numeric app id \u2014 use instead of appName when names collide.'),\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().optional().describe('Name of the app to delete. Omit if using appId.'),\n appId: z.string().optional().describe('Numeric app id \u2014 use instead of appName when names collide.'),\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 gate = await requireSession();\n if (!gate.ok) return gate.response;\n const { tenant, client } = gate.session;\n\n try {\n const appList = await 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 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 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; appId?: string }) => {\n const gate = await requireSession();\n if (!gate.ok) return gate.response;\n const { tenant, client } = gate.session;\n\n try {\n const resolution = await resolveAppForMcp(client, {\n appName: params.appName,\n id: params.appId,\n });\n if ('error' in resolution) {\n return resolution.error;\n }\n const app = resolution.app;\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 gate = await requireSession();\n if (!gate.ok) return gate.response;\n const { tenant, client } = gate.session;\n\n try {\n // Any name match means the name is taken \u2014 a collision still counts.\n const existing = matchApps(await client.listApps(), params.appName);\n if (existing.length > 0) {\n return errorResponse(`App \"${params.appName}\" already exists`, 'VALIDATION_ERROR');\n }\n\n const app = await 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 appId?: 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 gate = await requireSession();\n if (!gate.ok) return gate.response;\n const { tenant, client } = gate.session;\n\n try {\n const resolution = await resolveAppForMcp(client, {\n appName: params.appName,\n id: params.appId,\n });\n if ('error' in resolution) {\n return resolution.error;\n }\n const app = resolution.app;\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 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 client.updateApp(reference, changes, app);\n\n return successResponse({\n tenant,\n appName: params.newName || app.name,\n updated: Object.keys(changes),\n message: `App \"${app.name}\" 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; appId?: string }) => {\n const gate = await requireSession();\n if (!gate.ok) return gate.response;\n const { tenant, client } = gate.session;\n\n try {\n const resolution = await resolveAppItemForMcp(client, {\n appName: params.appName,\n id: params.appId,\n });\n if ('error' in resolution) {\n return resolution.error;\n }\n const appItem = resolution.item;\n\n await client.deleteApp(appItem.reference);\n\n // The folder API 200s even when nothing was deleted; confirm.\n const remaining = await client.listApps();\n if (remaining.some((a) => a.reference === appItem.reference)) {\n return errorResponse(\n `Delete reported success but \"${appItem.name}\" is still present`,\n 'NETWORK_ERROR',\n );\n }\n\n return successResponse({\n tenant,\n deletedApp: appItem.name,\n message: `App \"${appItem.name}\" has been deleted`,\n });\n } catch (error) {\n // A guard refusal is not retryable \u2014 nothing was deleted and a\n // retry cannot change that. Don't let it read as a transport blip.\n return errorResponse(\n `Delete app failed: ${await formatClientError(error)}`,\n error instanceof AppDeleteRefusedError ? 'VALIDATION_ERROR' : 'NETWORK_ERROR',\n );\n }\n },\n );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iBAAkB;AAClB,qBAA+B;AAC/B,kBAA8F;AAC9F,qBAAuF;AACvF,
|
|
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 { requireSession } from '../utils/session';\nimport { AppArgument, AppDeleteRefusedError, AppUpdateChanges, applySourceFolderChange } from '../../services/apps';\nimport { successResponse, errorResponse, resolveAppItemForMcp, resolveAppForMcp } from '../utils/helpers';\nimport { matchByName } from '../../utils/nameResolver';\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().optional().describe('Name of the app (can include spaces). Omit if using appId.'),\n appId: z.string().optional().describe('Numeric app id \u2014 use instead of appName when names collide.'),\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().optional().describe('Name of the app to configure. Omit if using appId.'),\n appId: z.string().optional().describe('Numeric app id \u2014 use instead of appName when names collide.'),\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().optional().describe('Name of the app to delete. Omit if using appId.'),\n appId: z.string().optional().describe('Numeric app id \u2014 use instead of appName when names collide.'),\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 gate = await requireSession();\n if (!gate.ok) return gate.response;\n const { tenant, client } = gate.session;\n\n try {\n const appList = await 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 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 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; appId?: string }) => {\n const gate = await requireSession();\n if (!gate.ok) return gate.response;\n const { tenant, client } = gate.session;\n\n try {\n const resolution = await resolveAppForMcp(client, {\n appName: params.appName,\n id: params.appId,\n });\n if ('error' in resolution) {\n return resolution.error;\n }\n const app = resolution.app;\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 gate = await requireSession();\n if (!gate.ok) return gate.response;\n const { tenant, client } = gate.session;\n\n try {\n // Any name match means the name is taken \u2014 a collision still counts.\n const existing = matchByName(await client.listApps(), params.appName);\n if (existing.length > 0) {\n return errorResponse(`App \"${params.appName}\" already exists`, 'VALIDATION_ERROR');\n }\n\n const app = await 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 appId?: 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 gate = await requireSession();\n if (!gate.ok) return gate.response;\n const { tenant, client } = gate.session;\n\n try {\n const resolution = await resolveAppForMcp(client, {\n appName: params.appName,\n id: params.appId,\n });\n if ('error' in resolution) {\n return resolution.error;\n }\n const app = resolution.app;\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 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 client.updateApp(reference, changes, app);\n\n return successResponse({\n tenant,\n appName: params.newName || app.name,\n updated: Object.keys(changes),\n message: `App \"${app.name}\" 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; appId?: string }) => {\n const gate = await requireSession();\n if (!gate.ok) return gate.response;\n const { tenant, client } = gate.session;\n\n try {\n const resolution = await resolveAppItemForMcp(client, {\n appName: params.appName,\n id: params.appId,\n });\n if ('error' in resolution) {\n return resolution.error;\n }\n const appItem = resolution.item;\n\n await client.deleteApp(appItem.reference);\n\n // The folder API 200s even when nothing was deleted; confirm.\n const remaining = await client.listApps();\n if (remaining.some((a) => a.reference === appItem.reference)) {\n return errorResponse(\n `Delete reported success but \"${appItem.name}\" is still present`,\n 'NETWORK_ERROR',\n );\n }\n\n return successResponse({\n tenant,\n deletedApp: appItem.name,\n message: `App \"${appItem.name}\" has been deleted`,\n });\n } catch (error) {\n // A guard refusal is not retryable \u2014 nothing was deleted and a\n // retry cannot change that. Don't let it read as a transport blip.\n return errorResponse(\n `Delete app failed: ${await formatClientError(error)}`,\n error instanceof AppDeleteRefusedError ? 'VALIDATION_ERROR' : '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;",
|
|
6
6
|
"names": ["s"]
|
|
7
7
|
}
|
|
@@ -34,9 +34,9 @@ module.exports = __toCommonJS(dashboardTools_exports);
|
|
|
34
34
|
var import_zod = require("zod");
|
|
35
35
|
var farseer = __toESM(require("farseer-client"));
|
|
36
36
|
var import_session = require("../utils/session");
|
|
37
|
-
var import_entityResolver = require("../../utils/entityResolver");
|
|
38
37
|
var import_helpers = require("../utils/helpers");
|
|
39
38
|
var import_errorFormatter = require("../../utils/errorFormatter");
|
|
39
|
+
var import_entityResolver = require("../../utils/entityResolver");
|
|
40
40
|
function getRawApiConfig(nativeClient) {
|
|
41
41
|
const config = nativeClient.dashboards?.configuration || nativeClient._configuration || nativeClient.configuration;
|
|
42
42
|
return {
|
|
@@ -66,20 +66,13 @@ async function rawApiCall(nativeClient, method, path, body) {
|
|
|
66
66
|
const text = await response.text();
|
|
67
67
|
return text ? JSON.parse(text) : null;
|
|
68
68
|
}
|
|
69
|
-
async function collectDashboardsWithPaths(client
|
|
70
|
-
const items =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} else if (child.type === farseer.FolderItemType.Folder) {
|
|
77
|
-
const subPath = currentPath ? `${currentPath}/${child.name}` : child.name;
|
|
78
|
-
const sub = await collectDashboardsWithPaths(client, child.id, subPath);
|
|
79
|
-
items.push(...sub);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return items;
|
|
69
|
+
async function collectDashboardsWithPaths(client) {
|
|
70
|
+
const items = await (0, import_entityResolver.collectFolderItems)(client, farseer.FolderItemType.Dashboard);
|
|
71
|
+
return items.map((item) => ({
|
|
72
|
+
id: Number(item.reference),
|
|
73
|
+
name: item.name,
|
|
74
|
+
folderPath: item.folderPath.join("/") || "/"
|
|
75
|
+
}));
|
|
83
76
|
}
|
|
84
77
|
const listDashboardsSchema = {
|
|
85
78
|
includeFolderPath: import_zod.z.boolean().optional().describe("Include folder path for each dashboard (slower, traverses folder tree). Default: false.")
|
|
@@ -162,7 +155,7 @@ Set includeFolderPath=true to also show the folder path for each dashboard
|
|
|
162
155
|
const { tenant, native: nativeClient } = gate.session;
|
|
163
156
|
try {
|
|
164
157
|
if (params.includeFolderPath) {
|
|
165
|
-
const dashboards2 = await collectDashboardsWithPaths(nativeClient
|
|
158
|
+
const dashboards2 = await collectDashboardsWithPaths(nativeClient);
|
|
166
159
|
return (0, import_helpers.successResponse)({
|
|
167
160
|
tenant,
|
|
168
161
|
totalDashboards: dashboards2.length,
|
|
@@ -197,11 +190,11 @@ Accepts either a dashboard name or numeric ID.`,
|
|
|
197
190
|
if (!gate.ok) return gate.response;
|
|
198
191
|
const { tenant, native: nativeClient } = gate.session;
|
|
199
192
|
try {
|
|
200
|
-
const dashRef = await (0,
|
|
201
|
-
if (
|
|
202
|
-
return
|
|
193
|
+
const dashRef = await (0, import_helpers.resolveEntityForMcp)(nativeClient, "dashboard", params.dashboardNameOrId);
|
|
194
|
+
if ("error" in dashRef) {
|
|
195
|
+
return dashRef.error;
|
|
203
196
|
}
|
|
204
|
-
const dashboard = await nativeClient.dashboards.get(dashRef.id);
|
|
197
|
+
const dashboard = await nativeClient.dashboards.get(dashRef.entity.id);
|
|
205
198
|
const includeTiles = params.includeTiles !== false;
|
|
206
199
|
const result = {
|
|
207
200
|
id: dashboard.id,
|
|
@@ -243,11 +236,11 @@ Accepts either a dashboard name or numeric ID.`,
|
|
|
243
236
|
if (!gate.ok) return gate.response;
|
|
244
237
|
const { tenant, native: nativeClient } = gate.session;
|
|
245
238
|
try {
|
|
246
|
-
const dashRef = await (0,
|
|
247
|
-
if (
|
|
248
|
-
return
|
|
239
|
+
const dashRef = await (0, import_helpers.resolveEntityForMcp)(nativeClient, "dashboard", params.dashboardNameOrId);
|
|
240
|
+
if ("error" in dashRef) {
|
|
241
|
+
return dashRef.error;
|
|
249
242
|
}
|
|
250
|
-
const tiles = await nativeClient.dashboards.listTiles(dashRef.id);
|
|
243
|
+
const tiles = await nativeClient.dashboards.listTiles(dashRef.entity.id);
|
|
251
244
|
const result = tiles.map((t) => {
|
|
252
245
|
const tile = {
|
|
253
246
|
id: t.id,
|
|
@@ -263,7 +256,7 @@ Accepts either a dashboard name or numeric ID.`,
|
|
|
263
256
|
});
|
|
264
257
|
return (0, import_helpers.successResponse)({
|
|
265
258
|
tenant,
|
|
266
|
-
dashboard: { id: dashRef.id, name: dashRef.name },
|
|
259
|
+
dashboard: { id: dashRef.entity.id, name: dashRef.entity.name },
|
|
267
260
|
totalTiles: result.length,
|
|
268
261
|
tiles: result
|
|
269
262
|
});
|
|
@@ -291,14 +284,18 @@ Accepts either a dashboard name or numeric ID.`,
|
|
|
291
284
|
if (!gate.ok) return gate.response;
|
|
292
285
|
const { tenant, native: nativeClient } = gate.session;
|
|
293
286
|
try {
|
|
294
|
-
const dashRef = await (0,
|
|
295
|
-
if (
|
|
296
|
-
return
|
|
287
|
+
const dashRef = await (0, import_helpers.resolveEntityForMcp)(nativeClient, "dashboard", params.dashboardNameOrId);
|
|
288
|
+
if ("error" in dashRef) {
|
|
289
|
+
return dashRef.error;
|
|
297
290
|
}
|
|
298
|
-
const tile = await rawApiCall(
|
|
291
|
+
const tile = await rawApiCall(
|
|
292
|
+
nativeClient,
|
|
293
|
+
"GET",
|
|
294
|
+
`/dashboards/${dashRef.entity.id}/tiles/${params.tileId}`
|
|
295
|
+
);
|
|
299
296
|
return (0, import_helpers.successResponse)({
|
|
300
297
|
tenant,
|
|
301
|
-
dashboard: { id: dashRef.id, name: dashRef.name },
|
|
298
|
+
dashboard: { id: dashRef.entity.id, name: dashRef.entity.name },
|
|
302
299
|
tile
|
|
303
300
|
});
|
|
304
301
|
} catch (error) {
|
|
@@ -329,9 +326,9 @@ Style options: showBackground, backgroundColor, showBorder, borderColor, hasShad
|
|
|
329
326
|
if (!gate.ok) return gate.response;
|
|
330
327
|
const { tenant, native: nativeClient } = gate.session;
|
|
331
328
|
try {
|
|
332
|
-
const dashRef = await (0,
|
|
333
|
-
if (
|
|
334
|
-
return
|
|
329
|
+
const dashRef = await (0, import_helpers.resolveEntityForMcp)(nativeClient, "dashboard", params.dashboardNameOrId);
|
|
330
|
+
if ("error" in dashRef) {
|
|
331
|
+
return dashRef.error;
|
|
335
332
|
}
|
|
336
333
|
const tilePayload = { ...params.tile };
|
|
337
334
|
if (tilePayload.subtitle === void 0) tilePayload.subtitle = "";
|
|
@@ -346,17 +343,22 @@ Style options: showBackground, backgroundColor, showBorder, borderColor, hasShad
|
|
|
346
343
|
if (d.exportConfigurationId === void 0) d.exportConfigurationId = null;
|
|
347
344
|
if (d.visualization === void 0) d.visualization = { type: "TABLE" };
|
|
348
345
|
}
|
|
349
|
-
const result = await rawApiCall(
|
|
346
|
+
const result = await rawApiCall(
|
|
347
|
+
nativeClient,
|
|
348
|
+
"POST",
|
|
349
|
+
`/dashboards/${dashRef.entity.id}/tiles`,
|
|
350
|
+
tilePayload
|
|
351
|
+
);
|
|
350
352
|
return (0, import_helpers.successResponse)({
|
|
351
353
|
tenant,
|
|
352
|
-
dashboard: { id: dashRef.id, name: dashRef.name },
|
|
354
|
+
dashboard: { id: dashRef.entity.id, name: dashRef.entity.name },
|
|
353
355
|
action: "created",
|
|
354
356
|
tile: {
|
|
355
357
|
id: result?.id,
|
|
356
358
|
name: result?.name,
|
|
357
359
|
type: result?.data?.type
|
|
358
360
|
},
|
|
359
|
-
message: `Tile "${params.tile.name || "unnamed"}" created on dashboard "${dashRef.name}"`
|
|
361
|
+
message: `Tile "${params.tile.name || "unnamed"}" created on dashboard "${dashRef.entity.name}"`
|
|
360
362
|
});
|
|
361
363
|
} catch (error) {
|
|
362
364
|
return (0, import_helpers.errorResponse)(`Create tile failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
|
|
@@ -394,17 +396,20 @@ WARNING: This modifies dashboard configuration. Use with caution.`,
|
|
|
394
396
|
if (!gate.ok) return gate.response;
|
|
395
397
|
const { tenant, native: nativeClient } = gate.session;
|
|
396
398
|
try {
|
|
397
|
-
const dashRef = await (0,
|
|
398
|
-
if (
|
|
399
|
-
return
|
|
399
|
+
const dashRef = await (0, import_helpers.resolveEntityForMcp)(nativeClient, "dashboard", params.dashboardNameOrId);
|
|
400
|
+
if ("error" in dashRef) {
|
|
401
|
+
return dashRef.error;
|
|
400
402
|
}
|
|
401
403
|
const currentTile = await rawApiCall(
|
|
402
404
|
nativeClient,
|
|
403
405
|
"GET",
|
|
404
|
-
`/dashboards/${dashRef.id}/tiles/${params.tileId}`
|
|
406
|
+
`/dashboards/${dashRef.entity.id}/tiles/${params.tileId}`
|
|
405
407
|
);
|
|
406
408
|
if (!currentTile) {
|
|
407
|
-
return (0, import_helpers.errorResponse)(
|
|
409
|
+
return (0, import_helpers.errorResponse)(
|
|
410
|
+
`Tile ${params.tileId} not found on dashboard "${dashRef.entity.name}"`,
|
|
411
|
+
"NOT_FOUND"
|
|
412
|
+
);
|
|
408
413
|
}
|
|
409
414
|
const replaceSet = new Set(params.replaceKeys || []);
|
|
410
415
|
const newVisType = params.tile?.data?.visualization?.type;
|
|
@@ -414,13 +419,18 @@ WARNING: This modifies dashboard configuration. Use with caution.`,
|
|
|
414
419
|
}
|
|
415
420
|
const merged = deepMerge(currentTile, params.tile, replaceSet);
|
|
416
421
|
delete merged.id;
|
|
417
|
-
await rawApiCall(
|
|
422
|
+
await rawApiCall(
|
|
423
|
+
nativeClient,
|
|
424
|
+
"PUT",
|
|
425
|
+
`/dashboards/${dashRef.entity.id}/tiles/${params.tileId}`,
|
|
426
|
+
merged
|
|
427
|
+
);
|
|
418
428
|
return (0, import_helpers.successResponse)({
|
|
419
429
|
tenant,
|
|
420
|
-
dashboard: { id: dashRef.id, name: dashRef.name },
|
|
430
|
+
dashboard: { id: dashRef.entity.id, name: dashRef.entity.name },
|
|
421
431
|
action: "updated",
|
|
422
432
|
tileId: params.tileId,
|
|
423
|
-
message: `Tile ${params.tileId} updated on dashboard "${dashRef.name}"`
|
|
433
|
+
message: `Tile ${params.tileId} updated on dashboard "${dashRef.entity.name}"`
|
|
424
434
|
});
|
|
425
435
|
} catch (error) {
|
|
426
436
|
return (0, import_helpers.errorResponse)(`Update tile failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
|
|
@@ -445,17 +455,17 @@ WARNING: This is destructive and cannot be undone.`,
|
|
|
445
455
|
if (!gate.ok) return gate.response;
|
|
446
456
|
const { tenant, native: nativeClient } = gate.session;
|
|
447
457
|
try {
|
|
448
|
-
const dashRef = await (0,
|
|
449
|
-
if (
|
|
450
|
-
return
|
|
458
|
+
const dashRef = await (0, import_helpers.resolveEntityForMcp)(nativeClient, "dashboard", params.dashboardNameOrId);
|
|
459
|
+
if ("error" in dashRef) {
|
|
460
|
+
return dashRef.error;
|
|
451
461
|
}
|
|
452
|
-
await rawApiCall(nativeClient, "DELETE", `/dashboards/${dashRef.id}/tiles/${params.tileId}`);
|
|
462
|
+
await rawApiCall(nativeClient, "DELETE", `/dashboards/${dashRef.entity.id}/tiles/${params.tileId}`);
|
|
453
463
|
return (0, import_helpers.successResponse)({
|
|
454
464
|
tenant,
|
|
455
|
-
dashboard: { id: dashRef.id, name: dashRef.name },
|
|
465
|
+
dashboard: { id: dashRef.entity.id, name: dashRef.entity.name },
|
|
456
466
|
action: "deleted",
|
|
457
467
|
tileId: params.tileId,
|
|
458
|
-
message: `Tile ${params.tileId} deleted from dashboard "${dashRef.name}"`
|
|
468
|
+
message: `Tile ${params.tileId} deleted from dashboard "${dashRef.entity.name}"`
|
|
459
469
|
});
|
|
460
470
|
} catch (error) {
|
|
461
471
|
return (0, import_helpers.errorResponse)(`Delete tile failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
|
|
@@ -553,11 +563,11 @@ WARNING: This modifies dashboard configuration. Use with caution.`,
|
|
|
553
563
|
if (!gate.ok) return gate.response;
|
|
554
564
|
const { tenant, native: nativeClient } = gate.session;
|
|
555
565
|
try {
|
|
556
|
-
const dashRef = await (0,
|
|
557
|
-
if (
|
|
558
|
-
return
|
|
566
|
+
const dashRef = await (0, import_helpers.resolveEntityForMcp)(nativeClient, "dashboard", params.dashboardNameOrId);
|
|
567
|
+
if ("error" in dashRef) {
|
|
568
|
+
return dashRef.error;
|
|
559
569
|
}
|
|
560
|
-
const current = await rawApiCall(nativeClient, "GET", `/dashboards/${dashRef.id}`);
|
|
570
|
+
const current = await rawApiCall(nativeClient, "GET", `/dashboards/${dashRef.entity.id}`);
|
|
561
571
|
const base = {
|
|
562
572
|
name: current.name,
|
|
563
573
|
columns: current.columns,
|
|
@@ -566,12 +576,12 @@ WARNING: This modifies dashboard configuration. Use with caution.`,
|
|
|
566
576
|
};
|
|
567
577
|
const replaceSet = /* @__PURE__ */ new Set(["columns", "rows", "options"]);
|
|
568
578
|
const merged = deepMerge(base, params.update, replaceSet);
|
|
569
|
-
await rawApiCall(nativeClient, "PUT", `/dashboards/${dashRef.id}`, merged);
|
|
579
|
+
await rawApiCall(nativeClient, "PUT", `/dashboards/${dashRef.entity.id}`, merged);
|
|
570
580
|
return (0, import_helpers.successResponse)({
|
|
571
581
|
tenant,
|
|
572
582
|
action: "updated",
|
|
573
|
-
dashboard: { id: dashRef.id, name: merged.name },
|
|
574
|
-
message: `Dashboard "${dashRef.name}" updated`
|
|
583
|
+
dashboard: { id: dashRef.entity.id, name: merged.name },
|
|
584
|
+
message: `Dashboard "${dashRef.entity.name}" updated`
|
|
575
585
|
});
|
|
576
586
|
} catch (error) {
|
|
577
587
|
return (0, import_helpers.errorResponse)(`Update dashboard failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
|
|
@@ -592,16 +602,16 @@ if dashboard deletion is not supported for the tenant.`,
|
|
|
592
602
|
if (!gate.ok) return gate.response;
|
|
593
603
|
const { tenant, native: nativeClient } = gate.session;
|
|
594
604
|
try {
|
|
595
|
-
const dashRef = await (0,
|
|
596
|
-
if (
|
|
597
|
-
return
|
|
605
|
+
const dashRef = await (0, import_helpers.resolveEntityForMcp)(nativeClient, "dashboard", params.dashboardNameOrId);
|
|
606
|
+
if ("error" in dashRef) {
|
|
607
|
+
return dashRef.error;
|
|
598
608
|
}
|
|
599
|
-
await rawApiCall(nativeClient, "DELETE", `/dashboards/${dashRef.id}`);
|
|
609
|
+
await rawApiCall(nativeClient, "DELETE", `/dashboards/${dashRef.entity.id}`);
|
|
600
610
|
return (0, import_helpers.successResponse)({
|
|
601
611
|
tenant,
|
|
602
612
|
action: "deleted",
|
|
603
|
-
dashboard: { id: dashRef.id, name: dashRef.name },
|
|
604
|
-
message: `Dashboard "${dashRef.name}" deleted`
|
|
613
|
+
dashboard: { id: dashRef.entity.id, name: dashRef.entity.name },
|
|
614
|
+
message: `Dashboard "${dashRef.entity.name}" deleted`
|
|
605
615
|
});
|
|
606
616
|
} catch (error) {
|
|
607
617
|
return (0, import_helpers.errorResponse)(`Delete dashboard failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
|
|
@@ -623,9 +633,9 @@ If no folder is specified, duplicates to the root Dashboards folder.`,
|
|
|
623
633
|
if (!gate.ok) return gate.response;
|
|
624
634
|
const { tenant, native: nativeClient } = gate.session;
|
|
625
635
|
try {
|
|
626
|
-
const dashRef = await (0,
|
|
627
|
-
if (
|
|
628
|
-
return
|
|
636
|
+
const dashRef = await (0, import_helpers.resolveEntityForMcp)(nativeClient, "dashboard", params.dashboardNameOrId);
|
|
637
|
+
if ("error" in dashRef) {
|
|
638
|
+
return dashRef.error;
|
|
629
639
|
}
|
|
630
640
|
let targetFolderId = params.folderId ?? 0;
|
|
631
641
|
if (!params.folderId && params.folderPath && params.folderPath.length > 0) {
|
|
@@ -649,19 +659,19 @@ If no folder is specified, duplicates to the root Dashboards folder.`,
|
|
|
649
659
|
}
|
|
650
660
|
const result = await nativeClient.dashboards.duplicate({
|
|
651
661
|
name: params.name,
|
|
652
|
-
sourceId: dashRef.id,
|
|
662
|
+
sourceId: dashRef.entity.id,
|
|
653
663
|
folderId: targetFolderId
|
|
654
664
|
});
|
|
655
665
|
return (0, import_helpers.successResponse)({
|
|
656
666
|
tenant,
|
|
657
667
|
action: "duplicated",
|
|
658
|
-
source: { id: dashRef.id, name: dashRef.name },
|
|
668
|
+
source: { id: dashRef.entity.id, name: dashRef.entity.name },
|
|
659
669
|
newDashboard: {
|
|
660
670
|
id: result.id,
|
|
661
671
|
name: result.name
|
|
662
672
|
},
|
|
663
673
|
folderId: targetFolderId,
|
|
664
|
-
message: `Dashboard "${dashRef.name}" duplicated as "${params.name}"`
|
|
674
|
+
message: `Dashboard "${dashRef.entity.name}" duplicated as "${params.name}"`
|
|
665
675
|
});
|
|
666
676
|
} catch (error) {
|
|
667
677
|
return (0, import_helpers.errorResponse)(`Duplicate dashboard failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
|