n8n
Version:
n8n Workflow Automation Tool
31 lines • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSdkReferenceHint = getSdkReferenceHint;
exports.getMcpWorkflow = getMcpWorkflow;
const mcp_errors_1 = require("../mcp.errors");
const constants_1 = require("./workflow-builder/constants");
function getSdkReferenceHint(error, options = {}) {
const isParseError = error instanceof Error &&
(error.name === 'WorkflowCodeParseError' || error instanceof SyntaxError);
if (!isParseError)
return undefined;
const afterReference = options.afterReference ??
`Rewrite the code using the documented patterns, then call ${constants_1.CODE_BUILDER_VALIDATE_TOOL.toolName} again before creating or updating a workflow.`;
return `The code failed to parse as n8n Workflow SDK code. This usually means it does not follow the required SDK patterns. Before retrying, call ${constants_1.MCP_GET_SDK_REFERENCE_TOOL.toolName} to read the Workflow SDK reference. Use workflow(), trigger()/node(), .add()/.to(), expr(), and newCredential() exactly as documented. ${afterReference}`;
}
async function getMcpWorkflow(workflowId, user, scopes, workflowFinderService, options) {
const workflow = await workflowFinderService.findWorkflowForUser(workflowId, user, scopes, {
includeActiveVersion: options?.includeActiveVersion,
});
if (!workflow) {
throw new mcp_errors_1.WorkflowAccessError("Workflow not found or you don't have permission to access it.", 'no_permission');
}
if (workflow.isArchived) {
throw new mcp_errors_1.WorkflowAccessError(`Workflow '${workflowId}' is archived and cannot be accessed.`, 'workflow_archived');
}
if (!workflow.settings?.availableInMCP) {
throw new mcp_errors_1.WorkflowAccessError('Workflow is not available in MCP. Enable MCP access in workflow settings.', 'not_available_in_mcp');
}
return workflow;
}
//# sourceMappingURL=workflow-validation.utils.js.map