UNPKG

@n8n/n8n-nodes-langchain

Version:
201 lines 8.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.McpRegistryClientTool = void 0; const n8n_workflow_1 = require("n8n-workflow"); const runtime_1 = require("../shared/runtime"); class McpRegistryClientTool { constructor() { this.description = { displayName: 'MCP Registry Client (internal)', name: 'mcpRegistryClientTool', hidden: true, group: ['output'], version: [1, 1.1], defaultVersion: 1.1, description: 'Runtime backing for MCP registry-derived nodes', defaults: { name: 'MCP Registry Client', }, codex: { categories: ['AI'], subcategories: { AI: ['Model Context Protocol'], }, alias: ['MCP', 'Model Context Protocol'], }, inputs: [], outputs: [{ type: n8n_workflow_1.NodeConnectionTypes.AiTool, displayName: 'Tools' }], credentials: [ { name: 'mcpOAuth2Api', required: true, }, ], properties: [ { displayName: 'Endpoint URL', name: 'endpointUrl', type: 'hidden', default: '', }, { displayName: 'Server Transport', name: 'serverTransport', type: 'hidden', default: 'httpStreamable', }, { displayName: 'Tools to Include', name: 'include', type: 'options', description: 'How to select the tools you want to be exposed to the AI Agent', default: 'all', options: [ { name: 'All', value: 'all', description: 'Expose every tool from the MCP server', }, { name: 'Selected', value: 'selected', description: 'Only expose the tools listed in "Tools to Include"', }, { name: 'All Except', value: 'except', description: 'Expose all tools except those listed in "Tools to Exclude"', }, ], }, { displayName: 'Tools to Include', name: 'includeTools', type: 'multiOptions', default: [], description: 'Tools from the MCP server to expose to the agent. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.', typeOptions: { loadOptionsMethod: 'getTools', }, displayOptions: { show: { include: ['selected'], }, }, }, { displayName: 'Tools to Exclude', name: 'excludeTools', type: 'multiOptions', default: [], description: 'Tools from the MCP server to hide from the agent. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.', typeOptions: { loadOptionsMethod: 'getTools', }, displayOptions: { show: { include: ['except'], }, }, }, { displayName: 'Options', name: 'options', placeholder: 'Add Option', description: 'Additional options to add', type: 'collection', default: {}, options: [ { displayName: 'Timeout', name: 'timeout', type: 'number', typeOptions: { minValue: 1, }, default: 60000, description: 'Time in ms to wait for tool calls to finish', }, ], }, ], }; this.methods = { loadOptions: { async getTools() { const selector = this.getNodeParameter('authentication', ''); const resolved = McpRegistryClientTool.getConnection(this.getNode(), selector); const authentication = getCredentialType(this, resolved); return await (0, runtime_1.loadMcpToolOptions)(this, { authentication, transport: resolved.connection.transport, endpointUrl: (0, n8n_workflow_1.getConfiguredEndpointUrl)(resolved.connection), registryCredential: { connection: resolved.connection, credentialType: authentication, prepareConnection: (input) => McpRegistryClientTool.prepareConnection(input), }, timeout: this.getNodeParameter('options.timeout', 60000), }); }, }, }; } setRegistryRuntime(runtime) { McpRegistryClientTool.registryRuntime = runtime; } static getConnection(node, selector) { const resolved = this.registryRuntime?.resolveConnection(node.type, selector); if (resolved) return resolved; throw new n8n_workflow_1.NodeOperationError(node, 'MCP registry connection is not registered'); } static prepareConnection(input) { return (this.registryRuntime?.prepareConnection(input) ?? { ok: false, error: { code: 'not_registered', message: 'MCP registry connection is not registered', }, }); } async supplyData(itemIndex) { return await (0, runtime_1.buildMcpToolkit)(this, itemIndex, resolveConfig(this, itemIndex)); } async execute() { return await (0, runtime_1.executeMcpTool)(this, (itemIndex) => resolveConfig(this, itemIndex), { enableSessionCache: this.getNode().typeVersion >= 1.1, }); } } exports.McpRegistryClientTool = McpRegistryClientTool; function resolveConfig(ctx, itemIndex) { const selector = ctx.getNodeParameter('authentication', itemIndex, ''); const resolved = McpRegistryClientTool.getConnection(ctx.getNode(), selector); const authentication = getCredentialType(ctx, resolved); return { authentication, transport: resolved.connection.transport, endpointUrl: (0, n8n_workflow_1.getConfiguredEndpointUrl)(resolved.connection), registryCredential: { connection: resolved.connection, credentialType: authentication, prepareConnection: (input) => McpRegistryClientTool.prepareConnection(input), }, timeout: ctx.getNodeParameter('options.timeout', itemIndex, 60000), toolFilter: { mode: ctx.getNodeParameter('include', itemIndex), includeTools: ctx.getNodeParameter('includeTools', itemIndex, []), excludeTools: ctx.getNodeParameter('excludeTools', itemIndex, []), }, }; } function getCredentialType(ctx, resolved) { const node = ctx.getNode(); const { credentialType } = resolved.binding; if (!Object.hasOwn(node.credentials ?? {}, credentialType)) { throw new n8n_workflow_1.NodeOperationError(node, 'No MCP credential found'); } return credentialType; } //# sourceMappingURL=McpRegistryClientTool.node.js.map