n8n
Version:
n8n Workflow Automation Tool
463 lines • 29.7 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.McpService = void 0;
const api_types_1 = require("@n8n/api-types");
const backend_common_1 = require("@n8n/backend-common");
const config_1 = require("@n8n/config");
const db_1 = require("@n8n/db");
const di_1 = require("@n8n/di");
const server_1 = require("@n8n/mcp-apps/server");
const lazy_import_1 = require("@n8n/utils/lazy-import");
const deferred_promise_1 = require("@n8n/utils/promise/deferred-promise");
const n8n_core_1 = require("n8n-core");
const n8n_workflow_1 = require("n8n-workflow");
const active_executions_1 = require("../../active-executions");
const collaboration_service_1 = require("../../collaboration/collaboration.service");
const constants_1 = require("../../constants");
const credentials_service_1 = require("../../credentials/credentials.service");
const event_service_1 = require("../../events/event.service");
const execution_service_1 = require("../../executions/execution.service");
const subworkflow_policy_checker_1 = require("../../executions/pre-execution-checks/subworkflow-policy-checker");
const data_table_proxy_service_1 = require("../../modules/data-table/data-table-proxy.service");
const node_catalog_1 = require("../../node-catalog");
const node_types_1 = require("../../node-types");
const posthog_1 = require("../../posthog");
const ai_gateway_service_1 = require("../../services/ai-gateway.service");
const node_resource_explorer_service_1 = require("../../services/node-resource-explorer.service");
const project_service_ee_1 = require("../../services/project.service.ee");
const role_service_1 = require("../../services/role.service");
const tag_service_1 = require("../../services/tag.service");
const url_service_1 = require("../../services/url.service");
const telemetry_1 = require("../../telemetry");
const workflow_runner_1 = require("../../workflow-runner");
const workflow_creation_service_1 = require("../../workflows/workflow-creation.service");
const workflow_finder_service_1 = require("../../workflows/workflow-finder.service");
const workflow_history_service_1 = require("../../workflows/workflow-history/workflow-history.service");
const workflow_published_data_service_1 = require("../../workflows/workflow-published-data.service");
const workflow_service_1 = require("../../workflows/workflow.service");
const mcp_constants_1 = require("./mcp.constants");
const mcp_scopes_1 = require("./mcp-scopes");
const mcp_tool_availability_1 = require("./mcp-tool-availability");
const tool_schema_util_1 = require("./tool-schema.util");
const data_table_1 = require("./tools/data-table");
const execute_workflow_tool_1 = require("./tools/execute-workflow.tool");
const get_execution_tool_1 = require("./tools/get-execution.tool");
const get_workflow_details_tool_1 = require("./tools/get-workflow-details.tool");
const get_workflow_history_tool_1 = require("./tools/get-workflow-history.tool");
const get_workflow_version_tool_1 = require("./tools/get-workflow-version.tool");
const list_credentials_tool_1 = require("./tools/list-credentials.tool");
const list_n8n_connect_services_tool_1 = require("./tools/list-n8n-connect-services.tool");
const list_tags_tool_1 = require("./tools/list-tags.tool");
const prepare_workflow_pin_data_tool_1 = require("./tools/prepare-workflow-pin-data.tool");
const publish_workflow_tool_1 = require("./tools/publish-workflow.tool");
const search_executions_tool_1 = require("./tools/search-executions.tool");
const search_folders_tool_1 = require("./tools/search-folders.tool");
const search_projects_tool_1 = require("./tools/search-projects.tool");
const search_workflows_tool_1 = require("./tools/search-workflows.tool");
const test_workflow_tool_1 = require("./tools/test-workflow.tool");
const unpublish_workflow_tool_1 = require("./tools/unpublish-workflow.tool");
const constants_2 = require("./tools/workflow-builder/constants");
const create_workflow_from_code_tool_1 = require("./tools/workflow-builder/create-workflow-from-code.tool");
const delete_workflow_tool_1 = require("./tools/workflow-builder/delete-workflow.tool");
const explore_node_resources_tool_1 = require("./tools/workflow-builder/explore-node-resources.tool");
const get_workflow_best_practices_tool_1 = require("./tools/workflow-builder/get-workflow-best-practices.tool");
const get_workflow_node_types_tool_1 = require("./tools/workflow-builder/get-workflow-node-types.tool");
const get_workflow_sdk_reference_tool_1 = require("./tools/workflow-builder/get-workflow-sdk-reference.tool");
const mcp_instructions_1 = require("./tools/workflow-builder/mcp-instructions");
const restore_workflow_version_tool_1 = require("./tools/workflow-builder/restore-workflow-version.tool");
const sdk_reference_content_1 = require("./tools/workflow-builder/sdk-reference-content");
const search_workflow_nodes_tool_1 = require("./tools/workflow-builder/search-workflow-nodes.tool");
const update_workflow_tool_1 = require("./tools/workflow-builder/update-workflow.tool");
const validate_node_tool_1 = require("./tools/workflow-builder/validate-node.tool");
const validate_workflow_code_tool_1 = require("./tools/workflow-builder/validate-workflow-code.tool");
function getToolCallOutcome(result) {
if (!result)
return { status: 'success' };
const structured = typeof result.structuredContent === 'object' && result.structuredContent !== null
? result.structuredContent
: undefined;
const errorMessage = typeof structured?.error === 'string' ? structured.error : undefined;
if (result.isError !== true && structured?.status !== 'error' && errorMessage === undefined) {
return { status: 'success' };
}
if (errorMessage !== undefined)
return { status: 'error', errorMessage };
for (const item of result.content ?? []) {
if (item.type === 'text')
return { status: 'error', errorMessage: item.text };
}
return { status: 'error' };
}
function getWorkflowId(source) {
if (!source || typeof source !== 'object' || !('workflowId' in source))
return undefined;
const workflowId = source.workflowId;
return typeof workflowId === 'string' ? workflowId : undefined;
}
let McpService = class McpService {
constructor(logger, executionsConfig, instanceSettings, workflowFinderService, workflowService, urlService, credentialsService, activeExecutions, globalConfig, telemetry, workflowRunner, roleService, projectService, nodeCatalogService, workflowCreationService, nodeTypes, projectRepository, folderRepository, sharedWorkflowRepository, executionRepository, executionService, dataTableProxyService, collaborationService, nodeResourceExplorerService, tagService, licenseState, postHogClient, workflowHistoryService, workflowsConfig, workflowPublishedDataService, subworkflowPolicyChecker, aiGatewayService, moduleRegistry, eventService) {
this.logger = logger;
this.executionsConfig = executionsConfig;
this.instanceSettings = instanceSettings;
this.workflowFinderService = workflowFinderService;
this.workflowService = workflowService;
this.urlService = urlService;
this.credentialsService = credentialsService;
this.activeExecutions = activeExecutions;
this.globalConfig = globalConfig;
this.telemetry = telemetry;
this.workflowRunner = workflowRunner;
this.roleService = roleService;
this.projectService = projectService;
this.nodeCatalogService = nodeCatalogService;
this.workflowCreationService = workflowCreationService;
this.nodeTypes = nodeTypes;
this.projectRepository = projectRepository;
this.folderRepository = folderRepository;
this.sharedWorkflowRepository = sharedWorkflowRepository;
this.executionRepository = executionRepository;
this.executionService = executionService;
this.dataTableProxyService = dataTableProxyService;
this.collaborationService = collaborationService;
this.nodeResourceExplorerService = nodeResourceExplorerService;
this.tagService = tagService;
this.licenseState = licenseState;
this.postHogClient = postHogClient;
this.workflowHistoryService = workflowHistoryService;
this.workflowsConfig = workflowsConfig;
this.workflowPublishedDataService = workflowPublishedDataService;
this.subworkflowPolicyChecker = subworkflowPolicyChecker;
this.aiGatewayService = aiGatewayService;
this.moduleRegistry = moduleRegistry;
this.eventService = eventService;
this.pendingResponses = new Map();
}
async resolveFeatureFlags(user) {
const { mcpAppsEnabled, mcpCanvasGroupsEnabled } = this.globalConfig.endpoints;
const flags = mcpAppsEnabled && mcpCanvasGroupsEnabled
? undefined
: await this.postHogClient.getFeatureFlags(user);
return {
mcpApps: this.resolveMcpApps(mcpAppsEnabled, flags),
canvasGroupsEnabled: mcpCanvasGroupsEnabled || flags?.[api_types_1.MCP_CANVAS_GROUPS_FLAG] === true,
};
}
resolveMcpApps(envOverride, flags) {
if (envOverride)
return { enabled: true, variant: 'env_override' };
const raw = flags?.[api_types_1.MCP_APPS_FLAG];
if (raw === api_types_1.MCP_APPS_VARIANT_ENABLED)
return { enabled: true, variant: 'variant' };
if (raw === api_types_1.MCP_APPS_VARIANT_CONTROL)
return { enabled: false, variant: 'control' };
return { enabled: false, variant: 'unassigned' };
}
buildMcpAppTelemetryConfig() {
const { enabled, frontendConfig } = this.globalConfig.diagnostics;
const disabledTelemetry = {
enabled: false,
writeKey: '',
dataPlaneUrl: '',
configUrl: '',
instanceId: this.instanceSettings.instanceId,
versionCli: constants_1.N8N_VERSION,
};
if (!enabled)
return { telemetry: disabledTelemetry };
const instanceBaseUrl = this.urlService.getInstanceBaseUrl();
const restEndpoint = this.globalConfig.endpoints.rest;
const [writeKey] = frontendConfig.split(';');
const telemetry = {
enabled,
writeKey: writeKey ?? '',
dataPlaneUrl: `${instanceBaseUrl}/${restEndpoint}/telemetry/proxy`,
configUrl: `${instanceBaseUrl}/${restEndpoint}/telemetry/rudderstack`,
instanceId: this.instanceSettings.instanceId,
versionCli: constants_1.N8N_VERSION,
};
try {
return { telemetry, instanceOrigin: new URL(telemetry.dataPlaneUrl).origin };
}
catch {
this.logger.warn('Disabling MCP app telemetry because telemetry proxy URL is invalid', {
dataPlaneUrl: telemetry.dataPlaneUrl,
});
return {
telemetry: disabledTelemetry,
};
}
}
createToolRegistrar(server, user, clientInfo) {
return (tool) => {
const invoke = tool.handler;
const instrumentedHandler = async (...handlerArgs) => {
const workflowId = getWorkflowId(handlerArgs[0]);
try {
const result = await invoke(...handlerArgs);
const { status, errorMessage } = getToolCallOutcome(result);
this.eventService.emit('mcp-tool-called', {
user,
toolName: tool.name,
workflowId: workflowId ?? getWorkflowId(result?.structuredContent),
status,
errorMessage,
clientName: clientInfo?.name,
});
return result;
}
catch (error) {
this.eventService.emit('mcp-tool-called', {
user,
toolName: tool.name,
workflowId,
status: 'error',
errorMessage: error instanceof Error ? error.message : String(error),
clientName: clientInfo?.name,
});
throw error;
}
};
const { inputSchema, outputSchema, ...config } = tool.config;
return server.registerTool(tool.name, {
...config,
...(inputSchema ? { inputSchema: (0, tool_schema_util_1.shapeToStandardSchema)(inputSchema) } : {}),
...(outputSchema ? { outputSchema: (0, tool_schema_util_1.shapeToStandardSchema)(outputSchema) } : {}),
}, instrumentedHandler);
};
}
createResourceRegistrar(server) {
return (resource) => server.registerResource(resource.name, resource.uri, resource.config, resource.read);
}
async getServer(user, featureFlags, clientInfo, grantedScopes) {
const { McpServer } = await (0, lazy_import_1.lazyImport)(async () => await import('@modelcontextprotocol/server'));
const builderEnabled = this.globalConfig.endpoints.mcpBuilderEnabled;
const n8nConnectAvailable = builderEnabled
? (await this.aiGatewayService.isAvailable()).available
: false;
const allowedToolNames = (0, mcp_scopes_1.getAllowedToolNames)(grantedScopes);
const builderInstructionsEnabled = builderEnabled &&
(allowedToolNames?.has(constants_2.MCP_CREATE_WORKFLOW_FROM_CODE_TOOL.toolName) ?? true);
const agentsEnabled = (0, mcp_tool_availability_1.areAgentToolsAvailable)(this.globalConfig, this.moduleRegistry);
const agentInstructionsEnabled = agentsEnabled && (allowedToolNames?.has(mcp_constants_1.MCP_CREATE_AGENT_TOOL_NAME) ?? true);
const server = new McpServer({
name: 'n8n MCP Server',
version: agentsEnabled ? '1.2.0' : builderEnabled ? '1.1.0' : '1.0.0',
}, {
instructions: (0, mcp_instructions_1.getMcpInstructions)({
isBuilderEnabled: builderInstructionsEnabled,
isN8nConnectAvailable: n8nConnectAvailable,
canvasGroupsEnabled: featureFlags.canvasGroupsEnabled,
isAgentsEnabled: agentInstructionsEnabled,
}),
});
const registerTool = this.createToolRegistrar(server, user, clientInfo);
const registerResource = this.createResourceRegistrar(server);
const registerIfAllowed = (tool) => {
if (allowedToolNames && !allowedToolNames.has(tool.name))
return;
registerTool(tool);
};
const workflowSearchTool = (0, search_workflows_tool_1.createSearchWorkflowsTool)(user, this.workflowService, this.telemetry);
registerIfAllowed(workflowSearchTool);
const executeWorkflowTool = (0, execute_workflow_tool_1.createExecuteWorkflowTool)(user, this.workflowFinderService, this.workflowRunner, this.telemetry, this, this.workflowsConfig, this.workflowPublishedDataService);
registerIfAllowed(executeWorkflowTool);
const getExecutionTool = (0, get_execution_tool_1.createGetExecutionTool)(user, this.executionRepository, this.workflowFinderService, this.telemetry);
registerIfAllowed(getExecutionTool);
const searchExecutionsTool = (0, search_executions_tool_1.createSearchExecutionsTool)(user, this.executionService, this.workflowFinderService, this.telemetry);
registerIfAllowed(searchExecutionsTool);
const workflowDetailsTool = (0, get_workflow_details_tool_1.createWorkflowDetailsTool)(user, this.urlService.getWebhookBaseUrl(), this.workflowFinderService, this.credentialsService, this.nodeTypes, {
webhook: this.globalConfig.endpoints.webhook,
webhookTest: this.globalConfig.endpoints.webhookTest,
}, this.telemetry, this.roleService, this.projectService, this.urlService.getTestWebhookBaseUrl());
registerIfAllowed(workflowDetailsTool);
const workflowHistoryTool = (0, get_workflow_history_tool_1.createGetWorkflowHistoryTool)(user, this.workflowFinderService, this.workflowHistoryService, this.telemetry);
registerIfAllowed(workflowHistoryTool);
const workflowVersionTool = (0, get_workflow_version_tool_1.createGetWorkflowVersionTool)(user, this.workflowFinderService, this.workflowHistoryService, this.telemetry);
registerIfAllowed(workflowVersionTool);
const publishWorkflowTool = (0, publish_workflow_tool_1.createPublishWorkflowTool)(user, this.workflowFinderService, this.workflowService, this.telemetry, this.collaborationService);
registerIfAllowed(publishWorkflowTool);
const unpublishWorkflowTool = (0, unpublish_workflow_tool_1.createUnpublishWorkflowTool)(user, this.workflowFinderService, this.workflowService, this.telemetry, this.collaborationService);
registerIfAllowed(unpublishWorkflowTool);
const prepareTestPinDataTool = (0, prepare_workflow_pin_data_tool_1.createPrepareTestPinDataTool)(user, this.workflowFinderService, this.executionService, this.nodeTypes, this.telemetry, this.logger);
registerIfAllowed(prepareTestPinDataTool);
const testWorkflowTool = (0, test_workflow_tool_1.createTestWorkflowTool)(user, this.workflowFinderService, this.activeExecutions, this.workflowRunner, this.nodeTypes, this.telemetry, this);
registerIfAllowed(testWorkflowTool);
const listCredentialsTool = (0, list_credentials_tool_1.createListCredentialsTool)(user, this.credentialsService, this.telemetry, this.aiGatewayService);
const listN8nConnectServicesTool = (0, list_n8n_connect_services_tool_1.createListN8nConnectServicesTool)(user, this.aiGatewayService, this.telemetry);
registerIfAllowed(listCredentialsTool);
registerIfAllowed(listN8nConnectServicesTool);
if (!this.globalConfig.tags.disabled) {
const listTagsTool = (0, list_tags_tool_1.createListTagsTool)(user, this.tagService, this.telemetry);
registerIfAllowed(listTagsTool);
}
const dataTableOps = this.dataTableProxyService.makeDataTableOperationsForUser(user);
const searchDataTablesTool = (0, data_table_1.createSearchDataTablesTool)(user, dataTableOps, this.telemetry);
registerIfAllowed(searchDataTablesTool);
const createDataTableTool = (0, data_table_1.createCreateDataTableTool)(user, dataTableOps, this.telemetry);
registerIfAllowed(createDataTableTool);
const renameDataTableTool = (0, data_table_1.createRenameDataTableTool)(user, dataTableOps, this.telemetry);
registerIfAllowed(renameDataTableTool);
const addDataTableColumnTool = (0, data_table_1.createAddDataTableColumnTool)(user, dataTableOps, this.telemetry);
registerIfAllowed(addDataTableColumnTool);
const deleteDataTableColumnTool = (0, data_table_1.createDeleteDataTableColumnTool)(user, dataTableOps, this.telemetry);
registerIfAllowed(deleteDataTableColumnTool);
const renameDataTableColumnTool = (0, data_table_1.createRenameDataTableColumnTool)(user, dataTableOps, this.telemetry);
registerIfAllowed(renameDataTableColumnTool);
const addDataTableRowsTool = (0, data_table_1.createAddDataTableRowsTool)(user, dataTableOps, this.telemetry);
registerIfAllowed(addDataTableRowsTool);
if (builderEnabled) {
await this.registerBuilderTools(server, user, dataTableOps, featureFlags, registerIfAllowed, registerResource, allowedToolNames, clientInfo);
}
if (agentsEnabled) {
const { McpAgentToolsService } = await import('./tools/agents/agent-tools.service.js');
di_1.Container.get(McpAgentToolsService).registerTools(registerIfAllowed, registerResource, user, allowedToolNames);
}
return server;
}
async registerBuilderTools(server, user, dataTableOps, featureFlags, registerIfAllowed, registerResource, allowedToolNames, clientInfo) {
await this.nodeCatalogService.initialize();
const searchNodesTool = (0, search_workflow_nodes_tool_1.createSearchWorkflowNodesTool)(user, this.nodeCatalogService, this.telemetry, this.aiGatewayService);
registerIfAllowed(searchNodesTool);
const getNodeTypesTool = (0, get_workflow_node_types_tool_1.createGetWorkflowNodeTypesTool)(user, this.nodeCatalogService, this.telemetry, this.aiGatewayService);
registerIfAllowed(getNodeTypesTool);
const bestPracticesTool = (0, get_workflow_best_practices_tool_1.createGetWorkflowBestPracticesTool)(user, this.telemetry, {
canvasGroupsEnabled: featureFlags.canvasGroupsEnabled,
});
registerIfAllowed(bestPracticesTool);
const exploreNodeResourcesTool = (0, explore_node_resources_tool_1.createExploreNodeResourcesTool)(user, this.nodeResourceExplorerService, this.telemetry);
registerIfAllowed(exploreNodeResourcesTool);
const validateTool = (0, validate_workflow_code_tool_1.createValidateWorkflowCodeTool)(user, this.telemetry, this.nodeTypes, {
canvasGroupsEnabled: featureFlags.canvasGroupsEnabled,
});
registerIfAllowed(validateTool);
const validateNodeTool = (0, validate_node_tool_1.createValidateNodeTool)(user, this.telemetry);
registerIfAllowed(validateNodeTool);
const createTool = (0, create_workflow_from_code_tool_1.createCreateWorkflowFromCodeTool)(user, this.workflowCreationService, this.workflowFinderService, this.urlService, this.telemetry, this.nodeTypes, this.credentialsService, this.projectRepository, dataTableOps, this.aiGatewayService, { canvasGroupsEnabled: featureFlags.canvasGroupsEnabled });
const createToolAllowed = !allowedToolNames || allowedToolNames.has(createTool.name);
if (featureFlags.mcpApps.enabled && createToolAllowed) {
const appTelemetry = this.buildMcpAppTelemetryConfig();
(0, server_1.registerWorkflowPreviewApp)(server, {
instanceOrigin: appTelemetry.instanceOrigin,
telemetry: appTelemetry.telemetry,
onResourceRead: () => {
this.telemetry.track(mcp_constants_1.MCP_PREVIEW_RENDER_REQUESTED_EVENT, {
user_id: user.id,
client_name: clientInfo?.name,
client_version: clientInfo?.version,
});
},
});
registerIfAllowed({
...createTool,
config: {
...createTool.config,
_meta: (0, server_1.mcpAppToolMeta)(server_1.WORKFLOW_PREVIEW_APP_URI),
},
});
}
else {
registerIfAllowed(createTool);
}
const searchProjectsTool = (0, search_projects_tool_1.createSearchProjectsTool)(user, this.projectRepository, this.licenseState, this.telemetry);
registerIfAllowed(searchProjectsTool);
const searchFoldersTool = (0, search_folders_tool_1.createSearchFoldersTool)(user, this.folderRepository, this.projectService, this.telemetry);
registerIfAllowed(searchFoldersTool);
const archiveTool = (0, delete_workflow_tool_1.createArchiveWorkflowTool)(user, this.workflowFinderService, this.workflowService, this.telemetry, this.collaborationService);
registerIfAllowed(archiveTool);
const updateTool = (0, update_workflow_tool_1.createUpdateWorkflowTool)(user, this.workflowFinderService, this.workflowService, this.urlService, this.telemetry, this.nodeTypes, this.credentialsService, this.sharedWorkflowRepository, this.collaborationService, dataTableOps, this.tagService, this.globalConfig, this.subworkflowPolicyChecker, this.workflowPublishedDataService, this.aiGatewayService, { canvasGroupsEnabled: featureFlags.canvasGroupsEnabled });
registerIfAllowed(updateTool);
const restoreVersionTool = (0, restore_workflow_version_tool_1.createRestoreWorkflowVersionTool)(user, this.workflowFinderService, this.workflowHistoryService, this.workflowService, this.telemetry, this.collaborationService);
registerIfAllowed(restoreVersionTool);
registerResource({
name: 'workflow-sdk-reference',
uri: 'n8n://workflow-sdk/reference',
config: {
description: 'Required n8n Workflow SDK reference for building workflows from code. Read this before writing workflow code.',
},
read: () => ({
contents: [
{
uri: 'n8n://workflow-sdk/reference',
mimeType: 'text/plain',
text: (0, sdk_reference_content_1.getSdkReferenceContent)(undefined, {
includeGroups: featureFlags.canvasGroupsEnabled,
}),
},
],
}),
});
const sdkRefTool = (0, get_workflow_sdk_reference_tool_1.createGetWorkflowSdkReferenceTool)(user, this.telemetry, {
canvasGroupsEnabled: featureFlags.canvasGroupsEnabled,
});
registerIfAllowed(sdkRefTool);
}
get isQueueMode() {
return this.executionsConfig.mode === 'queue';
}
createPendingResponse(executionId) {
const deferred = (0, deferred_promise_1.createDeferredPromise)();
this.pendingResponses.set(executionId, {
executionId,
promise: deferred,
createdAt: new Date(),
});
return deferred;
}
handleWorkerResponse(executionId, runData) {
const pending = this.pendingResponses.get(executionId);
if (!pending) {
this.logger.warn('Received MCP response for unknown execution', { executionId });
return;
}
pending.promise.resolve(runData);
this.pendingResponses.delete(executionId);
}
removePendingResponse(executionId) {
if (this.pendingResponses.has(executionId)) {
this.pendingResponses.delete(executionId);
this.logger.debug('Removed pending MCP response', { executionId });
}
}
cancelPendingExecution(executionId, reason = 'MCP execution cancelled') {
const pending = this.pendingResponses.get(executionId);
if (!pending) {
this.logger.debug('No pending MCP execution to cancel', { executionId });
return;
}
this.logger.debug('Cancelling pending MCP execution', { executionId, reason });
const cancellationError = new n8n_workflow_1.ManualExecutionCancelledError(executionId);
pending.promise.reject(cancellationError);
this.pendingResponses.delete(executionId);
if (this.activeExecutions.has(executionId)) {
this.activeExecutions.stopExecution(executionId, cancellationError);
}
}
cancelAllPendingExecutions(reason = 'MCP service shutdown') {
const executionIds = Array.from(this.pendingResponses.keys());
this.logger.debug('Cancelling all pending MCP executions', {
count: executionIds.length,
reason,
});
for (const executionId of executionIds) {
this.cancelPendingExecution(executionId, reason);
}
}
get pendingExecutionCount() {
return this.pendingResponses.size;
}
};
exports.McpService = McpService;
exports.McpService = McpService = __decorate([
(0, di_1.Service)(),
__metadata("design:paramtypes", [backend_common_1.Logger, config_1.ExecutionsConfig, n8n_core_1.InstanceSettings, workflow_finder_service_1.WorkflowFinderService, workflow_service_1.WorkflowService, url_service_1.UrlService, credentials_service_1.CredentialsService, active_executions_1.ActiveExecutions, config_1.GlobalConfig, telemetry_1.Telemetry, workflow_runner_1.WorkflowRunner, role_service_1.RoleService, project_service_ee_1.ProjectService, node_catalog_1.NodeCatalogService, workflow_creation_service_1.WorkflowCreationService, node_types_1.NodeTypes, db_1.ProjectRepository, db_1.FolderRepository, db_1.SharedWorkflowRepository, db_1.ExecutionRepository, execution_service_1.ExecutionService, data_table_proxy_service_1.DataTableProxyService, collaboration_service_1.CollaborationService, node_resource_explorer_service_1.NodeResourceExplorerService, tag_service_1.TagService, backend_common_1.LicenseState, posthog_1.PostHogClient, workflow_history_service_1.WorkflowHistoryService, config_1.WorkflowsConfig, workflow_published_data_service_1.WorkflowPublishedDataService, subworkflow_policy_checker_1.SubworkflowPolicyChecker, ai_gateway_service_1.AiGatewayService, backend_common_1.ModuleRegistry, event_service_1.EventService])
], McpService);
//# sourceMappingURL=mcp.service.js.map