@n8n-plus/n8n-plus
Version:
n8n Workflow Automation Tool (plus edition)
97 lines • 4.62 kB
JavaScript
;
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 n8n_workflow_1 = require("n8n-workflow");
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 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) => {
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, { 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, { workflowId }) {
const workflow = await workflowFinderService.findWorkflowForUser(workflowId, user, ['workflow:read'], { includeActiveVersion: true });
if (!workflow || workflow.isArchived || !workflow.settings?.availableInMCP) {
throw new n8n_workflow_1.UserError('Workflow not found');
}
const nodes = workflow.activeVersion?.nodes ?? [];
const connections = workflow.activeVersion?.connections ?? {};
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,
triggerCount: workflow.triggerCount,
createdAt: workflow.createdAt.toISOString(),
updatedAt: workflow.updatedAt.toISOString(),
settings: workflow.settings ?? null,
connections,
nodes: nodes.map(({ credentials: _credentials, ...node }) => node),
tags: (workflow.tags ?? []).map((tag) => ({ id: tag.id, name: tag.name })),
meta: workflow.meta ?? null,
parentFolderId: workflow.parentFolder?.id ?? null,
description: workflow.description ?? undefined,
};
return { workflow: sanitizedWorkflow, triggerInfo: triggerNotice };
}
//# sourceMappingURL=get-workflow-details.tool.js.map