@n8n/n8n-nodes-langchain 1.119.0 → 1.120.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/credentials/AzureAiSearchApi.credentials.js +75 -0
- package/dist/credentials/AzureAiSearchApi.credentials.js.map +1 -0
- package/dist/known/credentials.json +7 -0
- package/dist/known/nodes.json +4 -0
- package/dist/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.js +8 -0
- package/dist/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.js.map +1 -1
- package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js +23 -7
- package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js.map +1 -1
- package/dist/nodes/mcp/McpClientTool/types.js.map +1 -1
- package/dist/nodes/mcp/McpClientTool/utils.js +20 -2
- package/dist/nodes/mcp/McpClientTool/utils.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/Chat.node.js +29 -2
- package/dist/nodes/trigger/ChatTrigger/Chat.node.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js +2 -0
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.js +340 -0
- package/dist/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreAzureAISearch/azure-aisearch.svg +1 -0
- package/dist/types/credentials.json +1 -0
- package/dist/types/nodes.json +3 -2
- package/dist/utils/httpProxyAgent.js +11 -2
- package/dist/utils/httpProxyAgent.js.map +1 -1
- package/package.json +16 -13
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var AzureAiSearchApi_credentials_exports = {};
|
|
20
|
+
__export(AzureAiSearchApi_credentials_exports, {
|
|
21
|
+
AzureAiSearchApi: () => AzureAiSearchApi
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(AzureAiSearchApi_credentials_exports);
|
|
24
|
+
class AzureAiSearchApi {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.name = "azureAiSearchApi";
|
|
27
|
+
this.displayName = "Azure AI Search API";
|
|
28
|
+
this.documentationUrl = "azureaisearch";
|
|
29
|
+
this.properties = [
|
|
30
|
+
{
|
|
31
|
+
displayName: "Search Endpoint",
|
|
32
|
+
name: "endpoint",
|
|
33
|
+
type: "string",
|
|
34
|
+
required: true,
|
|
35
|
+
default: "",
|
|
36
|
+
placeholder: "https://your-search-service.search.windows.net"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
displayName: "API Key",
|
|
40
|
+
name: "apiKey",
|
|
41
|
+
type: "string",
|
|
42
|
+
typeOptions: { password: true },
|
|
43
|
+
required: true,
|
|
44
|
+
default: ""
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
this.authenticate = async (credentials, requestOptions) => {
|
|
48
|
+
return {
|
|
49
|
+
...requestOptions,
|
|
50
|
+
headers: {
|
|
51
|
+
...requestOptions.headers,
|
|
52
|
+
"api-key": credentials.apiKey
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
this.test = {
|
|
57
|
+
request: {
|
|
58
|
+
baseURL: "={{$credentials.endpoint}}/indexes",
|
|
59
|
+
url: "",
|
|
60
|
+
method: "GET",
|
|
61
|
+
headers: {
|
|
62
|
+
accept: "application/json"
|
|
63
|
+
},
|
|
64
|
+
qs: {
|
|
65
|
+
"api-version": "2024-07-01"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
AzureAiSearchApi
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=AzureAiSearchApi.credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../credentials/AzureAiSearchApi.credentials.ts"],"sourcesContent":["import type {\n\tICredentialDataDecryptedObject,\n\tICredentialTestRequest,\n\tICredentialType,\n\tIHttpRequestOptions,\n\tINodeProperties,\n} from 'n8n-workflow';\n\nexport class AzureAiSearchApi implements ICredentialType {\n\tname = 'azureAiSearchApi';\n\n\tdisplayName = 'Azure AI Search API';\n\n\tdocumentationUrl = 'azureaisearch';\n\n\tproperties: INodeProperties[] = [\n\t\t{\n\t\t\tdisplayName: 'Search Endpoint',\n\t\t\tname: 'endpoint',\n\t\t\ttype: 'string',\n\t\t\trequired: true,\n\t\t\tdefault: '',\n\t\t\tplaceholder: 'https://your-search-service.search.windows.net',\n\t\t},\n\t\t{\n\t\t\tdisplayName: 'API Key',\n\t\t\tname: 'apiKey',\n\t\t\ttype: 'string',\n\t\t\ttypeOptions: { password: true },\n\t\t\trequired: true,\n\t\t\tdefault: '',\n\t\t},\n\t];\n\n\tauthenticate = async (\n\t\tcredentials: ICredentialDataDecryptedObject,\n\t\trequestOptions: IHttpRequestOptions,\n\t): Promise<IHttpRequestOptions> => {\n\t\treturn {\n\t\t\t...requestOptions,\n\t\t\theaders: {\n\t\t\t\t...requestOptions.headers,\n\t\t\t\t'api-key': credentials.apiKey,\n\t\t\t},\n\t\t};\n\t};\n\n\ttest: ICredentialTestRequest = {\n\t\trequest: {\n\t\t\tbaseURL: '={{$credentials.endpoint}}/indexes',\n\t\t\turl: '',\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\taccept: 'application/json',\n\t\t\t},\n\t\t\tqs: {\n\t\t\t\t'api-version': '2024-07-01',\n\t\t\t},\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,MAAM,iBAA4C;AAAA,EAAlD;AACN,gBAAO;AAEP,uBAAc;AAEd,4BAAmB;AAEnB,sBAAgC;AAAA,MAC/B;AAAA,QACC,aAAa;AAAA,QACb,MAAM;AAAA,QACN,MAAM;AAAA,QACN,UAAU;AAAA,QACV,SAAS;AAAA,QACT,aAAa;AAAA,MACd;AAAA,MACA;AAAA,QACC,aAAa;AAAA,QACb,MAAM;AAAA,QACN,MAAM;AAAA,QACN,aAAa,EAAE,UAAU,KAAK;AAAA,QAC9B,UAAU;AAAA,QACV,SAAS;AAAA,MACV;AAAA,IACD;AAEA,wBAAe,OACd,aACA,mBACkC;AAClC,aAAO;AAAA,QACN,GAAG;AAAA,QACH,SAAS;AAAA,UACR,GAAG,eAAe;AAAA,UAClB,WAAW,YAAY;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAEA,gBAA+B;AAAA,MAC9B,SAAS;AAAA,QACR,SAAS;AAAA,QACT,KAAK;AAAA,QACL,QAAQ;AAAA,QACR,SAAS;AAAA,UACR,QAAQ;AAAA,QACT;AAAA,QACA,IAAI;AAAA,UACH,eAAe;AAAA,QAChB;AAAA,MACD;AAAA,IACD;AAAA;AACD;","names":[]}
|
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
"lmChatAnthropic"
|
|
8
8
|
]
|
|
9
9
|
},
|
|
10
|
+
"azureAiSearchApi": {
|
|
11
|
+
"className": "AzureAiSearchApi",
|
|
12
|
+
"sourcePath": "dist/credentials/AzureAiSearchApi.credentials.js",
|
|
13
|
+
"supportedNodes": [
|
|
14
|
+
"vectorStoreAzureAISearch"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
10
17
|
"azureOpenAiApi": {
|
|
11
18
|
"className": "AzureOpenAiApi",
|
|
12
19
|
"sourcePath": "dist/credentials/AzureOpenAiApi.credentials.js",
|
package/dist/known/nodes.json
CHANGED
|
@@ -331,6 +331,10 @@
|
|
|
331
331
|
"className": "Chat",
|
|
332
332
|
"sourcePath": "dist/nodes/trigger/ChatTrigger/Chat.node.js"
|
|
333
333
|
},
|
|
334
|
+
"vectorStoreAzureAISearch": {
|
|
335
|
+
"className": "VectorStoreAzureAISearch",
|
|
336
|
+
"sourcePath": "dist/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.js"
|
|
337
|
+
},
|
|
334
338
|
"vectorStoreInMemory": {
|
|
335
339
|
"className": "VectorStoreInMemory",
|
|
336
340
|
"sourcePath": "dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js"
|
|
@@ -23,6 +23,7 @@ __export(EmbeddingsAzureOpenAi_node_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(EmbeddingsAzureOpenAi_node_exports);
|
|
24
24
|
var import_openai = require("@langchain/openai");
|
|
25
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
26
|
+
var import_httpProxyAgent = require("../../../utils/httpProxyAgent");
|
|
26
27
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
27
28
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
28
29
|
class EmbeddingsAzureOpenAi {
|
|
@@ -149,6 +150,13 @@ class EmbeddingsAzureOpenAi {
|
|
|
149
150
|
// azureOpenAIEndpoint and configuration.baseURL are both ignored here
|
|
150
151
|
// only setting azureOpenAIBasePath worked
|
|
151
152
|
azureOpenAIBasePath: credentials.endpoint ? `${credentials.endpoint}/openai/deployments` : void 0,
|
|
153
|
+
configuration: {
|
|
154
|
+
fetchOptions: {
|
|
155
|
+
dispatcher: (0, import_httpProxyAgent.getProxyAgent)(
|
|
156
|
+
credentials.endpoint ?? `https://${credentials.resourceName}.openai.azure.com`
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
},
|
|
152
160
|
...options
|
|
153
161
|
});
|
|
154
162
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts"],"sourcesContent":["import { AzureOpenAIEmbeddings } from '@langchain/openai';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nexport class EmbeddingsAzureOpenAi implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Embeddings Azure OpenAI',\n\t\tname: 'embeddingsAzureOpenAi',\n\t\ticon: 'file:azure.svg',\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'azureOpenAiApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Use Embeddings Azure OpenAI',\n\t\tdefaults: {\n\t\t\tname: 'Embeddings Azure OpenAI',\n\t\t},\n\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Embeddings'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.embeddingsazureopenai/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiEmbedding],\n\t\toutputNames: ['Embeddings'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiVectorStore]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Model (Deployment) Name',\n\t\t\t\tname: 'model',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'The name of the model(deployment) to use',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Batch Size',\n\t\t\t\t\t\tname: 'batchSize',\n\t\t\t\t\t\tdefault: 512,\n\t\t\t\t\t\ttypeOptions: { maxValue: 2048 },\n\t\t\t\t\t\tdescription: 'Maximum number of documents to send in each request',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Strip New Lines',\n\t\t\t\t\t\tname: 'stripNewLines',\n\t\t\t\t\t\tdefault: true,\n\t\t\t\t\t\tdescription: 'Whether to strip new lines from the input text',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Timeout',\n\t\t\t\t\t\tname: 'timeout',\n\t\t\t\t\t\tdefault: -1,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Maximum amount of time a request is allowed to take in seconds. Set to -1 for no timeout.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Dimensions',\n\t\t\t\t\t\tname: 'dimensions',\n\t\t\t\t\t\tdefault: undefined,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: '256',\n\t\t\t\t\t\t\t\tvalue: 256,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: '512',\n\t\t\t\t\t\t\t\tvalue: 512,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: '1024',\n\t\t\t\t\t\t\t\tvalue: 1024,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: '1536',\n\t\t\t\t\t\t\t\tvalue: 1536,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: '3072',\n\t\t\t\t\t\t\t\tvalue: 3072,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supply data for embeddings');\n\t\tconst credentials = await this.getCredentials<{\n\t\t\tapiKey: string;\n\t\t\tresourceName: string;\n\t\t\tapiVersion: string;\n\t\t\tendpoint?: string;\n\t\t}>('azureOpenAiApi');\n\t\tconst modelName = this.getNodeParameter('model', itemIndex) as string;\n\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\tbatchSize?: number;\n\t\t\tstripNewLines?: boolean;\n\t\t\ttimeout?: number;\n\t\t\tdimensions?: number | undefined;\n\t\t};\n\n\t\tif (options.timeout === -1) {\n\t\t\toptions.timeout = undefined;\n\t\t}\n\n\t\tconst embeddings = new AzureOpenAIEmbeddings({\n\t\t\tazureOpenAIApiDeploymentName: modelName,\n\t\t\t// instance name only needed to set base url\n\t\t\tazureOpenAIApiInstanceName: !credentials.endpoint ? credentials.resourceName : undefined,\n\t\t\tazureOpenAIApiKey: credentials.apiKey,\n\t\t\tazureOpenAIApiVersion: credentials.apiVersion,\n\t\t\t// azureOpenAIEndpoint and configuration.baseURL are both ignored here\n\t\t\t// only setting azureOpenAIBasePath worked\n\t\t\tazureOpenAIBasePath: credentials.endpoint\n\t\t\t\t? `${credentials.endpoint}/openai/deployments`\n\t\t\t\t: undefined,\n\t\t\t...options,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(embeddings, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAsC;AACtC,0BAMO;AAEP,wBAA2B;AAC3B,0BAA6C;AAEtC,MAAM,sBAA2C;AAAA,EAAjD;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,QACZ;AAAA,UACC,MAAM;AAAA,UACN,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MAEA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,YAAY;AAAA,QAClB;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ,CAAC;AAAA,MAET,SAAS,CAAC,wCAAoB,WAAW;AAAA,MACzC,aAAa,CAAC,YAAY;AAAA,MAC1B,YAAY;AAAA,YACX,kDAA6B,CAAC,wCA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BAAiB,SAAS,SAAS;AAE1D,UAAM,UAAU,KAAK,iBAAiB,WAAW,WAAW,CAAC,CAAC;AAO9D,QAAI,QAAQ,YAAY,IAAI;AAC3B,cAAQ,UAAU;AAAA,IACnB;AAEA,UAAM,aAAa,IAAI,oCAAsB;AAAA,MAC5C,8BAA8B;AAAA;AAAA,MAE9B,4BAA4B,CAAC,YAAY,WAAW,YAAY,eAAe;AAAA,MAC/E,mBAAmB,YAAY;AAAA,MAC/B,uBAAuB,YAAY;AAAA;AAAA;AAAA,MAGnC,qBAAqB,YAAY,WAC9B,GAAG,YAAY,QAAQ,wBACvB;AAAA,MACH,GAAG;AAAA,IACJ,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,YAAY,IAAI;AAAA,IACtC;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts"],"sourcesContent":["import { AzureOpenAIEmbeddings } from '@langchain/openai';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { getProxyAgent } from '@utils/httpProxyAgent';\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nexport class EmbeddingsAzureOpenAi implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Embeddings Azure OpenAI',\n\t\tname: 'embeddingsAzureOpenAi',\n\t\ticon: 'file:azure.svg',\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'azureOpenAiApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Use Embeddings Azure OpenAI',\n\t\tdefaults: {\n\t\t\tname: 'Embeddings Azure OpenAI',\n\t\t},\n\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Embeddings'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.embeddingsazureopenai/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiEmbedding],\n\t\toutputNames: ['Embeddings'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiVectorStore]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Model (Deployment) Name',\n\t\t\t\tname: 'model',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'The name of the model(deployment) to use',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Batch Size',\n\t\t\t\t\t\tname: 'batchSize',\n\t\t\t\t\t\tdefault: 512,\n\t\t\t\t\t\ttypeOptions: { maxValue: 2048 },\n\t\t\t\t\t\tdescription: 'Maximum number of documents to send in each request',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Strip New Lines',\n\t\t\t\t\t\tname: 'stripNewLines',\n\t\t\t\t\t\tdefault: true,\n\t\t\t\t\t\tdescription: 'Whether to strip new lines from the input text',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Timeout',\n\t\t\t\t\t\tname: 'timeout',\n\t\t\t\t\t\tdefault: -1,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Maximum amount of time a request is allowed to take in seconds. Set to -1 for no timeout.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Dimensions',\n\t\t\t\t\t\tname: 'dimensions',\n\t\t\t\t\t\tdefault: undefined,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: '256',\n\t\t\t\t\t\t\t\tvalue: 256,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: '512',\n\t\t\t\t\t\t\t\tvalue: 512,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: '1024',\n\t\t\t\t\t\t\t\tvalue: 1024,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: '1536',\n\t\t\t\t\t\t\t\tvalue: 1536,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: '3072',\n\t\t\t\t\t\t\t\tvalue: 3072,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supply data for embeddings');\n\t\tconst credentials = await this.getCredentials<{\n\t\t\tapiKey: string;\n\t\t\tresourceName: string;\n\t\t\tapiVersion: string;\n\t\t\tendpoint?: string;\n\t\t}>('azureOpenAiApi');\n\t\tconst modelName = this.getNodeParameter('model', itemIndex) as string;\n\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\tbatchSize?: number;\n\t\t\tstripNewLines?: boolean;\n\t\t\ttimeout?: number;\n\t\t\tdimensions?: number | undefined;\n\t\t};\n\n\t\tif (options.timeout === -1) {\n\t\t\toptions.timeout = undefined;\n\t\t}\n\n\t\tconst embeddings = new AzureOpenAIEmbeddings({\n\t\t\tazureOpenAIApiDeploymentName: modelName,\n\t\t\t// instance name only needed to set base url\n\t\t\tazureOpenAIApiInstanceName: !credentials.endpoint ? credentials.resourceName : undefined,\n\t\t\tazureOpenAIApiKey: credentials.apiKey,\n\t\t\tazureOpenAIApiVersion: credentials.apiVersion,\n\t\t\t// azureOpenAIEndpoint and configuration.baseURL are both ignored here\n\t\t\t// only setting azureOpenAIBasePath worked\n\t\t\tazureOpenAIBasePath: credentials.endpoint\n\t\t\t\t? `${credentials.endpoint}/openai/deployments`\n\t\t\t\t: undefined,\n\t\t\tconfiguration: {\n\t\t\t\tfetchOptions: {\n\t\t\t\t\tdispatcher: getProxyAgent(\n\t\t\t\t\t\tcredentials.endpoint ?? `https://${credentials.resourceName}.openai.azure.com`,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t},\n\t\t\t...options,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(embeddings, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAsC;AACtC,0BAMO;AAEP,4BAA8B;AAC9B,wBAA2B;AAC3B,0BAA6C;AAEtC,MAAM,sBAA2C;AAAA,EAAjD;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,QACZ;AAAA,UACC,MAAM;AAAA,UACN,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MAEA,OAAO;AAAA,QACN,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AA,gBACA;AAAA,kBACC,MAAM;AAAA,kBACN,OAAO;AAAA,gBACR;AAAA,gBACA;AAAA,kBACC,MAAM;AAAA,kBACN,OAAO;AAAA,gBACR;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,SAAK,OAAO,MAAM,4BAA4B;AAC9C,UAAM,cAAc,MAAM,KAAK,eAK5B,gBAAgB;AACnB,UAAM,YAAY,KAAK,iBAAiB,SAAS,SAAS;AAE1D,UAAM,UAAU,KAAK,iBAAiB,WAAW,WAAW,CAAC,CAAC;AAO9D,QAAI,QAAQ,YAAY,IAAI;AAC3B,cAAQ,UAAU;AAAA,IACnB;AAEA,UAAM,aAAa,IAAI,oCAAsB;AAAA,MAC5C,8BAA8B;AAAA;AAAA,MAE9B,4BAA4B,CAAC,YAAY,WAAW,YAAY,eAAe;AAAA,MAC/E,mBAAmB,YAAY;AAAA,MAC/B,uBAAuB,YAAY;AAAA;AAAA;AAAA,MAGnC,qBAAqB,YAAY,WAC9B,GAAG,YAAY,QAAQ,wBACvB;AAAA,MACH,eAAe;AAAA,QACd,cAAc;AAAA,UACb,gBAAY;AAAA,YACX,YAAY,YAAY,WAAW,YAAY,YAAY;AAAA,UAC5D;AAAA,QACD;AAAA,MACD;AAAA,MACA,GAAG;AAAA,IACJ,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,YAAY,IAAI;AAAA,IACtC;AAAA,EACD;AACD;","names":[]}
|
|
@@ -21,6 +21,7 @@ __export(McpClientTool_node_exports, {
|
|
|
21
21
|
McpClientTool: () => McpClientTool
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(McpClientTool_node_exports);
|
|
24
|
+
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
24
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
25
26
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
26
27
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
@@ -130,6 +131,15 @@ class McpClientTool {
|
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
},
|
|
134
|
+
{
|
|
135
|
+
name: "httpMultipleHeadersAuth",
|
|
136
|
+
required: true,
|
|
137
|
+
displayOptions: {
|
|
138
|
+
show: {
|
|
139
|
+
authentication: ["multipleHeadersAuth"]
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
133
143
|
{
|
|
134
144
|
name: "mcpOAuth2Api",
|
|
135
145
|
required: true,
|
|
@@ -217,10 +227,6 @@ class McpClientTool {
|
|
|
217
227
|
name: "authentication",
|
|
218
228
|
type: "options",
|
|
219
229
|
options: [
|
|
220
|
-
{
|
|
221
|
-
name: "MCP OAuth2",
|
|
222
|
-
value: "mcpOAuth2Api"
|
|
223
|
-
},
|
|
224
230
|
{
|
|
225
231
|
name: "Bearer Auth",
|
|
226
232
|
value: "bearerAuth"
|
|
@@ -229,6 +235,14 @@ class McpClientTool {
|
|
|
229
235
|
name: "Header Auth",
|
|
230
236
|
value: "headerAuth"
|
|
231
237
|
},
|
|
238
|
+
{
|
|
239
|
+
name: "MCP OAuth2",
|
|
240
|
+
value: "mcpOAuth2Api"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: "Multiple Headers Auth",
|
|
244
|
+
value: "multipleHeadersAuth"
|
|
245
|
+
},
|
|
232
246
|
{
|
|
233
247
|
name: "None",
|
|
234
248
|
value: "none"
|
|
@@ -249,7 +263,7 @@ class McpClientTool {
|
|
|
249
263
|
default: "",
|
|
250
264
|
displayOptions: {
|
|
251
265
|
show: {
|
|
252
|
-
authentication: ["headerAuth", "bearerAuth", "mcpOAuth2Api"]
|
|
266
|
+
authentication: ["headerAuth", "bearerAuth", "mcpOAuth2Api", "multipleHeadersAuth"]
|
|
253
267
|
}
|
|
254
268
|
}
|
|
255
269
|
},
|
|
@@ -356,7 +370,7 @@ class McpClientTool {
|
|
|
356
370
|
}
|
|
357
371
|
}
|
|
358
372
|
this.logger.debug("McpClientTool: Successfully connected to MCP Server");
|
|
359
|
-
if (!mcpTools
|
|
373
|
+
if (!mcpTools?.length) {
|
|
360
374
|
return setError(
|
|
361
375
|
"MCP Server returned no tools",
|
|
362
376
|
"Connected successfully to your MCP server but it returned an empty list of tools."
|
|
@@ -406,7 +420,9 @@ class McpClientTool {
|
|
|
406
420
|
name: tool.name,
|
|
407
421
|
arguments: toolArguments
|
|
408
422
|
};
|
|
409
|
-
const result = await client.callTool(params
|
|
423
|
+
const result = await client.callTool(params, import_types.CallToolResultSchema, {
|
|
424
|
+
timeout: config.timeout
|
|
425
|
+
});
|
|
410
426
|
returnData.push({
|
|
411
427
|
json: {
|
|
412
428
|
response: result.content
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/mcp/McpClientTool/McpClientTool.node.ts"],"sourcesContent":["import {\n\ttype IDataObject,\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { transportSelect } from './descriptions';\nimport { getTools } from './loadOptions';\nimport type { McpServerTransport, McpAuthenticationOption, McpToolIncludeMode } from './types';\nimport {\n\tconnectMcpClient,\n\tcreateCallTool,\n\tgetAllTools,\n\tgetAuthHeaders,\n\tgetSelectedTools,\n\tMcpToolkit,\n\tmcpToolToDynamicTool,\n\ttryRefreshOAuth2Token,\n} from './utils';\n\n/**\n * Get node parameters for MCP client configuration\n */\nfunction getNodeConfig(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\titemIndex: number,\n): {\n\tauthentication: McpAuthenticationOption;\n\ttimeout: number;\n\tserverTransport: McpServerTransport;\n\tendpointUrl: string;\n\tmode: McpToolIncludeMode;\n\tincludeTools: string[];\n\texcludeTools: string[];\n} {\n\tconst node = ctx.getNode();\n\tconst authentication = ctx.getNodeParameter(\n\t\t'authentication',\n\t\titemIndex,\n\t) as McpAuthenticationOption;\n\tconst timeout = ctx.getNodeParameter('options.timeout', itemIndex, 60000) as number;\n\n\tlet serverTransport: McpServerTransport;\n\tlet endpointUrl: string;\n\tif (node.typeVersion === 1) {\n\t\tserverTransport = 'sse';\n\t\tendpointUrl = ctx.getNodeParameter('sseEndpoint', itemIndex) as string;\n\t} else {\n\t\tserverTransport = ctx.getNodeParameter('serverTransport', itemIndex) as McpServerTransport;\n\t\tendpointUrl = ctx.getNodeParameter('endpointUrl', itemIndex) as string;\n\t}\n\n\tconst mode = ctx.getNodeParameter('include', itemIndex) as McpToolIncludeMode;\n\tconst includeTools = ctx.getNodeParameter('includeTools', itemIndex, []) as string[];\n\tconst excludeTools = ctx.getNodeParameter('excludeTools', itemIndex, []) as string[];\n\n\treturn {\n\t\tauthentication,\n\t\ttimeout,\n\t\tserverTransport,\n\t\tendpointUrl,\n\t\tmode,\n\t\tincludeTools,\n\t\texcludeTools,\n\t};\n}\n\n/**\n * Connect to MCP server and get filtered tools\n */\nasync function connectAndGetTools(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\tconfig: ReturnType<typeof getNodeConfig>,\n) {\n\tconst node = ctx.getNode();\n\tconst { headers } = await getAuthHeaders(ctx, config.authentication);\n\n\tconst client = await connectMcpClient({\n\t\tserverTransport: config.serverTransport,\n\t\tendpointUrl: config.endpointUrl,\n\t\theaders,\n\t\tname: node.type,\n\t\tversion: node.typeVersion,\n\t\tonUnauthorized: async (headers) =>\n\t\t\tawait tryRefreshOAuth2Token(ctx, config.authentication, headers),\n\t});\n\n\tif (!client.ok) {\n\t\treturn { client, mcpTools: null, error: client.error };\n\t}\n\n\tconst allTools = await getAllTools(client.result);\n\tconst mcpTools = getSelectedTools({\n\t\ttools: allTools,\n\t\tmode: config.mode,\n\t\tincludeTools: config.includeTools,\n\t\texcludeTools: config.excludeTools,\n\t});\n\n\treturn { client: client.result, mcpTools, error: null };\n}\n\nexport class McpClientTool implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'MCP Client Tool',\n\t\tname: 'mcpClientTool',\n\t\ticon: {\n\t\t\tlight: 'file:../mcp.svg',\n\t\t\tdark: 'file:../mcp.dark.svg',\n\t\t},\n\t\tgroup: ['output'],\n\t\tversion: [1, 1.1, 1.2],\n\t\tdescription: 'Connect tools from an MCP Server',\n\t\tdefaults: {\n\t\t\tname: 'MCP Client',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Model Context Protocol', 'Tools'],\n\t\t\t},\n\t\t\talias: ['Model Context Protocol', 'MCP Client'],\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolmcp/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [],\n\t\toutputs: [{ type: NodeConnectionTypes.AiTool, displayName: 'Tools' }],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-credentials-name-unsuffixed\n\t\t\t\tname: 'httpBearerAuth',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['bearerAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'httpHeaderAuth',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['headerAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'mcpOAuth2Api',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['mcpOAuth2Api'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'SSE Endpoint',\n\t\t\t\tname: 'sseEndpoint',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'SSE Endpoint of your MCP server',\n\t\t\t\tplaceholder: 'e.g. https://my-mcp-server.ai/sse',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Endpoint',\n\t\t\t\tname: 'endpointUrl',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Endpoint of your MCP server',\n\t\t\t\tplaceholder: 'e.g. https://my-mcp-server.ai/mcp',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.1 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\ttransportSelect({\n\t\t\t\tdefaultOption: 'sse',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\ttransportSelect({\n\t\t\t\tdefaultOption: 'httpStreamable',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\t{\n\t\t\t\tdisplayName: 'Authentication',\n\t\t\t\tname: 'authentication',\n\t\t\t\ttype: 'options',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Bearer Auth',\n\t\t\t\t\t\tvalue: 'bearerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Header Auth',\n\t\t\t\t\t\tvalue: 'headerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'None',\n\t\t\t\t\t\tvalue: 'none',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdefault: 'none',\n\t\t\t\tdescription: 'The way to authenticate with your endpoint',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lt: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Authentication',\n\t\t\t\tname: 'authentication',\n\t\t\t\ttype: 'options',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'MCP OAuth2',\n\t\t\t\t\t\tvalue: 'mcpOAuth2Api',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Bearer Auth',\n\t\t\t\t\t\tvalue: 'bearerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Header Auth',\n\t\t\t\t\t\tvalue: 'headerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'None',\n\t\t\t\t\t\tvalue: 'none',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdefault: 'none',\n\t\t\t\tdescription: 'The way to authenticate with your endpoint',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Credentials',\n\t\t\t\tname: 'credentials',\n\t\t\t\ttype: 'credentials',\n\t\t\t\tdefault: '',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['headerAuth', 'bearerAuth', 'mcpOAuth2Api'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Tools to Include',\n\t\t\t\tname: 'include',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'How to select the tools you want to be exposed to the AI Agent',\n\t\t\t\tdefault: 'all',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'All',\n\t\t\t\t\t\tvalue: 'all',\n\t\t\t\t\t\tdescription: 'Also include all unchanged fields from the input',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Selected',\n\t\t\t\t\t\tvalue: 'selected',\n\t\t\t\t\t\tdescription: 'Also include the tools listed in the parameter \"Tools to Include\"',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'All Except',\n\t\t\t\t\t\tvalue: 'except',\n\t\t\t\t\t\tdescription: 'Exclude the tools listed in the parameter \"Tools to Exclude\"',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Tools to Include',\n\t\t\t\tname: 'includeTools',\n\t\t\t\ttype: 'multiOptions',\n\t\t\t\tdefault: [],\n\t\t\t\tdescription:\n\t\t\t\t\t'Choose from the list, or specify IDs using an <a href=\"https://docs.n8n.io/code/expressions/\">expression</a>',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tloadOptionsMethod: 'getTools',\n\t\t\t\t\tloadOptionsDependsOn: ['sseEndpoint'],\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tinclude: ['selected'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Tools to Exclude',\n\t\t\t\tname: 'excludeTools',\n\t\t\t\ttype: 'multiOptions',\n\t\t\t\tdefault: [],\n\t\t\t\tdescription:\n\t\t\t\t\t'Choose from the list, or specify IDs using an <a href=\"https://docs.n8n.io/code/expressions/\">expression</a>',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tloadOptionsMethod: 'getTools',\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tinclude: ['except'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Timeout',\n\t\t\t\t\t\tname: 'timeout',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\tminValue: 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdefault: 60000,\n\t\t\t\t\t\tdescription: 'Time in ms to wait for tool calls to finish',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tmethods = {\n\t\tloadOptions: {\n\t\t\tgetTools,\n\t\t},\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst node = this.getNode();\n\t\tconst config = getNodeConfig(this, itemIndex);\n\n\t\tconst setError = (message: string, description?: string): SupplyData => {\n\t\t\tconst error = new NodeOperationError(node, message, { itemIndex, description });\n\t\t\tthis.addOutputData(NodeConnectionTypes.AiTool, itemIndex, error);\n\t\t\tthrow error;\n\t\t};\n\n\t\tconst { client, mcpTools, error } = await connectAndGetTools(this, config);\n\n\t\tif (error) {\n\t\t\tthis.logger.error('McpClientTool: Failed to connect to MCP Server', { error });\n\n\t\t\tswitch (error.type) {\n\t\t\t\tcase 'invalid_url':\n\t\t\t\t\treturn setError('Could not connect to your MCP server. The provided URL is invalid.');\n\t\t\t\tcase 'connection':\n\t\t\t\tdefault:\n\t\t\t\t\treturn setError('Could not connect to your MCP server');\n\t\t\t}\n\t\t}\n\n\t\tthis.logger.debug('McpClientTool: Successfully connected to MCP Server');\n\n\t\tif (!mcpTools || !mcpTools.length) {\n\t\t\treturn setError(\n\t\t\t\t'MCP Server returned no tools',\n\t\t\t\t'Connected successfully to your MCP server but it returned an empty list of tools.',\n\t\t\t);\n\t\t}\n\n\t\tconst tools = mcpTools.map((tool) =>\n\t\t\tlogWrapper(\n\t\t\t\tmcpToolToDynamicTool(\n\t\t\t\t\ttool,\n\t\t\t\t\tcreateCallTool(tool.name, client, config.timeout, (errorMessage) => {\n\t\t\t\t\t\tconst error = new NodeOperationError(node, errorMessage, { itemIndex });\n\t\t\t\t\t\tvoid this.addOutputData(NodeConnectionTypes.AiTool, itemIndex, error);\n\t\t\t\t\t\tthis.logger.error(`McpClientTool: Tool \"${tool.name}\" failed to execute`, { error });\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\tthis,\n\t\t\t),\n\t\t);\n\n\t\tthis.logger.debug(`McpClientTool: Connected to MCP Server with ${tools.length} tools`);\n\n\t\tconst toolkit = new McpToolkit(tools);\n\n\t\treturn { response: toolkit, closeFunction: async () => await client.close() };\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst node = this.getNode();\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\tconst item = items[itemIndex];\n\t\t\tconst config = getNodeConfig(this, itemIndex);\n\n\t\t\tconst { client, mcpTools, error } = await connectAndGetTools(this, config);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new NodeOperationError(node, error.error, { itemIndex });\n\t\t\t}\n\n\t\t\tif (!mcpTools?.length) {\n\t\t\t\tthrow new NodeOperationError(node, 'MCP Server returned no tools', { itemIndex });\n\t\t\t}\n\n\t\t\tfor (const tool of mcpTools) {\n\t\t\t\t// Check for tool name in item.json.tool (for toolkit execution from agent)\n\t\t\t\t// or item.tool (for direct execution)\n\t\t\t\tif (!item.json.tool || typeof item.json.tool !== 'string') {\n\t\t\t\t\tthrow new NodeOperationError(node, 'Tool name not found in item.json.tool or item.tool', {\n\t\t\t\t\t\titemIndex,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst toolName = item.json.tool;\n\t\t\t\tif (toolName === tool.name) {\n\t\t\t\t\t// Extract the tool name from arguments before passing to MCP\n\t\t\t\t\tconst { tool: _, ...toolArguments } = item.json;\n\t\t\t\t\tconst params: {\n\t\t\t\t\t\tname: string;\n\t\t\t\t\t\targuments: IDataObject;\n\t\t\t\t\t} = {\n\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\targuments: toolArguments,\n\t\t\t\t\t};\n\t\t\t\t\tconst result = await client.callTool(params);\n\t\t\t\t\treturnData.push({\n\t\t\t\t\t\tjson: {\n\t\t\t\t\t\t\tresponse: result.content as IDataObject,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpairedItem: {\n\t\t\t\t\t\t\titem: itemIndex,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAUO;AAEP,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAAgC;AAChC,yBAAyB;AAEzB,mBASO;AAKP,SAAS,cACR,KACA,WASC;AACD,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,iBAAiB,IAAI;AAAA,IAC1B;AAAA,IACA;AAAA,EACD;AACA,QAAM,UAAU,IAAI,iBAAiB,mBAAmB,WAAW,GAAK;AAExE,MAAI;AAC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AC1D,gBAAM,IAAI,uCAAmB,MAAM,sDAAsD;AAAA,YACxF;AAAA,UACD,CAAC;AAAA,QACF;AAEA,cAAM,WAAW,KAAK,KAAK;AAC3B,YAAI,aAAa,KAAK,MAAM;AAE3B,gBAAM,EAAE,MAAM,GAAG,GAAG,cAAc,IAAI,KAAK;AAC3C,gBAAM,SAGF;AAAA,YACH,MAAM,KAAK;AAAA,YACX,WAAW;AAAA,UACZ;AACA,gBAAM,SAAS,MAAM,OAAO,SAAS,MAAM;AAC3C,qBAAW,KAAK;AAAA,YACf,MAAM;AAAA,cACL,UAAU,OAAO;AAAA,YAClB;AAAA,YACA,YAAY;AAAA,cACX,MAAM;AAAA,YACP;AAAA,UACD,CAAC;AAAA,QACF;AAAA,MACD;AAAA,IACD;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":["headers","error"]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/mcp/McpClientTool/McpClientTool.node.ts"],"sourcesContent":["import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport {\n\ttype IDataObject,\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { transportSelect } from './descriptions';\nimport { getTools } from './loadOptions';\nimport type { McpServerTransport, McpAuthenticationOption, McpToolIncludeMode } from './types';\nimport {\n\tconnectMcpClient,\n\tcreateCallTool,\n\tgetAllTools,\n\tgetAuthHeaders,\n\tgetSelectedTools,\n\tMcpToolkit,\n\tmcpToolToDynamicTool,\n\ttryRefreshOAuth2Token,\n} from './utils';\n\n/**\n * Get node parameters for MCP client configuration\n */\nfunction getNodeConfig(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\titemIndex: number,\n): {\n\tauthentication: McpAuthenticationOption;\n\ttimeout: number;\n\tserverTransport: McpServerTransport;\n\tendpointUrl: string;\n\tmode: McpToolIncludeMode;\n\tincludeTools: string[];\n\texcludeTools: string[];\n} {\n\tconst node = ctx.getNode();\n\tconst authentication = ctx.getNodeParameter(\n\t\t'authentication',\n\t\titemIndex,\n\t) as McpAuthenticationOption;\n\tconst timeout = ctx.getNodeParameter('options.timeout', itemIndex, 60000) as number;\n\n\tlet serverTransport: McpServerTransport;\n\tlet endpointUrl: string;\n\tif (node.typeVersion === 1) {\n\t\tserverTransport = 'sse';\n\t\tendpointUrl = ctx.getNodeParameter('sseEndpoint', itemIndex) as string;\n\t} else {\n\t\tserverTransport = ctx.getNodeParameter('serverTransport', itemIndex) as McpServerTransport;\n\t\tendpointUrl = ctx.getNodeParameter('endpointUrl', itemIndex) as string;\n\t}\n\n\tconst mode = ctx.getNodeParameter('include', itemIndex) as McpToolIncludeMode;\n\tconst includeTools = ctx.getNodeParameter('includeTools', itemIndex, []) as string[];\n\tconst excludeTools = ctx.getNodeParameter('excludeTools', itemIndex, []) as string[];\n\n\treturn {\n\t\tauthentication,\n\t\ttimeout,\n\t\tserverTransport,\n\t\tendpointUrl,\n\t\tmode,\n\t\tincludeTools,\n\t\texcludeTools,\n\t};\n}\n\n/**\n * Connect to MCP server and get filtered tools\n */\nasync function connectAndGetTools(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\tconfig: ReturnType<typeof getNodeConfig>,\n) {\n\tconst node = ctx.getNode();\n\tconst { headers } = await getAuthHeaders(ctx, config.authentication);\n\n\tconst client = await connectMcpClient({\n\t\tserverTransport: config.serverTransport,\n\t\tendpointUrl: config.endpointUrl,\n\t\theaders,\n\t\tname: node.type,\n\t\tversion: node.typeVersion,\n\t\tonUnauthorized: async (headers) =>\n\t\t\tawait tryRefreshOAuth2Token(ctx, config.authentication, headers),\n\t});\n\n\tif (!client.ok) {\n\t\treturn { client, mcpTools: null, error: client.error };\n\t}\n\n\tconst allTools = await getAllTools(client.result);\n\tconst mcpTools = getSelectedTools({\n\t\ttools: allTools,\n\t\tmode: config.mode,\n\t\tincludeTools: config.includeTools,\n\t\texcludeTools: config.excludeTools,\n\t});\n\n\treturn { client: client.result, mcpTools, error: null };\n}\n\nexport class McpClientTool implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'MCP Client Tool',\n\t\tname: 'mcpClientTool',\n\t\ticon: {\n\t\t\tlight: 'file:../mcp.svg',\n\t\t\tdark: 'file:../mcp.dark.svg',\n\t\t},\n\t\tgroup: ['output'],\n\t\tversion: [1, 1.1, 1.2],\n\t\tdescription: 'Connect tools from an MCP Server',\n\t\tdefaults: {\n\t\t\tname: 'MCP Client',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Model Context Protocol', 'Tools'],\n\t\t\t},\n\t\t\talias: ['Model Context Protocol', 'MCP Client'],\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolmcp/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [],\n\t\toutputs: [{ type: NodeConnectionTypes.AiTool, displayName: 'Tools' }],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-credentials-name-unsuffixed\n\t\t\t\tname: 'httpBearerAuth',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['bearerAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'httpHeaderAuth',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['headerAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'httpMultipleHeadersAuth',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['multipleHeadersAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'mcpOAuth2Api',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['mcpOAuth2Api'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'SSE Endpoint',\n\t\t\t\tname: 'sseEndpoint',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'SSE Endpoint of your MCP server',\n\t\t\t\tplaceholder: 'e.g. https://my-mcp-server.ai/sse',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Endpoint',\n\t\t\t\tname: 'endpointUrl',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Endpoint of your MCP server',\n\t\t\t\tplaceholder: 'e.g. https://my-mcp-server.ai/mcp',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.1 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\ttransportSelect({\n\t\t\t\tdefaultOption: 'sse',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\ttransportSelect({\n\t\t\t\tdefaultOption: 'httpStreamable',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\t{\n\t\t\t\tdisplayName: 'Authentication',\n\t\t\t\tname: 'authentication',\n\t\t\t\ttype: 'options',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Bearer Auth',\n\t\t\t\t\t\tvalue: 'bearerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Header Auth',\n\t\t\t\t\t\tvalue: 'headerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'None',\n\t\t\t\t\t\tvalue: 'none',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdefault: 'none',\n\t\t\t\tdescription: 'The way to authenticate with your endpoint',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lt: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Authentication',\n\t\t\t\tname: 'authentication',\n\t\t\t\ttype: 'options',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Bearer Auth',\n\t\t\t\t\t\tvalue: 'bearerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Header Auth',\n\t\t\t\t\t\tvalue: 'headerAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'MCP OAuth2',\n\t\t\t\t\t\tvalue: 'mcpOAuth2Api',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Multiple Headers Auth',\n\t\t\t\t\t\tvalue: 'multipleHeadersAuth',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'None',\n\t\t\t\t\t\tvalue: 'none',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdefault: 'none',\n\t\t\t\tdescription: 'The way to authenticate with your endpoint',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Credentials',\n\t\t\t\tname: 'credentials',\n\t\t\t\ttype: 'credentials',\n\t\t\t\tdefault: '',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['headerAuth', 'bearerAuth', 'mcpOAuth2Api', 'multipleHeadersAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Tools to Include',\n\t\t\t\tname: 'include',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'How to select the tools you want to be exposed to the AI Agent',\n\t\t\t\tdefault: 'all',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'All',\n\t\t\t\t\t\tvalue: 'all',\n\t\t\t\t\t\tdescription: 'Also include all unchanged fields from the input',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Selected',\n\t\t\t\t\t\tvalue: 'selected',\n\t\t\t\t\t\tdescription: 'Also include the tools listed in the parameter \"Tools to Include\"',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'All Except',\n\t\t\t\t\t\tvalue: 'except',\n\t\t\t\t\t\tdescription: 'Exclude the tools listed in the parameter \"Tools to Exclude\"',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Tools to Include',\n\t\t\t\tname: 'includeTools',\n\t\t\t\ttype: 'multiOptions',\n\t\t\t\tdefault: [],\n\t\t\t\tdescription:\n\t\t\t\t\t'Choose from the list, or specify IDs using an <a href=\"https://docs.n8n.io/code/expressions/\">expression</a>',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tloadOptionsMethod: 'getTools',\n\t\t\t\t\tloadOptionsDependsOn: ['sseEndpoint'],\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tinclude: ['selected'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Tools to Exclude',\n\t\t\t\tname: 'excludeTools',\n\t\t\t\ttype: 'multiOptions',\n\t\t\t\tdefault: [],\n\t\t\t\tdescription:\n\t\t\t\t\t'Choose from the list, or specify IDs using an <a href=\"https://docs.n8n.io/code/expressions/\">expression</a>',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tloadOptionsMethod: 'getTools',\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tinclude: ['except'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Timeout',\n\t\t\t\t\t\tname: 'timeout',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\tminValue: 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdefault: 60000,\n\t\t\t\t\t\tdescription: 'Time in ms to wait for tool calls to finish',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tmethods = {\n\t\tloadOptions: {\n\t\t\tgetTools,\n\t\t},\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst node = this.getNode();\n\t\tconst config = getNodeConfig(this, itemIndex);\n\n\t\tconst setError = (message: string, description?: string): SupplyData => {\n\t\t\tconst error = new NodeOperationError(node, message, { itemIndex, description });\n\t\t\tthis.addOutputData(NodeConnectionTypes.AiTool, itemIndex, error);\n\t\t\tthrow error;\n\t\t};\n\n\t\tconst { client, mcpTools, error } = await connectAndGetTools(this, config);\n\n\t\tif (error) {\n\t\t\tthis.logger.error('McpClientTool: Failed to connect to MCP Server', { error });\n\n\t\t\tswitch (error.type) {\n\t\t\t\tcase 'invalid_url':\n\t\t\t\t\treturn setError('Could not connect to your MCP server. The provided URL is invalid.');\n\t\t\t\tcase 'connection':\n\t\t\t\tdefault:\n\t\t\t\t\treturn setError('Could not connect to your MCP server');\n\t\t\t}\n\t\t}\n\n\t\tthis.logger.debug('McpClientTool: Successfully connected to MCP Server');\n\n\t\tif (!mcpTools?.length) {\n\t\t\treturn setError(\n\t\t\t\t'MCP Server returned no tools',\n\t\t\t\t'Connected successfully to your MCP server but it returned an empty list of tools.',\n\t\t\t);\n\t\t}\n\n\t\tconst tools = mcpTools.map((tool) =>\n\t\t\tlogWrapper(\n\t\t\t\tmcpToolToDynamicTool(\n\t\t\t\t\ttool,\n\t\t\t\t\tcreateCallTool(tool.name, client, config.timeout, (errorMessage) => {\n\t\t\t\t\t\tconst error = new NodeOperationError(node, errorMessage, { itemIndex });\n\t\t\t\t\t\tvoid this.addOutputData(NodeConnectionTypes.AiTool, itemIndex, error);\n\t\t\t\t\t\tthis.logger.error(`McpClientTool: Tool \"${tool.name}\" failed to execute`, { error });\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\tthis,\n\t\t\t),\n\t\t);\n\n\t\tthis.logger.debug(`McpClientTool: Connected to MCP Server with ${tools.length} tools`);\n\n\t\tconst toolkit = new McpToolkit(tools);\n\n\t\treturn { response: toolkit, closeFunction: async () => await client.close() };\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst node = this.getNode();\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\tconst item = items[itemIndex];\n\t\t\tconst config = getNodeConfig(this, itemIndex);\n\n\t\t\tconst { client, mcpTools, error } = await connectAndGetTools(this, config);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new NodeOperationError(node, error.error, { itemIndex });\n\t\t\t}\n\n\t\t\tif (!mcpTools?.length) {\n\t\t\t\tthrow new NodeOperationError(node, 'MCP Server returned no tools', { itemIndex });\n\t\t\t}\n\n\t\t\tfor (const tool of mcpTools) {\n\t\t\t\t// Check for tool name in item.json.tool (for toolkit execution from agent)\n\t\t\t\t// or item.tool (for direct execution)\n\t\t\t\tif (!item.json.tool || typeof item.json.tool !== 'string') {\n\t\t\t\t\tthrow new NodeOperationError(node, 'Tool name not found in item.json.tool or item.tool', {\n\t\t\t\t\t\titemIndex,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst toolName = item.json.tool;\n\t\t\t\tif (toolName === tool.name) {\n\t\t\t\t\t// Extract the tool name from arguments before passing to MCP\n\t\t\t\t\tconst { tool: _, ...toolArguments } = item.json;\n\t\t\t\t\tconst params: {\n\t\t\t\t\t\tname: string;\n\t\t\t\t\t\targuments: IDataObject;\n\t\t\t\t\t} = {\n\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\targuments: toolArguments,\n\t\t\t\t\t};\n\t\t\t\t\tconst result = await client.callTool(params, CallToolResultSchema, {\n\t\t\t\t\t\ttimeout: config.timeout,\n\t\t\t\t\t});\n\t\t\t\t\treturnData.push({\n\t\t\t\t\t\tjson: {\n\t\t\t\t\t\t\tresponse: result.content as IDataObject,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpairedItem: {\n\t\t\t\t\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["headers","error"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/mcp/McpClientTool/types.ts"],"sourcesContent":["import type { JSONSchema7 } from 'json-schema';\n\nexport type McpTool = { name: string; description?: string; inputSchema: JSONSchema7 };\n\nexport type McpServerTransport = 'sse' | 'httpStreamable';\n\nexport type McpToolIncludeMode = 'all' | 'selected' | 'except';\n\nexport type McpAuthenticationOption
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/mcp/McpClientTool/types.ts"],"sourcesContent":["import type { JSONSchema7 } from 'json-schema';\n\nexport type McpTool = { name: string; description?: string; inputSchema: JSONSchema7 };\n\nexport type McpServerTransport = 'sse' | 'httpStreamable';\n\nexport type McpToolIncludeMode = 'all' | 'selected' | 'except';\n\nexport type McpAuthenticationOption =\n\t| 'none'\n\t| 'headerAuth'\n\t| 'bearerAuth'\n\t| 'mcpOAuth2Api'\n\t| 'multipleHeadersAuth';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -38,6 +38,7 @@ var import_agents = require("langchain/agents");
|
|
|
38
38
|
var import_n8n_workflow = require("n8n-workflow");
|
|
39
39
|
var import_zod = require("zod");
|
|
40
40
|
var import_schemaParsing = require("../../../utils/schemaParsing");
|
|
41
|
+
var import_httpProxyAgent = require("../../../utils/httpProxyAgent");
|
|
41
42
|
async function getAllTools(client, cursor) {
|
|
42
43
|
const { tools, nextCursor } = await client.listTools({ cursor });
|
|
43
44
|
if (nextCursor) {
|
|
@@ -158,7 +159,8 @@ async function connectMcpClient({
|
|
|
158
159
|
if (serverTransport === "httpStreamable") {
|
|
159
160
|
try {
|
|
160
161
|
const transport = new import_streamableHttp.StreamableHTTPClientTransport(endpoint.result, {
|
|
161
|
-
requestInit: { headers }
|
|
162
|
+
requestInit: { headers },
|
|
163
|
+
fetch: import_httpProxyAgent.proxyFetch
|
|
162
164
|
});
|
|
163
165
|
await client.connect(transport);
|
|
164
166
|
return (0, import_n8n_workflow.createResultOk)(client);
|
|
@@ -181,7 +183,7 @@ async function connectMcpClient({
|
|
|
181
183
|
try {
|
|
182
184
|
const sseTransport = new import_sse.SSEClientTransport(endpoint.result, {
|
|
183
185
|
eventSourceInit: {
|
|
184
|
-
fetch: async (url, init) => await
|
|
186
|
+
fetch: async (url, init) => await (0, import_httpProxyAgent.proxyFetch)(url, {
|
|
185
187
|
...init,
|
|
186
188
|
headers: {
|
|
187
189
|
...headers,
|
|
@@ -189,6 +191,7 @@ async function connectMcpClient({
|
|
|
189
191
|
}
|
|
190
192
|
})
|
|
191
193
|
},
|
|
194
|
+
fetch: import_httpProxyAgent.proxyFetch,
|
|
192
195
|
requestInit: { headers }
|
|
193
196
|
});
|
|
194
197
|
await client.connect(sseTransport);
|
|
@@ -226,6 +229,21 @@ async function getAuthHeaders(ctx, authentication) {
|
|
|
226
229
|
if (!result) return {};
|
|
227
230
|
return { headers: { Authorization: `Bearer ${result.oauthTokenData.access_token}` } };
|
|
228
231
|
}
|
|
232
|
+
case "multipleHeadersAuth": {
|
|
233
|
+
const result = await ctx.getCredentials(
|
|
234
|
+
"httpMultipleHeadersAuth"
|
|
235
|
+
).catch(() => null);
|
|
236
|
+
if (!result) return {};
|
|
237
|
+
return {
|
|
238
|
+
headers: result.headers.values.reduce(
|
|
239
|
+
(acc, cur) => {
|
|
240
|
+
acc[cur.name] = cur.value;
|
|
241
|
+
return acc;
|
|
242
|
+
},
|
|
243
|
+
{}
|
|
244
|
+
)
|
|
245
|
+
};
|
|
246
|
+
}
|
|
229
247
|
case "none":
|
|
230
248
|
default: {
|
|
231
249
|
return {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/mcp/McpClientTool/utils.ts"],"sourcesContent":["import { DynamicStructuredTool, type DynamicStructuredToolInput } from '@langchain/core/tools';\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport { CompatibilityCallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport type { ClientOAuth2TokenData } from '@n8n/client-oauth2';\nimport { Toolkit } from 'langchain/agents';\nimport {\n\tcreateResultError,\n\tcreateResultOk,\n\ttype ILoadOptionsFunctions,\n\ttype ISupplyDataFunctions,\n\ttype IDataObject,\n\ttype IExecuteFunctions,\n\ttype Result,\n} from 'n8n-workflow';\nimport { z } from 'zod';\n\nimport { convertJsonSchemaToZod } from '@utils/schemaParsing';\n\nimport type {\n\tMcpAuthenticationOption,\n\tMcpServerTransport,\n\tMcpTool,\n\tMcpToolIncludeMode,\n} from './types';\n\nexport async function getAllTools(client: Client, cursor?: string): Promise<McpTool[]> {\n\tconst { tools, nextCursor } = await client.listTools({ cursor });\n\n\tif (nextCursor) {\n\t\treturn (tools as McpTool[]).concat(await getAllTools(client, nextCursor));\n\t}\n\n\treturn tools as McpTool[];\n}\n\nexport function getSelectedTools({\n\tmode,\n\tincludeTools,\n\texcludeTools,\n\ttools,\n}: {\n\tmode: McpToolIncludeMode;\n\tincludeTools?: string[];\n\texcludeTools?: string[];\n\ttools: McpTool[];\n}) {\n\tswitch (mode) {\n\t\tcase 'selected': {\n\t\t\tif (!includeTools?.length) return tools;\n\t\t\tconst include = new Set(includeTools);\n\t\t\treturn tools.filter((tool) => include.has(tool.name));\n\t\t}\n\t\tcase 'except': {\n\t\t\tconst except = new Set(excludeTools ?? []);\n\t\t\treturn tools.filter((tool) => !except.has(tool.name));\n\t\t}\n\t\tcase 'all':\n\t\tdefault:\n\t\t\treturn tools;\n\t}\n}\n\nexport const getErrorDescriptionFromToolCall = (result: unknown): string | undefined => {\n\tif (result && typeof result === 'object') {\n\t\tif ('content' in result && Array.isArray(result.content)) {\n\t\t\tconst errorMessage = (result.content as Array<{ type: 'text'; text: string }>).find(\n\t\t\t\t(content) => content && typeof content === 'object' && typeof content.text === 'string',\n\t\t\t)?.text;\n\t\t\treturn errorMessage;\n\t\t} else if ('toolResult' in result && typeof result.toolResult === 'string') {\n\t\t\treturn result.toolResult;\n\t\t}\n\t\tif ('message' in result && typeof result.message === 'string') {\n\t\t\treturn result.message;\n\t\t}\n\t}\n\n\treturn undefined;\n};\n\nexport const createCallTool =\n\t(name: string, client: Client, timeout: number, onError: (error: string) => void) =>\n\tasync (args: IDataObject) => {\n\t\tlet result: Awaited<ReturnType<Client['callTool']>>;\n\n\t\tfunction handleError(error: unknown) {\n\t\t\tconst errorDescription =\n\t\t\t\tgetErrorDescriptionFromToolCall(error) ?? `Failed to execute tool \"${name}\"`;\n\t\t\tonError(errorDescription);\n\t\t\treturn errorDescription;\n\t\t}\n\n\t\ttry {\n\t\t\tresult = await client.callTool({ name, arguments: args }, CompatibilityCallToolResultSchema, {\n\t\t\t\ttimeout,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\treturn handleError(error);\n\t\t}\n\n\t\tif (result.isError) {\n\t\t\treturn handleError(result);\n\t\t}\n\n\t\tif (result.toolResult !== undefined) {\n\t\t\treturn result.toolResult;\n\t\t}\n\n\t\tif (result.content !== undefined) {\n\t\t\treturn result.content;\n\t\t}\n\n\t\treturn result;\n\t};\n\nexport function mcpToolToDynamicTool(\n\ttool: McpTool,\n\tonCallTool: DynamicStructuredToolInput['func'],\n): DynamicStructuredTool {\n\tconst rawSchema = convertJsonSchemaToZod(tool.inputSchema);\n\n\t// Ensure we always have an object schema for structured tools\n\tconst objectSchema =\n\t\trawSchema instanceof z.ZodObject ? rawSchema : z.object({ value: rawSchema });\n\n\treturn new DynamicStructuredTool({\n\t\tname: tool.name,\n\t\tdescription: tool.description ?? '',\n\t\tschema: objectSchema,\n\t\tfunc: onCallTool,\n\t\tmetadata: { isFromToolkit: true },\n\t});\n}\n\nexport class McpToolkit extends Toolkit {\n\tconstructor(public tools: DynamicStructuredTool[]) {\n\t\tsuper();\n\t}\n}\n\nfunction safeCreateUrl(url: string, baseUrl?: string | URL): Result<URL, Error> {\n\ttry {\n\t\treturn createResultOk(new URL(url, baseUrl));\n\t} catch (error) {\n\t\treturn createResultError(error);\n\t}\n}\n\nfunction normalizeAndValidateUrl(input: string): Result<URL, Error> {\n\tconst withProtocol = !/^https?:\\/\\//i.test(input) ? `https://${input}` : input;\n\tconst parsedUrl = safeCreateUrl(withProtocol);\n\n\tif (!parsedUrl.ok) {\n\t\treturn createResultError(parsedUrl.error);\n\t}\n\n\treturn parsedUrl;\n}\n\nfunction isUnauthorizedError(error: unknown): boolean {\n\treturn (\n\t\t!!error &&\n\t\ttypeof error === 'object' &&\n\t\t(('code' in error && Number(error.code) === 401) ||\n\t\t\t('message' in error && typeof error.message === 'string' && error.message.includes('401')))\n\t);\n}\n\ntype OnUnauthorizedHandler = (\n\theaders?: Record<string, string>,\n) => Promise<Record<string, string> | null>;\n\ntype ConnectMcpClientError =\n\t| { type: 'invalid_url'; error: Error }\n\t| { type: 'connection'; error: Error };\n\nexport async function connectMcpClient({\n\theaders,\n\tserverTransport,\n\tendpointUrl,\n\tname,\n\tversion,\n\tonUnauthorized,\n}: {\n\tserverTransport: McpServerTransport;\n\tendpointUrl: string;\n\theaders?: Record<string, string>;\n\tname: string;\n\tversion: number;\n\tonUnauthorized?: OnUnauthorizedHandler;\n}): Promise<Result<Client, ConnectMcpClientError>> {\n\tconst endpoint = normalizeAndValidateUrl(endpointUrl);\n\n\tif (!endpoint.ok) {\n\t\treturn createResultError({ type: 'invalid_url', error: endpoint.error });\n\t}\n\n\tconst client = new Client({ name, version: version.toString() }, { capabilities: { tools: {} } });\n\n\tif (serverTransport === 'httpStreamable') {\n\t\ttry {\n\t\t\tconst transport = new StreamableHTTPClientTransport(endpoint.result, {\n\t\t\t\trequestInit: { headers },\n\t\t\t});\n\t\t\tawait client.connect(transport);\n\t\t\treturn createResultOk(client);\n\t\t} catch (error) {\n\t\t\tif (onUnauthorized && isUnauthorizedError(error)) {\n\t\t\t\tconst newHeaders = await onUnauthorized(headers);\n\t\t\t\tif (newHeaders) {\n\t\t\t\t\t// Don't pass `onUnauthorized` to avoid possible infinite recursion\n\t\t\t\t\treturn await connectMcpClient({\n\t\t\t\t\t\theaders: newHeaders,\n\t\t\t\t\t\tserverTransport,\n\t\t\t\t\t\tendpointUrl,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn createResultError({ type: 'connection', error });\n\t\t}\n\t}\n\n\ttry {\n\t\tconst sseTransport = new SSEClientTransport(endpoint.result, {\n\t\t\teventSourceInit: {\n\t\t\t\tfetch: async (url, init) =>\n\t\t\t\t\tawait fetch(url, {\n\t\t\t\t\t\t...init,\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t...headers,\n\t\t\t\t\t\t\tAccept: 'text/event-stream',\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t},\n\t\t\trequestInit: { headers },\n\t\t});\n\t\tawait client.connect(sseTransport);\n\t\treturn createResultOk(client);\n\t} catch (error) {\n\t\tif (onUnauthorized && isUnauthorizedError(error)) {\n\t\t\tconst newHeaders = await onUnauthorized(headers);\n\t\t\tif (newHeaders) {\n\t\t\t\t// Don't pass `onUnauthorized` to avoid possible infinite recursion\n\t\t\t\treturn await connectMcpClient({\n\t\t\t\t\theaders: newHeaders,\n\t\t\t\t\tserverTransport,\n\t\t\t\t\tendpointUrl,\n\t\t\t\t\tname,\n\t\t\t\t\tversion,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn createResultError({ type: 'connection', error });\n\t}\n}\n\nexport async function getAuthHeaders(\n\tctx: Pick<IExecuteFunctions, 'getCredentials'>,\n\tauthentication: McpAuthenticationOption,\n): Promise<{ headers?: Record<string, string> }> {\n\tswitch (authentication) {\n\t\tcase 'headerAuth': {\n\t\t\tconst header = await ctx\n\t\t\t\t.getCredentials<{ name: string; value: string }>('httpHeaderAuth')\n\t\t\t\t.catch(() => null);\n\n\t\t\tif (!header) return {};\n\n\t\t\treturn { headers: { [header.name]: header.value } };\n\t\t}\n\t\tcase 'bearerAuth': {\n\t\t\tconst result = await ctx\n\t\t\t\t.getCredentials<{ token: string }>('httpBearerAuth')\n\t\t\t\t.catch(() => null);\n\n\t\t\tif (!result) return {};\n\n\t\t\treturn { headers: { Authorization: `Bearer ${result.token}` } };\n\t\t}\n\t\tcase 'mcpOAuth2Api': {\n\t\t\tconst result = await ctx\n\t\t\t\t.getCredentials<{ oauthTokenData: { access_token: string } }>('mcpOAuth2Api')\n\t\t\t\t.catch(() => null);\n\n\t\t\tif (!result) return {};\n\n\t\t\treturn { headers: { Authorization: `Bearer ${result.oauthTokenData.access_token}` } };\n\t\t}\n\t\tcase 'none':\n\t\tdefault: {\n\t\t\treturn {};\n\t\t}\n\t}\n}\n\n/**\n * Tries to refresh the OAuth2 token, storing them in the database if successful\n * @param ctx - The execution context\n * @param authentication - The authentication method\n * @param headers - The headers to refresh\n * @returns The refreshed headers or null if the authentication method is not oAuth2Api or has failed\n */\nexport async function tryRefreshOAuth2Token(\n\tctx: IExecuteFunctions | ISupplyDataFunctions | ILoadOptionsFunctions,\n\tauthentication: McpAuthenticationOption,\n\theaders?: Record<string, string>,\n) {\n\tif (authentication !== 'mcpOAuth2Api') {\n\t\treturn null;\n\t}\n\n\tlet access_token: string | null = null;\n\ttry {\n\t\tconst result = (await ctx.helpers.refreshOAuth2Token.call(\n\t\t\tctx,\n\t\t\t'mcpOAuth2Api',\n\t\t)) as ClientOAuth2TokenData;\n\t\taccess_token = result?.access_token;\n\t} catch (error) {\n\t\treturn null;\n\t}\n\n\tif (!access_token) {\n\t\treturn null;\n\t}\n\n\tif (!headers) {\n\t\treturn {\n\t\t\tAuthorization: `Bearer ${access_token}`,\n\t\t};\n\t}\n\n\treturn {\n\t\t...headers,\n\t\tAuthorization: `Bearer ${access_token}`,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AAM,IAAI;AAElB,UAAI,CAAC,OAAQ,QAAO,CAAC;AAErB,aAAO,EAAE,SAAS,EAAE,eAAe,UAAU,OAAO,eAAe,YAAY,GAAG,EAAE;AAAA,IACrF;AAAA,IACA,KAAK;AAAA,IACL,SAAS;AACR,aAAO,CAAC;AAAA,IACT;AAAA,EACD;AACD;AASA,eAAsB,sBACrB,KACA,gBACA,SACC;AACD,MAAI,mBAAmB,gBAAgB;AACtC,WAAO;AAAA,EACR;AAEA,MAAI,eAA8B;AAClC,MAAI;AACH,UAAM,SAAU,MAAM,IAAI,QAAQ,mBAAmB;AAAA,MACpD;AAAA,MACA;AAAA,IACD;AACA,mBAAe,QAAQ;AAAA,EACxB,SAAS,OAAO;AACf,WAAO;AAAA,EACR;AAEA,MAAI,CAAC,cAAc;AAClB,WAAO;AAAA,EACR;AAEA,MAAI,CAAC,SAAS;AACb,WAAO;AAAA,MACN,eAAe,UAAU,YAAY;AAAA,IACtC;AAAA,EACD;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,eAAe,UAAU,YAAY;AAAA,EACtC;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/mcp/McpClientTool/utils.ts"],"sourcesContent":["import { DynamicStructuredTool, type DynamicStructuredToolInput } from '@langchain/core/tools';\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport { CompatibilityCallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport type { ClientOAuth2TokenData } from '@n8n/client-oauth2';\nimport { Toolkit } from 'langchain/agents';\nimport {\n\tcreateResultError,\n\tcreateResultOk,\n\ttype IDataObject,\n\ttype IExecuteFunctions,\n\ttype ILoadOptionsFunctions,\n\ttype ISupplyDataFunctions,\n\ttype Result,\n} from 'n8n-workflow';\nimport { z } from 'zod';\n\nimport { convertJsonSchemaToZod } from '@utils/schemaParsing';\n\nimport { proxyFetch } from '@utils/httpProxyAgent';\nimport type {\n\tMcpAuthenticationOption,\n\tMcpServerTransport,\n\tMcpTool,\n\tMcpToolIncludeMode,\n} from './types';\n\nexport async function getAllTools(client: Client, cursor?: string): Promise<McpTool[]> {\n\tconst { tools, nextCursor } = await client.listTools({ cursor });\n\n\tif (nextCursor) {\n\t\treturn (tools as McpTool[]).concat(await getAllTools(client, nextCursor));\n\t}\n\n\treturn tools as McpTool[];\n}\n\nexport function getSelectedTools({\n\tmode,\n\tincludeTools,\n\texcludeTools,\n\ttools,\n}: {\n\tmode: McpToolIncludeMode;\n\tincludeTools?: string[];\n\texcludeTools?: string[];\n\ttools: McpTool[];\n}) {\n\tswitch (mode) {\n\t\tcase 'selected': {\n\t\t\tif (!includeTools?.length) return tools;\n\t\t\tconst include = new Set(includeTools);\n\t\t\treturn tools.filter((tool) => include.has(tool.name));\n\t\t}\n\t\tcase 'except': {\n\t\t\tconst except = new Set(excludeTools ?? []);\n\t\t\treturn tools.filter((tool) => !except.has(tool.name));\n\t\t}\n\t\tcase 'all':\n\t\tdefault:\n\t\t\treturn tools;\n\t}\n}\n\nexport const getErrorDescriptionFromToolCall = (result: unknown): string | undefined => {\n\tif (result && typeof result === 'object') {\n\t\tif ('content' in result && Array.isArray(result.content)) {\n\t\t\tconst errorMessage = (result.content as Array<{ type: 'text'; text: string }>).find(\n\t\t\t\t(content) => content && typeof content === 'object' && typeof content.text === 'string',\n\t\t\t)?.text;\n\t\t\treturn errorMessage;\n\t\t} else if ('toolResult' in result && typeof result.toolResult === 'string') {\n\t\t\treturn result.toolResult;\n\t\t}\n\t\tif ('message' in result && typeof result.message === 'string') {\n\t\t\treturn result.message;\n\t\t}\n\t}\n\n\treturn undefined;\n};\n\nexport const createCallTool =\n\t(name: string, client: Client, timeout: number, onError: (error: string) => void) =>\n\tasync (args: IDataObject) => {\n\t\tlet result: Awaited<ReturnType<Client['callTool']>>;\n\n\t\tfunction handleError(error: unknown) {\n\t\t\tconst errorDescription =\n\t\t\t\tgetErrorDescriptionFromToolCall(error) ?? `Failed to execute tool \"${name}\"`;\n\t\t\tonError(errorDescription);\n\t\t\treturn errorDescription;\n\t\t}\n\n\t\ttry {\n\t\t\tresult = await client.callTool({ name, arguments: args }, CompatibilityCallToolResultSchema, {\n\t\t\t\ttimeout,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\treturn handleError(error);\n\t\t}\n\n\t\tif (result.isError) {\n\t\t\treturn handleError(result);\n\t\t}\n\n\t\tif (result.toolResult !== undefined) {\n\t\t\treturn result.toolResult;\n\t\t}\n\n\t\tif (result.content !== undefined) {\n\t\t\treturn result.content;\n\t\t}\n\n\t\treturn result;\n\t};\n\nexport function mcpToolToDynamicTool(\n\ttool: McpTool,\n\tonCallTool: DynamicStructuredToolInput['func'],\n): DynamicStructuredTool {\n\tconst rawSchema = convertJsonSchemaToZod(tool.inputSchema);\n\n\t// Ensure we always have an object schema for structured tools\n\tconst objectSchema =\n\t\trawSchema instanceof z.ZodObject ? rawSchema : z.object({ value: rawSchema });\n\n\treturn new DynamicStructuredTool({\n\t\tname: tool.name,\n\t\tdescription: tool.description ?? '',\n\t\tschema: objectSchema,\n\t\tfunc: onCallTool,\n\t\tmetadata: { isFromToolkit: true },\n\t});\n}\n\nexport class McpToolkit extends Toolkit {\n\tconstructor(public tools: DynamicStructuredTool[]) {\n\t\tsuper();\n\t}\n}\n\nfunction safeCreateUrl(url: string, baseUrl?: string | URL): Result<URL, Error> {\n\ttry {\n\t\treturn createResultOk(new URL(url, baseUrl));\n\t} catch (error) {\n\t\treturn createResultError(error);\n\t}\n}\n\nfunction normalizeAndValidateUrl(input: string): Result<URL, Error> {\n\tconst withProtocol = !/^https?:\\/\\//i.test(input) ? `https://${input}` : input;\n\tconst parsedUrl = safeCreateUrl(withProtocol);\n\n\tif (!parsedUrl.ok) {\n\t\treturn createResultError(parsedUrl.error);\n\t}\n\n\treturn parsedUrl;\n}\n\nfunction isUnauthorizedError(error: unknown): boolean {\n\treturn (\n\t\t!!error &&\n\t\ttypeof error === 'object' &&\n\t\t(('code' in error && Number(error.code) === 401) ||\n\t\t\t('message' in error && typeof error.message === 'string' && error.message.includes('401')))\n\t);\n}\n\ntype OnUnauthorizedHandler = (\n\theaders?: Record<string, string>,\n) => Promise<Record<string, string> | null>;\n\ntype ConnectMcpClientError =\n\t| { type: 'invalid_url'; error: Error }\n\t| { type: 'connection'; error: Error };\n\nexport async function connectMcpClient({\n\theaders,\n\tserverTransport,\n\tendpointUrl,\n\tname,\n\tversion,\n\tonUnauthorized,\n}: {\n\tserverTransport: McpServerTransport;\n\tendpointUrl: string;\n\theaders?: Record<string, string>;\n\tname: string;\n\tversion: number;\n\tonUnauthorized?: OnUnauthorizedHandler;\n}): Promise<Result<Client, ConnectMcpClientError>> {\n\tconst endpoint = normalizeAndValidateUrl(endpointUrl);\n\n\tif (!endpoint.ok) {\n\t\treturn createResultError({ type: 'invalid_url', error: endpoint.error });\n\t}\n\n\tconst client = new Client({ name, version: version.toString() }, { capabilities: { tools: {} } });\n\n\tif (serverTransport === 'httpStreamable') {\n\t\ttry {\n\t\t\tconst transport = new StreamableHTTPClientTransport(endpoint.result, {\n\t\t\t\trequestInit: { headers },\n\t\t\t\tfetch: proxyFetch,\n\t\t\t});\n\t\t\tawait client.connect(transport);\n\t\t\treturn createResultOk(client);\n\t\t} catch (error) {\n\t\t\tif (onUnauthorized && isUnauthorizedError(error)) {\n\t\t\t\tconst newHeaders = await onUnauthorized(headers);\n\t\t\t\tif (newHeaders) {\n\t\t\t\t\t// Don't pass `onUnauthorized` to avoid possible infinite recursion\n\t\t\t\t\treturn await connectMcpClient({\n\t\t\t\t\t\theaders: newHeaders,\n\t\t\t\t\t\tserverTransport,\n\t\t\t\t\t\tendpointUrl,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn createResultError({ type: 'connection', error });\n\t\t}\n\t}\n\n\ttry {\n\t\tconst sseTransport = new SSEClientTransport(endpoint.result, {\n\t\t\teventSourceInit: {\n\t\t\t\tfetch: async (url, init) =>\n\t\t\t\t\tawait proxyFetch(url, {\n\t\t\t\t\t\t...init,\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t...headers,\n\t\t\t\t\t\t\tAccept: 'text/event-stream',\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t},\n\t\t\tfetch: proxyFetch,\n\t\t\trequestInit: { headers },\n\t\t});\n\t\tawait client.connect(sseTransport);\n\t\treturn createResultOk(client);\n\t} catch (error) {\n\t\tif (onUnauthorized && isUnauthorizedError(error)) {\n\t\t\tconst newHeaders = await onUnauthorized(headers);\n\t\t\tif (newHeaders) {\n\t\t\t\t// Don't pass `onUnauthorized` to avoid possible infinite recursion\n\t\t\t\treturn await connectMcpClient({\n\t\t\t\t\theaders: newHeaders,\n\t\t\t\t\tserverTransport,\n\t\t\t\t\tendpointUrl,\n\t\t\t\t\tname,\n\t\t\t\t\tversion,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn createResultError({ type: 'connection', error });\n\t}\n}\n\nexport async function getAuthHeaders(\n\tctx: Pick<IExecuteFunctions, 'getCredentials'>,\n\tauthentication: McpAuthenticationOption,\n): Promise<{ headers?: Record<string, string> }> {\n\tswitch (authentication) {\n\t\tcase 'headerAuth': {\n\t\t\tconst header = await ctx\n\t\t\t\t.getCredentials<{ name: string; value: string }>('httpHeaderAuth')\n\t\t\t\t.catch(() => null);\n\n\t\t\tif (!header) return {};\n\n\t\t\treturn { headers: { [header.name]: header.value } };\n\t\t}\n\t\tcase 'bearerAuth': {\n\t\t\tconst result = await ctx\n\t\t\t\t.getCredentials<{ token: string }>('httpBearerAuth')\n\t\t\t\t.catch(() => null);\n\n\t\t\tif (!result) return {};\n\n\t\t\treturn { headers: { Authorization: `Bearer ${result.token}` } };\n\t\t}\n\t\tcase 'mcpOAuth2Api': {\n\t\t\tconst result = await ctx\n\t\t\t\t.getCredentials<{ oauthTokenData: { access_token: string } }>('mcpOAuth2Api')\n\t\t\t\t.catch(() => null);\n\n\t\t\tif (!result) return {};\n\n\t\t\treturn { headers: { Authorization: `Bearer ${result.oauthTokenData.access_token}` } };\n\t\t}\n\t\tcase 'multipleHeadersAuth': {\n\t\t\tconst result = await ctx\n\t\t\t\t.getCredentials<{ headers: { values: Array<{ name: string; value: string }> } }>(\n\t\t\t\t\t'httpMultipleHeadersAuth',\n\t\t\t\t)\n\t\t\t\t.catch(() => null);\n\n\t\t\tif (!result) return {};\n\n\t\t\treturn {\n\t\t\t\theaders: result.headers.values.reduce(\n\t\t\t\t\t(acc, cur) => {\n\t\t\t\t\t\tacc[cur.name] = cur.value;\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{} as Record<string, string>,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t\tcase 'none':\n\t\tdefault: {\n\t\t\treturn {};\n\t\t}\n\t}\n}\n\n/**\n * Tries to refresh the OAuth2 token, storing them in the database if successful\n * @param ctx - The execution context\n * @param authentication - The authentication method\n * @param headers - The headers to refresh\n * @returns The refreshed headers or null if the authentication method is not oAuth2Api or has failed\n */\nexport async function tryRefreshOAuth2Token(\n\tctx: IExecuteFunctions | ISupplyDataFunctions | ILoadOptionsFunctions,\n\tauthentication: McpAuthenticationOption,\n\theaders?: Record<string, string>,\n) {\n\tif (authentication !== 'mcpOAuth2Api') {\n\t\treturn null;\n\t}\n\n\tlet access_token: string | null = null;\n\ttry {\n\t\tconst result = (await ctx.helpers.refreshOAuth2Token.call(\n\t\t\tctx,\n\t\t\t'mcpOAuth2Api',\n\t\t)) as ClientOAuth2TokenData;\n\t\taccess_token = result?.access_token;\n\t} catch (error) {\n\t\treturn null;\n\t}\n\n\tif (!access_token) {\n\t\treturn null;\n\t}\n\n\tif (!headers) {\n\t\treturn {\n\t\t\tAuthorization: `Bearer ${access_token}`,\n\t\t};\n\t}\n\n\tre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 @@ const limitWaitTimeOption = {
|
|
|
120
120
|
class Chat {
|
|
121
121
|
constructor() {
|
|
122
122
|
this.description = {
|
|
123
|
+
usableAsTool: true,
|
|
123
124
|
displayName: "Respond to Chat",
|
|
124
125
|
name: "chat",
|
|
125
126
|
icon: "fa:comments",
|
|
@@ -167,7 +168,8 @@ class Chat {
|
|
|
167
168
|
displayName: "Wait for User Reply",
|
|
168
169
|
name: import_n8n_workflow.CHAT_WAIT_USER_REPLY,
|
|
169
170
|
type: "boolean",
|
|
170
|
-
default: true
|
|
171
|
+
default: true,
|
|
172
|
+
noDataExpression: true
|
|
171
173
|
},
|
|
172
174
|
{
|
|
173
175
|
displayName: "Options",
|
|
@@ -175,6 +177,11 @@ class Chat {
|
|
|
175
177
|
type: "collection",
|
|
176
178
|
placeholder: "Add Option",
|
|
177
179
|
default: {},
|
|
180
|
+
displayOptions: {
|
|
181
|
+
hide: {
|
|
182
|
+
"@tool": [true]
|
|
183
|
+
}
|
|
184
|
+
},
|
|
178
185
|
options: [
|
|
179
186
|
{
|
|
180
187
|
displayName: "Add Memory Input Connection",
|
|
@@ -184,6 +191,20 @@ class Chat {
|
|
|
184
191
|
},
|
|
185
192
|
limitWaitTimeOption
|
|
186
193
|
]
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
displayName: "Options",
|
|
197
|
+
name: "options",
|
|
198
|
+
type: "collection",
|
|
199
|
+
placeholder: "Add Option",
|
|
200
|
+
default: {},
|
|
201
|
+
options: [limitWaitTimeOption],
|
|
202
|
+
displayOptions: {
|
|
203
|
+
show: {
|
|
204
|
+
"@tool": [true],
|
|
205
|
+
[`/${import_n8n_workflow.CHAT_WAIT_USER_REPLY}`]: [true]
|
|
206
|
+
}
|
|
207
|
+
}
|
|
187
208
|
}
|
|
188
209
|
]
|
|
189
210
|
};
|
|
@@ -208,9 +229,15 @@ class Chat {
|
|
|
208
229
|
const connectedNodes = this.getParentNodes(this.getNode().name, {
|
|
209
230
|
includeNodeParameters: true
|
|
210
231
|
});
|
|
211
|
-
|
|
232
|
+
let chatTrigger = connectedNodes.find(
|
|
212
233
|
(node) => node.type === import_n8n_workflow.CHAT_TRIGGER_NODE_TYPE && !node.disabled
|
|
213
234
|
);
|
|
235
|
+
if (!chatTrigger) {
|
|
236
|
+
try {
|
|
237
|
+
chatTrigger = this.getChatTrigger();
|
|
238
|
+
} catch (error) {
|
|
239
|
+
}
|
|
240
|
+
}
|
|
214
241
|
if (!chatTrigger) {
|
|
215
242
|
throw new import_n8n_workflow.NodeOperationError(
|
|
216
243
|
this.getNode(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/trigger/ChatTrigger/Chat.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { BaseChatMemory } from 'langchain/memory';\nimport {\n\tCHAT_TRIGGER_NODE_TYPE,\n\tCHAT_WAIT_USER_REPLY,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n} from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeTypeDescription,\n\tINodeType,\n\tINodeProperties,\n} from 'n8n-workflow';\n\nimport { configureInputs, configureWaitTillDate } from './util';\n\nconst limitWaitTimeProperties: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Limit Type',\n\t\tname: 'limitType',\n\t\ttype: 'options',\n\t\tdefault: 'afterTimeInterval',\n\t\tdescription:\n\t\t\t'Sets the condition for the execution to resume. Can be a specified date or after some time.',\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'After Time Interval',\n\t\t\t\tdescription: 'Waits for a certain amount of time',\n\t\t\t\tvalue: 'afterTimeInterval',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'At Specified Time',\n\t\t\t\tdescription: 'Waits until the set date and time to continue',\n\t\t\t\tvalue: 'atSpecifiedTime',\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tdisplayName: 'Amount',\n\t\tname: 'resumeAmount',\n\t\ttype: 'number',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['afterTimeInterval'],\n\t\t\t},\n\t\t},\n\t\ttypeOptions: {\n\t\t\tminValue: 0,\n\t\t\tnumberPrecision: 2,\n\t\t},\n\t\tdefault: 1,\n\t\tdescription: 'The time to wait',\n\t},\n\t{\n\t\tdisplayName: 'Unit',\n\t\tname: 'resumeUnit',\n\t\ttype: 'options',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['afterTimeInterval'],\n\t\t\t},\n\t\t},\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'Minutes',\n\t\t\t\tvalue: 'minutes',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Hours',\n\t\t\t\tvalue: 'hours',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Days',\n\t\t\t\tvalue: 'days',\n\t\t\t},\n\t\t],\n\t\tdefault: 'hours',\n\t\tdescription: 'Unit of the interval value',\n\t},\n\t{\n\t\tdisplayName: 'Max Date and Time',\n\t\tname: 'maxDateAndTime',\n\t\ttype: 'dateTime',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['atSpecifiedTime'],\n\t\t\t},\n\t\t},\n\t\tdefault: '',\n\t\tdescription: 'Continue execution after the specified date and time',\n\t},\n];\n\nconst limitWaitTimeOption: INodeProperties = {\n\tdisplayName: 'Limit Wait Time',\n\tname: 'limitWaitTime',\n\ttype: 'fixedCollection',\n\tdescription:\n\t\t'Whether to limit the time this node should wait for a user response before execution resumes',\n\tdefault: { values: { limitType: 'afterTimeInterval', resumeAmount: 45, resumeUnit: 'minutes' } },\n\toptions: [\n\t\t{\n\t\t\tdisplayName: 'Values',\n\t\t\tname: 'values',\n\t\t\tvalues: limitWaitTimeProperties,\n\t\t},\n\t],\n\tdisplayOptions: {\n\t\tshow: {\n\t\t\t[`/${CHAT_WAIT_USER_REPLY}`]: [true],\n\t\t},\n\t},\n};\n\nexport class Chat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Respond to Chat',\n\t\tname: 'chat',\n\t\ticon: 'fa:comments',\n\t\ticonColor: 'black',\n\t\tgroup: ['input'],\n\t\tversion: 1,\n\t\tdescription: 'Send a message to a chat',\n\t\tdefaults: {\n\t\t\tname: 'Respond to Chat',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['Core Nodes', 'HITL'],\n\t\t\tsubcategories: {\n\t\t\t\tHITL: ['Human in the Loop'],\n\t\t\t},\n\t\t\talias: ['human', 'wait', 'hitl'],\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.chat/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: `={{ (${configureInputs})($parameter) }}`,\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t\"Verify you're using a chat trigger with the 'Response Mode' option set to 'Using Response Nodes'\",\n\t\t\t\tname: 'generalNotice',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Message',\n\t\t\t\tname: 'message',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 6,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Wait for User Reply',\n\t\t\t\tname: CHAT_WAIT_USER_REPLY,\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Add Memory Input Connection',\n\t\t\t\t\t\tname: 'memoryConnection',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t\tlimitWaitTimeOption,\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync onMessage(\n\t\tcontext: IExecuteFunctions,\n\t\tdata: INodeExecutionData,\n\t): Promise<INodeExecutionData[][]> {\n\t\tconst options = context.getNodeParameter('options', 0, {}) as {\n\t\t\tmemoryConnection?: boolean;\n\t\t};\n\n\t\tconst waitForReply = context.getNodeParameter(CHAT_WAIT_USER_REPLY, 0, true) as boolean;\n\n\t\tif (!waitForReply) {\n\t\t\tconst inputData = context.getInputData();\n\t\t\treturn [inputData];\n\t\t}\n\n\t\tif (options.memoryConnection) {\n\t\t\tconst memory = (await context.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t\t\t| BaseChatMemory\n\t\t\t\t| undefined;\n\n\t\t\tconst message = data.json?.chatInput;\n\n\t\t\tif (memory && message) {\n\t\t\t\tawait memory.chatHistory.addUserMessage(message as string);\n\t\t\t}\n\t\t}\n\n\t\treturn [[data]];\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst connectedNodes = this.getParentNodes(this.getNode().name, {\n\t\t\tincludeNodeParameters: true,\n\t\t});\n\n\t\tconst chatTrigger = connectedNodes.find(\n\t\t\t(node) => node.type === CHAT_TRIGGER_NODE_TYPE && !node.disabled,\n\t\t);\n\n\t\tif (!chatTrigger) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Workflow must be started from a chat trigger node',\n\t\t\t);\n\t\t}\n\n\t\tconst parameters = chatTrigger.parameters as {\n\t\t\tmode?: 'hostedChat' | 'webhook';\n\t\t\toptions: { responseMode: 'lastNode' | 'responseNodes' | 'streaming' | 'responseNode' };\n\t\t};\n\n\t\tif (parameters.mode === 'webhook') {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'\"Embeded chat\" is not supported, change the \"Mode\" in the chat trigger node to the \"Hosted Chat\"',\n\t\t\t);\n\t\t}\n\n\t\tif (parameters.options.responseMode !== 'responseNodes') {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'\"Response Mode\" in the chat trigger node must be set to \"Respond Nodes\"',\n\t\t\t);\n\t\t}\n\n\t\tconst message = (this.getNodeParameter('message', 0) as string) ?? '';\n\t\tconst options = this.getNodeParameter('options', 0, {}) as {\n\t\t\tmemoryConnection?: boolean;\n\t\t};\n\n\t\tif (options.memoryConnection) {\n\t\t\tconst memory = (await this.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t\t\t| BaseChatMemory\n\t\t\t\t| undefined;\n\n\t\t\tif (memory) {\n\t\t\t\tawait memory.chatHistory.addAIChatMessage(message);\n\t\t\t}\n\t\t}\n\n\t\tconst waitTill = configureWaitTillDate(this);\n\n\t\tawait this.putExecutionToWait(waitTill);\n\t\treturn [[{ json: {}, sendMessage: message }]];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAKO;AASP,kBAAuD;AAEvD,MAAM,0BAA6C;AAAA,EAClD;AAAA,IACC,aAAa;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aACC;AAAA,IACD,SAAS;AAAA,MACR;AAAA,QACC,MAAM;AAAA,QACN,aAAa;AAAA,QACb,OAAO;AAAA,MACR;AAAA,MACA;AAAA,QACC,MAAM;AAAA,QACN,aAAa;AAAA,QACb,OAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAAA,EACA;AAAA,IACC,aAAa;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AAAA,IACN,gBAAgB;AAAA,MACf,MAAM;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M,KAAK,mBAAmB,QAAQ;AACtC,WAAO,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,aAAa,QAAQ,CAAC,CAAC;AAAA,EAC7C;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/trigger/ChatTrigger/Chat.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { BaseChatMemory } from 'langchain/memory';\nimport {\n\tCHAT_TRIGGER_NODE_TYPE,\n\tCHAT_WAIT_USER_REPLY,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n} from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeTypeDescription,\n\tINodeType,\n\tINodeProperties,\n\tNodeTypeAndVersion,\n\tINode,\n} from 'n8n-workflow';\n\nimport { configureInputs, configureWaitTillDate } from './util';\n\nconst limitWaitTimeProperties: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Limit Type',\n\t\tname: 'limitType',\n\t\ttype: 'options',\n\t\tdefault: 'afterTimeInterval',\n\t\tdescription:\n\t\t\t'Sets the condition for the execution to resume. Can be a specified date or after some time.',\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'After Time Interval',\n\t\t\t\tdescription: 'Waits for a certain amount of time',\n\t\t\t\tvalue: 'afterTimeInterval',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'At Specified Time',\n\t\t\t\tdescription: 'Waits until the set date and time to continue',\n\t\t\t\tvalue: 'atSpecifiedTime',\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tdisplayName: 'Amount',\n\t\tname: 'resumeAmount',\n\t\ttype: 'number',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['afterTimeInterval'],\n\t\t\t},\n\t\t},\n\t\ttypeOptions: {\n\t\t\tminValue: 0,\n\t\t\tnumberPrecision: 2,\n\t\t},\n\t\tdefault: 1,\n\t\tdescription: 'The time to wait',\n\t},\n\t{\n\t\tdisplayName: 'Unit',\n\t\tname: 'resumeUnit',\n\t\ttype: 'options',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['afterTimeInterval'],\n\t\t\t},\n\t\t},\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'Minutes',\n\t\t\t\tvalue: 'minutes',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Hours',\n\t\t\t\tvalue: 'hours',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Days',\n\t\t\t\tvalue: 'days',\n\t\t\t},\n\t\t],\n\t\tdefault: 'hours',\n\t\tdescription: 'Unit of the interval value',\n\t},\n\t{\n\t\tdisplayName: 'Max Date and Time',\n\t\tname: 'maxDateAndTime',\n\t\ttype: 'dateTime',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['atSpecifiedTime'],\n\t\t\t},\n\t\t},\n\t\tdefault: '',\n\t\tdescription: 'Continue execution after the specified date and time',\n\t},\n];\n\nconst limitWaitTimeOption: INodeProperties = {\n\tdisplayName: 'Limit Wait Time',\n\tname: 'limitWaitTime',\n\ttype: 'fixedCollection',\n\tdescription:\n\t\t'Whether to limit the time this node should wait for a user response before execution resumes',\n\tdefault: { values: { limitType: 'afterTimeInterval', resumeAmount: 45, resumeUnit: 'minutes' } },\n\toptions: [\n\t\t{\n\t\t\tdisplayName: 'Values',\n\t\t\tname: 'values',\n\t\t\tvalues: limitWaitTimeProperties,\n\t\t},\n\t],\n\tdisplayOptions: {\n\t\tshow: {\n\t\t\t[`/${CHAT_WAIT_USER_REPLY}`]: [true],\n\t\t},\n\t},\n};\n\nexport class Chat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tusableAsTool: true,\n\t\tdisplayName: 'Respond to Chat',\n\t\tname: 'chat',\n\t\ticon: 'fa:comments',\n\t\ticonColor: 'black',\n\t\tgroup: ['input'],\n\t\tversion: 1,\n\t\tdescription: 'Send a message to a chat',\n\t\tdefaults: {\n\t\t\tname: 'Respond to Chat',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['Core Nodes', 'HITL'],\n\t\t\tsubcategories: {\n\t\t\t\tHITL: ['Human in the Loop'],\n\t\t\t},\n\t\t\talias: ['human', 'wait', 'hitl'],\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.chat/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: `={{ (${configureInputs})($parameter) }}`,\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t\"Verify you're using a chat trigger with the 'Response Mode' option set to 'Using Response Nodes'\",\n\t\t\t\tname: 'generalNotice',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Message',\n\t\t\t\tname: 'message',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 6,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Wait for User Reply',\n\t\t\t\tname: CHAT_WAIT_USER_REPLY,\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: true,\n\t\t\t\tnoDataExpression: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\thide: {\n\t\t\t\t\t\t'@tool': [true],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Add Memory Input Connection',\n\t\t\t\t\t\tname: 'memoryConnection',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t\tlimitWaitTimeOption,\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [limitWaitTimeOption],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@tool': [true],\n\t\t\t\t\t\t[`/${CHAT_WAIT_USER_REPLY}`]: [true],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t};\n\n\tasync onMessage(\n\t\tcontext: IExecuteFunctions,\n\t\tdata: INodeExecutionData,\n\t): Promise<INodeExecutionData[][]> {\n\t\tconst options = context.getNodeParameter('options', 0, {}) as {\n\t\t\tmemoryConnection?: boolean;\n\t\t};\n\n\t\tconst waitForReply = context.getNodeParameter(CHAT_WAIT_USER_REPLY, 0, true) as boolean;\n\n\t\tif (!waitForReply) {\n\t\t\tconst inputData = context.getInputData();\n\t\t\treturn [inputData];\n\t\t}\n\n\t\tif (options.memoryConnection) {\n\t\t\tconst memory = (await context.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t\t\t| BaseChatMemory\n\t\t\t\t| undefined;\n\n\t\t\tconst message = data.json?.chatInput;\n\n\t\t\tif (memory && message) {\n\t\t\t\tawait memory.chatHistory.addUserMessage(message as string);\n\t\t\t}\n\t\t}\n\n\t\treturn [[data]];\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst connectedNodes = this.getParentNodes(this.getNode().name, {\n\t\t\tincludeNodeParameters: true,\n\t\t});\n\n\t\tlet chatTrigger: INode | NodeTypeAndVersion | undefined | null = connectedNodes.find(\n\t\t\t(node) => node.type === CHAT_TRIGGER_NODE_TYPE && !node.disabled,\n\t\t);\n\n\t\tif (!chatTrigger) {\n\t\t\ttry {\n\t\t\t\t// try to get chat trigger from workflow if node working as a tool\n\t\t\t\tchatTrigger = this.getChatTrigger();\n\t\t\t} catch (error) {}\n\t\t}\n\n\t\tif (!chatTrigger) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Workflow must be started from a chat trigger node',\n\t\t\t);\n\t\t}\n\n\t\tconst parameters = chatTrigger.parameters as {\n\t\t\tmode?: 'hostedChat' | 'webhook';\n\t\t\toptions: { responseMode: 'lastNode' | 'responseNodes' | 'streaming' | 'responseNode' };\n\t\t};\n\n\t\tif (parameters.mode === 'webhook') {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'\"Embeded chat\" is not supported, change the \"Mode\" in the chat trigger node to the \"Hosted Chat\"',\n\t\t\t);\n\t\t}\n\n\t\tif (parameters.options.responseMode !== 'responseNodes') {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'\"Response Mode\" in the chat trigger node must be set to \"Respond Nodes\"',\n\t\t\t);\n\t\t}\n\n\t\tconst message = (this.getNodeParameter('message', 0) as string) ?? '';\n\t\tconst options = this.getNodeParameter('options', 0, {}) as {\n\t\t\tmemoryConnection?: boolean;\n\t\t};\n\n\t\tif (options.memoryConnection) {\n\t\t\tconst memory = (await this.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t\t\t| BaseChatMemory\n\t\t\t\t| undefined;\n\n\t\t\tif (memory) {\n\t\t\t\tawait memory.chatHistory.addAIChatMessage(message);\n\t\t\t}\n\t\t}\n\n\t\tconst waitTill = configureWaitTillDate(this);\n\n\t\tawait this.putExecutionToWait(waitTill);\n\t\treturn [[{ json: {}, sendMessage: message }]];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAKO;AAWP,kBAAuD;AAEvD,M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