UNPKG

n8n

Version:

n8n Workflow Automation Tool

108 lines 5.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createWorkflowDetailsTool = void 0; exports.getWorkflowDetails = getWorkflowDetails; const zod_1 = __importDefault(require("zod")); const mcp_constants_1 = require("../mcp.constants"); const schemas_1 = require("./schemas"); const webhook_utils_1 = require("./webhook-utils"); const workflow_validation_utils_1 = require("./workflow-validation.utils"); const inputSchema = { workflowId: zod_1.default.string().describe('The ID of the workflow to retrieve'), }; const outputSchema = schemas_1.workflowDetailsOutputSchema.shape; const createWorkflowDetailsTool = (user, baseWebhookUrl, workflowFinderService, credentialsService, endpoints, telemetry, roleService, projectService) => { return { name: 'get_workflow_details', config: { description: 'Get detailed information about a specific workflow including trigger details', inputSchema, outputSchema, annotations: { title: 'Get Workflow Details', readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, }, handler: async ({ workflowId }) => { const parameters = { workflowId }; const telemetryPayload = { user_id: user.id, tool_name: 'get_workflow_details', parameters, }; try { const payload = await getWorkflowDetails(user, baseWebhookUrl, workflowFinderService, credentialsService, endpoints, roleService, projectService, { workflowId }); telemetryPayload.results = { success: true, data: { workflow_id: workflowId, workflow_name: payload.workflow.name, trigger_count: payload.workflow.triggerCount, node_count: payload.workflow.nodes.length, }, }; telemetry.track(mcp_constants_1.USER_CALLED_MCP_TOOL_EVENT, telemetryPayload); return { content: [{ type: 'text', text: JSON.stringify(payload) }], structuredContent: payload, }; } catch (error) { telemetryPayload.results = { success: false, error: error instanceof Error ? error.message : String(error), }; telemetry.track(mcp_constants_1.USER_CALLED_MCP_TOOL_EVENT, telemetryPayload); throw error; } }, }; }; exports.createWorkflowDetailsTool = createWorkflowDetailsTool; async function getWorkflowDetails(user, baseWebhookUrl, workflowFinderService, credentialsService, endpoints, roleService, projectService, { workflowId }) { const workflow = await (0, workflow_validation_utils_1.getMcpWorkflow)(workflowId, user, ['workflow:read'], workflowFinderService, { includeActiveVersion: true }); const projectRelations = await projectService.getProjectRelationsForUser(user); const workflowWithScopes = roleService.addScopes(workflow, user, projectRelations); const scopes = workflowWithScopes.scopes ?? []; const canExecute = scopes.includes('workflow:execute'); const nodes = workflow.nodes ?? []; const connections = workflow.connections ?? {}; const activeVersion = workflow.activeVersionId && workflow.activeVersion ? { nodes: (workflow.activeVersion.nodes ?? []).map(({ credentials: _credentials, ...node }) => node), connections: workflow.activeVersion.connections ?? {}, } : null; const supportedTriggers = Object.keys(mcp_constants_1.SUPPORTED_MCP_TRIGGERS); const triggers = nodes.filter((node) => supportedTriggers.includes(node.type) && node.disabled !== true); const triggerNotice = await (0, webhook_utils_1.getTriggerDetails)(user, triggers, baseWebhookUrl, credentialsService, endpoints); const sanitizedWorkflow = { id: workflow.id, name: workflow.name, active: workflow.activeVersionId !== null, isArchived: workflow.isArchived, versionId: workflow.versionId, activeVersionId: workflow.activeVersionId, triggerCount: workflow.triggerCount, createdAt: workflow.createdAt.toISOString(), updatedAt: workflow.updatedAt.toISOString(), settings: workflow.settings ?? null, connections, nodes: nodes.map(({ credentials: _credentials, ...node }) => node), activeVersion, tags: (workflow.tags ?? []).map((tag) => ({ id: tag.id, name: tag.name })), meta: workflow.meta ?? null, parentFolderId: workflow.parentFolder?.id ?? null, description: workflow.description ?? undefined, scopes, canExecute, }; return { workflow: sanitizedWorkflow, triggerInfo: triggerNotice }; } //# sourceMappingURL=get-workflow-details.tool.js.map