UNPKG

n8n

Version:

n8n Workflow Automation Tool

105 lines 4.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.McpRegistryNodeLoader = void 0; const change_case_1 = require("change-case"); const n8n_core_1 = require("n8n-core"); const n8n_workflow_1 = require("n8n-workflow"); const node_description_transform_1 = require("./node-description-transform"); class McpRegistryNodeLoader { constructor(registry, loadNodesAndCredentials, logger) { this.registry = registry; this.loadNodesAndCredentials = loadNodesAndCredentials; this.logger = logger; this.packageName = node_description_transform_1.MCP_REGISTRY_PACKAGE_NAME; this.known = { nodes: {}, credentials: {} }; this.types = { nodes: [], credentials: [], }; this.nodeTypes = {}; this.credentialTypes = {}; this.typesReleased = true; } async loadAll() { this.reset(); const baseLoaded = this.resolveBaseNode(); this.typesReleased = false; if (!baseLoaded) return; const { type: baseNode, sourcePath } = baseLoaded; const { description: baseDescription } = n8n_workflow_1.NodeHelpers.getVersionedNodeType(baseNode); for (const server of this.registry.getAll({ includeDeprecated: true })) { const nodeDescription = (0, node_description_transform_1.serverToNodeDescription)(server, baseDescription); const credentialDescription = (0, node_description_transform_1.serverToCredentialDescription)(server); if (!nodeDescription || !credentialDescription) continue; const bareName = (0, change_case_1.camelCase)(server.slug); this.types.nodes.push(nodeDescription); const syntheticNode = Object.create(baseNode, { description: { value: nodeDescription, enumerable: true }, }); this.nodeTypes[bareName] = { type: syntheticNode, sourcePath }; this.known.nodes[bareName] = { className: 'McpRegistryClientTool', sourcePath, }; this.types.credentials.push(credentialDescription); this.credentialTypes[credentialDescription.name] = { type: credentialDescription, sourcePath: '', }; this.known.credentials[credentialDescription.name] = { className: 'McpRegistryApi', sourcePath: '', extends: credentialDescription.extends, supportedNodes: [bareName], }; } } getNode(nodeType) { const entry = this.nodeTypes[nodeType]; if (!entry) throw new n8n_core_1.UnrecognizedNodeTypeError(this.packageName, nodeType); return entry; } getCredential(credentialType) { const entry = this.credentialTypes[credentialType]; if (!entry) throw new n8n_core_1.UnrecognizedCredentialTypeError(credentialType); return entry; } reset() { this.known = { nodes: {}, credentials: {} }; this.types = { nodes: [], credentials: [] }; this.nodeTypes = {}; this.credentialTypes = {}; this.typesReleased = true; } releaseTypes() { this.types = { nodes: [], credentials: [] }; this.typesReleased = true; } async ensureTypesLoaded() { if (this.typesReleased) await this.loadAll(); } resolveSourcePath(sourcePath) { return sourcePath; } resolveBaseNode() { const langchainLoader = this.loadNodesAndCredentials.loaders[node_description_transform_1.LANGCHAIN_PACKAGE_NAME]; if (!langchainLoader) { this.logger.warn(`McpRegistryNodeLoader: langchain package "${node_description_transform_1.LANGCHAIN_PACKAGE_NAME}" is not loaded; registry nodes will not be available.`); return undefined; } try { return langchainLoader.getNode(node_description_transform_1.MCP_REGISTRY_BASE_NODE_NAME); } catch (error) { this.logger.warn(`McpRegistryNodeLoader: failed to resolve base node "${node_description_transform_1.MCP_REGISTRY_BASE_NODE_NAME}"`, { error: (0, n8n_workflow_1.ensureError)(error) }); return undefined; } } } exports.McpRegistryNodeLoader = McpRegistryNodeLoader; //# sourceMappingURL=mcp-registry-node-loader.js.map