@n8n/n8n-nodes-langchain 1.87.1 → 1.89.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.
Files changed (54) hide show
  1. package/dist/credentials/MilvusApi.credentials.js +72 -0
  2. package/dist/credentials/MilvusApi.credentials.js.map +1 -0
  3. package/dist/credentials/QdrantApi.credentials.js +1 -3
  4. package/dist/credentials/QdrantApi.credentials.js.map +1 -1
  5. package/dist/credentials/SearXngApi.credentials.js +44 -0
  6. package/dist/credentials/SearXngApi.credentials.js.map +1 -0
  7. package/dist/known/credentials.json +14 -0
  8. package/dist/known/nodes.json +16 -0
  9. package/dist/methods/defined.json +3 -0
  10. package/dist/methods/referenced.json +3 -0
  11. package/dist/nodes/agents/Agent/Agent.node.js +1 -1
  12. package/dist/nodes/agents/Agent/Agent.node.js.map +1 -1
  13. package/dist/nodes/agents/Agent/agents/ToolsAgent/execute.js +11 -5
  14. package/dist/nodes/agents/Agent/agents/ToolsAgent/execute.js.map +1 -1
  15. package/dist/nodes/llms/LmChatXAiGrok/LmChatXAiGrok.node.js +6 -3
  16. package/dist/nodes/llms/LmChatXAiGrok/LmChatXAiGrok.node.js.map +1 -1
  17. package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js +258 -0
  18. package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js.map +1 -0
  19. package/dist/nodes/mcp/McpClientTool/loadOptions.js +51 -0
  20. package/dist/nodes/mcp/McpClientTool/loadOptions.js.map +1 -0
  21. package/dist/nodes/mcp/McpClientTool/types.js +17 -0
  22. package/dist/nodes/mcp/McpClientTool/types.js.map +1 -0
  23. package/dist/nodes/mcp/McpClientTool/utils.js +192 -0
  24. package/dist/nodes/mcp/McpClientTool/utils.js.map +1 -0
  25. package/dist/nodes/mcp/McpTrigger/FlushingSSEServerTransport.js +39 -0
  26. package/dist/nodes/mcp/McpTrigger/FlushingSSEServerTransport.js.map +1 -0
  27. package/dist/nodes/mcp/McpTrigger/McpServer.js +179 -0
  28. package/dist/nodes/mcp/McpTrigger/McpServer.js.map +1 -0
  29. package/dist/nodes/mcp/McpTrigger/McpTrigger.node.js +181 -0
  30. package/dist/nodes/mcp/McpTrigger/McpTrigger.node.js.map +1 -0
  31. package/dist/nodes/mcp/mcp.dark.svg +7 -0
  32. package/dist/nodes/mcp/mcp.svg +7 -0
  33. package/dist/nodes/tools/ToolSearXng/ToolSearXng.node.js +136 -0
  34. package/dist/nodes/tools/ToolSearXng/ToolSearXng.node.js.map +1 -0
  35. package/dist/nodes/tools/ToolSearXng/searXng.svg +1 -0
  36. package/dist/nodes/vector_store/VectorStoreMilvus/VectorStoreMilvus.node.js +106 -0
  37. package/dist/nodes/vector_store/VectorStoreMilvus/VectorStoreMilvus.node.js.map +1 -0
  38. package/dist/nodes/vector_store/VectorStoreMilvus/milvus-icon-black.svg +1 -0
  39. package/dist/nodes/vector_store/VectorStoreMilvus/milvus-icon-white.svg +1 -0
  40. package/dist/nodes/vector_store/VectorStoreQdrant/Qdrant.utils.js +54 -0
  41. package/dist/nodes/vector_store/VectorStoreQdrant/Qdrant.utils.js.map +1 -0
  42. package/dist/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.js +5 -4
  43. package/dist/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.js.map +1 -1
  44. package/dist/nodes/vector_store/shared/createVectorStoreNode/methods/listSearch.js +18 -5
  45. package/dist/nodes/vector_store/shared/createVectorStoreNode/methods/listSearch.js.map +1 -1
  46. package/dist/nodes/vector_store/shared/descriptions.js +24 -0
  47. package/dist/nodes/vector_store/shared/descriptions.js.map +1 -1
  48. package/dist/types/credentials.json +3 -1
  49. package/dist/types/nodes.json +5 -1
  50. package/dist/utils/helpers.js +7 -1
  51. package/dist/utils/helpers.js.map +1 -1
  52. package/dist/utils/logWrapper.js +9 -2
  53. package/dist/utils/logWrapper.js.map +1 -1
  54. package/package.json +13 -5
@@ -0,0 +1,258 @@
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 McpClientTool_node_exports = {};
20
+ __export(McpClientTool_node_exports, {
21
+ McpClientTool: () => McpClientTool
22
+ });
23
+ module.exports = __toCommonJS(McpClientTool_node_exports);
24
+ var import_n8n_workflow = require("n8n-workflow");
25
+ var import_logWrapper = require("../../../utils/logWrapper");
26
+ var import_sharedFields = require("../../../utils/sharedFields");
27
+ var import_loadOptions = require("./loadOptions");
28
+ var import_utils = require("./utils");
29
+ class McpClientTool {
30
+ constructor() {
31
+ this.description = {
32
+ displayName: "MCP Client Tool",
33
+ name: "mcpClientTool",
34
+ icon: {
35
+ light: "file:../mcp.svg",
36
+ dark: "file:../mcp.dark.svg"
37
+ },
38
+ group: ["output"],
39
+ version: 1,
40
+ description: "Connect tools from an MCP Server",
41
+ defaults: {
42
+ name: "MCP Client"
43
+ },
44
+ codex: {
45
+ categories: ["AI"],
46
+ subcategories: {
47
+ AI: ["Model Context Protocol", "Tools"]
48
+ },
49
+ alias: ["Model Context Protocol", "MCP Client"],
50
+ resources: {
51
+ primaryDocumentation: [
52
+ {
53
+ url: "https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolmcp/"
54
+ }
55
+ ]
56
+ }
57
+ },
58
+ inputs: [],
59
+ outputs: [{ type: import_n8n_workflow.NodeConnectionTypes.AiTool, displayName: "Tools" }],
60
+ credentials: [
61
+ {
62
+ // eslint-disable-next-line n8n-nodes-base/node-class-description-credentials-name-unsuffixed
63
+ name: "httpBearerAuth",
64
+ required: true,
65
+ displayOptions: {
66
+ show: {
67
+ authentication: ["bearerAuth"]
68
+ }
69
+ }
70
+ },
71
+ {
72
+ name: "httpHeaderAuth",
73
+ required: true,
74
+ displayOptions: {
75
+ show: {
76
+ authentication: ["headerAuth"]
77
+ }
78
+ }
79
+ }
80
+ ],
81
+ properties: [
82
+ (0, import_sharedFields.getConnectionHintNoticeField)([import_n8n_workflow.NodeConnectionTypes.AiAgent]),
83
+ {
84
+ displayName: "SSE Endpoint",
85
+ name: "sseEndpoint",
86
+ type: "string",
87
+ description: "SSE Endpoint of your MCP server",
88
+ placeholder: "e.g. https://my-mcp-server.ai/sse",
89
+ default: "",
90
+ required: true
91
+ },
92
+ {
93
+ displayName: "Authentication",
94
+ name: "authentication",
95
+ type: "options",
96
+ options: [
97
+ {
98
+ name: "Bearer Auth",
99
+ value: "bearerAuth"
100
+ },
101
+ {
102
+ name: "Header Auth",
103
+ value: "headerAuth"
104
+ },
105
+ {
106
+ name: "None",
107
+ value: "none"
108
+ }
109
+ ],
110
+ default: "none",
111
+ description: "The way to authenticate with your SSE endpoint"
112
+ },
113
+ {
114
+ displayName: "Credentials",
115
+ name: "credentials",
116
+ type: "credentials",
117
+ default: "",
118
+ displayOptions: {
119
+ show: {
120
+ authentication: ["headerAuth", "bearerAuth"]
121
+ }
122
+ }
123
+ },
124
+ {
125
+ displayName: "Tools to Include",
126
+ name: "include",
127
+ type: "options",
128
+ description: "How to select the tools you want to be exposed to the AI Agent",
129
+ default: "all",
130
+ options: [
131
+ {
132
+ name: "All",
133
+ value: "all",
134
+ description: "Also include all unchanged fields from the input"
135
+ },
136
+ {
137
+ name: "Selected",
138
+ value: "selected",
139
+ description: 'Also include the tools listed in the parameter "Tools to Include"'
140
+ },
141
+ {
142
+ name: "All Except",
143
+ value: "except",
144
+ description: 'Exclude the tools listed in the parameter "Tools to Exclude"'
145
+ }
146
+ ]
147
+ },
148
+ {
149
+ displayName: "Tools to Include",
150
+ name: "includeTools",
151
+ type: "multiOptions",
152
+ default: [],
153
+ description: 'Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
154
+ typeOptions: {
155
+ loadOptionsMethod: "getTools",
156
+ loadOptionsDependsOn: ["sseEndpoint"]
157
+ },
158
+ displayOptions: {
159
+ show: {
160
+ include: ["selected"]
161
+ }
162
+ }
163
+ },
164
+ {
165
+ displayName: "Tools to Exclude",
166
+ name: "excludeTools",
167
+ type: "multiOptions",
168
+ default: [],
169
+ description: 'Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
170
+ typeOptions: {
171
+ loadOptionsMethod: "getTools"
172
+ },
173
+ displayOptions: {
174
+ show: {
175
+ include: ["except"]
176
+ }
177
+ }
178
+ }
179
+ ]
180
+ };
181
+ this.methods = {
182
+ loadOptions: {
183
+ getTools: import_loadOptions.getTools
184
+ }
185
+ };
186
+ }
187
+ async supplyData(itemIndex) {
188
+ const authentication = this.getNodeParameter(
189
+ "authentication",
190
+ itemIndex
191
+ );
192
+ const sseEndpoint = this.getNodeParameter("sseEndpoint", itemIndex);
193
+ const node = this.getNode();
194
+ const { headers } = await (0, import_utils.getAuthHeaders)(this, authentication);
195
+ const client = await (0, import_utils.connectMcpClient)({
196
+ sseEndpoint,
197
+ headers,
198
+ name: node.type,
199
+ version: node.typeVersion
200
+ });
201
+ const setError = (message, description) => {
202
+ const error = new import_n8n_workflow.NodeOperationError(node, message, { itemIndex, description });
203
+ this.addOutputData(import_n8n_workflow.NodeConnectionTypes.AiTool, itemIndex, error);
204
+ throw error;
205
+ };
206
+ if (!client.ok) {
207
+ this.logger.error("McpClientTool: Failed to connect to MCP Server", {
208
+ error: client.error
209
+ });
210
+ switch (client.error.type) {
211
+ case "invalid_url":
212
+ return setError("Could not connect to your MCP server. The provided URL is invalid.");
213
+ case "connection":
214
+ default:
215
+ return setError("Could not connect to your MCP server");
216
+ }
217
+ }
218
+ this.logger.debug("McpClientTool: Successfully connected to MCP Server");
219
+ const mode = this.getNodeParameter("include", itemIndex);
220
+ const includeTools = this.getNodeParameter("includeTools", itemIndex, []);
221
+ const excludeTools = this.getNodeParameter("excludeTools", itemIndex, []);
222
+ const allTools = await (0, import_utils.getAllTools)(client.result);
223
+ const mcpTools = (0, import_utils.getSelectedTools)({
224
+ tools: allTools,
225
+ mode,
226
+ includeTools,
227
+ excludeTools
228
+ });
229
+ if (!mcpTools.length) {
230
+ return setError(
231
+ "MCP Server returned no tools",
232
+ "Connected successfully to your MCP server but it returned an empty list of tools."
233
+ );
234
+ }
235
+ const tools = mcpTools.map(
236
+ (tool) => (0, import_logWrapper.logWrapper)(
237
+ (0, import_utils.mcpToolToDynamicTool)(
238
+ tool,
239
+ (0, import_utils.createCallTool)(tool.name, client.result, (error) => {
240
+ this.logger.error(`McpClientTool: Tool "${tool.name}" failed to execute`, { error });
241
+ throw new import_n8n_workflow.NodeOperationError(node, `Failed to execute tool "${tool.name}"`, {
242
+ description: error
243
+ });
244
+ })
245
+ ),
246
+ this
247
+ )
248
+ );
249
+ this.logger.debug(`McpClientTool: Connected to MCP Server with ${tools.length} tools`);
250
+ const toolkit = new import_utils.McpToolkit(tools);
251
+ return { response: toolkit, closeFunction: async () => await client.result.close() };
252
+ }
253
+ }
254
+ // Annotate the CommonJS export names for ESM import in node:
255
+ 0 && (module.exports = {
256
+ McpClientTool
257
+ });
258
+ //# sourceMappingURL=McpClientTool.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../nodes/mcp/McpClientTool/McpClientTool.node.ts"],"sourcesContent":["import {\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 { getTools } from './loadOptions';\nimport type { McpAuthenticationOption, McpToolIncludeMode } from './types';\nimport {\n\tconnectMcpClient,\n\tcreateCallTool,\n\tgetAllTools,\n\tgetAuthHeaders,\n\tgetSelectedTools,\n\tMcpToolkit,\n\tmcpToolToDynamicTool,\n} from './utils';\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,\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],\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},\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 SSE endpoint',\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'],\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],\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 authentication = this.getNodeParameter(\n\t\t\t'authentication',\n\t\t\titemIndex,\n\t\t) as McpAuthenticationOption;\n\t\tconst sseEndpoint = this.getNodeParameter('sseEndpoint', itemIndex) as string;\n\t\tconst node = this.getNode();\n\t\tconst { headers } = await getAuthHeaders(this, authentication);\n\t\tconst client = await connectMcpClient({\n\t\t\tsseEndpoint,\n\t\t\theaders,\n\t\t\tname: node.type,\n\t\t\tversion: node.typeVersion,\n\t\t});\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\tif (!client.ok) {\n\t\t\tthis.logger.error('McpClientTool: Failed to connect to MCP Server', {\n\t\t\t\terror: client.error,\n\t\t\t});\n\n\t\t\tswitch (client.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\tconst mode = this.getNodeParameter('include', itemIndex) as McpToolIncludeMode;\n\t\tconst includeTools = this.getNodeParameter('includeTools', itemIndex, []) as string[];\n\t\tconst excludeTools = this.getNodeParameter('excludeTools', itemIndex, []) as string[];\n\n\t\tconst allTools = await getAllTools(client.result);\n\t\tconst mcpTools = getSelectedTools({\n\t\t\ttools: allTools,\n\t\t\tmode,\n\t\t\tincludeTools,\n\t\t\texcludeTools,\n\t\t});\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.result, (error) => {\n\t\t\t\t\t\tthis.logger.error(`McpClientTool: Tool \"${tool.name}\" failed to execute`, { error });\n\t\t\t\t\t\tthrow new NodeOperationError(node, `Failed to execute tool \"${tool.name}\"`, {\n\t\t\t\t\t\t\tdescription: error,\n\t\t\t\t\t\t});\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.result.close() };\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAOO;AAEP,wBAA2B;AAC3B,0BAA6C;AAE7C,yBAAyB;AAEzB,mBAQO;AAEA,MAAM,cAAmC;AAAA,EAAzC;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,QACL,OAAO;AAAA,QACP,MAAM;AAAA,MACP;AAAA,MACA,OAAO,CAAC,QAAQ;AAAA,MAChB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,0BAA0B,OAAO;AAAA,QACvC;AAAA,QACA,OAAO,CAAC,0BAA0B,YAAY;AAAA,QAC9C,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD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AM,QAAQ;AAErF,UAAM,UAAU,IAAI,wBAAW,KAAK;AAEpC,WAAO,EAAE,UAAU,SAAS,eAAe,YAAY,MAAM,OAAO,OAAO,MAAM,EAAE;AAAA,EACpF;AACD;","names":[]}
@@ -0,0 +1,51 @@
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 loadOptions_exports = {};
20
+ __export(loadOptions_exports, {
21
+ getTools: () => getTools
22
+ });
23
+ module.exports = __toCommonJS(loadOptions_exports);
24
+ var import_n8n_workflow = require("n8n-workflow");
25
+ var import_utils = require("./utils");
26
+ async function getTools() {
27
+ const authentication = this.getNodeParameter("authentication");
28
+ const sseEndpoint = this.getNodeParameter("sseEndpoint");
29
+ const node = this.getNode();
30
+ const { headers } = await (0, import_utils.getAuthHeaders)(this, authentication);
31
+ const client = await (0, import_utils.connectMcpClient)({
32
+ sseEndpoint,
33
+ headers,
34
+ name: node.type,
35
+ version: node.typeVersion
36
+ });
37
+ if (!client.ok) {
38
+ throw new import_n8n_workflow.NodeOperationError(this.getNode(), "Could not connect to your MCP server");
39
+ }
40
+ const tools = await (0, import_utils.getAllTools)(client.result);
41
+ return tools.map((tool) => ({
42
+ name: tool.name,
43
+ value: tool.name,
44
+ description: tool.description
45
+ }));
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ getTools
50
+ });
51
+ //# sourceMappingURL=loadOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../nodes/mcp/McpClientTool/loadOptions.ts"],"sourcesContent":["import {\n\ttype ILoadOptionsFunctions,\n\ttype INodePropertyOptions,\n\tNodeOperationError,\n} from 'n8n-workflow';\n\nimport type { McpAuthenticationOption } from './types';\nimport { connectMcpClient, getAllTools, getAuthHeaders } from './utils';\n\nexport async function getTools(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {\n\tconst authentication = this.getNodeParameter('authentication') as McpAuthenticationOption;\n\tconst sseEndpoint = this.getNodeParameter('sseEndpoint') as string;\n\tconst node = this.getNode();\n\tconst { headers } = await getAuthHeaders(this, authentication);\n\tconst client = await connectMcpClient({\n\t\tsseEndpoint,\n\t\theaders,\n\t\tname: node.type,\n\t\tversion: node.typeVersion,\n\t});\n\n\tif (!client.ok) {\n\t\tthrow new NodeOperationError(this.getNode(), 'Could not connect to your MCP server');\n\t}\n\n\tconst tools = await getAllTools(client.result);\n\treturn tools.map((tool) => ({\n\t\tname: tool.name,\n\t\tvalue: tool.name,\n\t\tdescription: tool.description,\n\t}));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAIO;AAGP,mBAA8D;AAE9D,eAAsB,WAAuE;AAC5F,QAAM,iBAAiB,KAAK,iBAAiB,gBAAgB;AAC7D,QAAM,cAAc,KAAK,iBAAiB,aAAa;AACvD,QAAM,OAAO,KAAK,QAAQ;AAC1B,QAAM,EAAE,QAAQ,IAAI,UAAM,6BAAe,MAAM,cAAc;AAC7D,QAAM,SAAS,UAAM,+BAAiB;AAAA,IACrC;AAAA,IACA;AAAA,IACA,MAAM,KAAK;AAAA,IACX,SAAS,KAAK;AAAA,EACf,CAAC;AAED,MAAI,CAAC,OAAO,IAAI;AACf,UAAM,IAAI,uCAAmB,KAAK,QAAQ,GAAG,sCAAsC;AAAA,EACpF;AAEA,QAAM,QAAQ,UAAM,0BAAY,OAAO,MAAM;AAC7C,SAAO,MAAM,IAAI,CAAC,UAAU;AAAA,IAC3B,MAAM,KAAK;AAAA,IACX,OAAO,KAAK;AAAA,IACZ,aAAa,KAAK;AAAA,EACnB,EAAE;AACH;","names":[]}
@@ -0,0 +1,17 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
17
+ //# sourceMappingURL=types.js.map
@@ -0,0 +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 McpToolIncludeMode = 'all' | 'selected' | 'except';\n\nexport type McpAuthenticationOption = 'none' | 'headerAuth' | 'bearerAuth';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,192 @@
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 utils_exports = {};
20
+ __export(utils_exports, {
21
+ McpToolkit: () => McpToolkit,
22
+ connectMcpClient: () => connectMcpClient,
23
+ createCallTool: () => createCallTool,
24
+ getAllTools: () => getAllTools,
25
+ getAuthHeaders: () => getAuthHeaders,
26
+ getErrorDescriptionFromToolCall: () => getErrorDescriptionFromToolCall,
27
+ getSelectedTools: () => getSelectedTools,
28
+ mcpToolToDynamicTool: () => mcpToolToDynamicTool
29
+ });
30
+ module.exports = __toCommonJS(utils_exports);
31
+ var import_client = require("@modelcontextprotocol/sdk/client/index.js");
32
+ var import_sse = require("@modelcontextprotocol/sdk/client/sse.js");
33
+ var import_types = require("@modelcontextprotocol/sdk/types.js");
34
+ var import_agents = require("langchain/agents");
35
+ var import_tools = require("langchain/tools");
36
+ var import_n8n_workflow = require("n8n-workflow");
37
+ var import_schemaParsing = require("../../../utils/schemaParsing");
38
+ async function getAllTools(client, cursor) {
39
+ const { tools, nextCursor } = await client.listTools({ cursor });
40
+ if (nextCursor) {
41
+ return tools.concat(await getAllTools(client, nextCursor));
42
+ }
43
+ return tools;
44
+ }
45
+ function getSelectedTools({
46
+ mode,
47
+ includeTools,
48
+ excludeTools,
49
+ tools
50
+ }) {
51
+ switch (mode) {
52
+ case "selected": {
53
+ if (!includeTools?.length) return tools;
54
+ const include = new Set(includeTools);
55
+ return tools.filter((tool) => include.has(tool.name));
56
+ }
57
+ case "except": {
58
+ const except = new Set(excludeTools ?? []);
59
+ return tools.filter((tool) => !except.has(tool.name));
60
+ }
61
+ case "all":
62
+ default:
63
+ return tools;
64
+ }
65
+ }
66
+ const getErrorDescriptionFromToolCall = (result) => {
67
+ if (result && typeof result === "object") {
68
+ if ("content" in result && Array.isArray(result.content)) {
69
+ const errorMessage = result.content.find(
70
+ (content) => content && typeof content === "object" && typeof content.text === "string"
71
+ )?.text;
72
+ return errorMessage;
73
+ } else if ("toolResult" in result && typeof result.toolResult === "string") {
74
+ return result.toolResult;
75
+ }
76
+ if ("message" in result && typeof result.message === "string") {
77
+ return result.message;
78
+ }
79
+ }
80
+ return void 0;
81
+ };
82
+ const createCallTool = (name, client, onError) => async (args) => {
83
+ let result;
84
+ try {
85
+ result = await client.callTool({ name, arguments: args }, import_types.CompatibilityCallToolResultSchema);
86
+ } catch (error) {
87
+ return onError(getErrorDescriptionFromToolCall(error));
88
+ }
89
+ if (result.isError) {
90
+ return onError(getErrorDescriptionFromToolCall(result));
91
+ }
92
+ if (result.toolResult !== void 0) {
93
+ return result.toolResult;
94
+ }
95
+ if (result.content !== void 0) {
96
+ return result.content;
97
+ }
98
+ return result;
99
+ };
100
+ function mcpToolToDynamicTool(tool, onCallTool) {
101
+ return new import_tools.DynamicStructuredTool({
102
+ name: tool.name,
103
+ description: tool.description ?? "",
104
+ schema: (0, import_schemaParsing.convertJsonSchemaToZod)(tool.inputSchema),
105
+ func: onCallTool,
106
+ metadata: { isFromToolkit: true }
107
+ });
108
+ }
109
+ class McpToolkit extends import_agents.Toolkit {
110
+ constructor(tools) {
111
+ super();
112
+ this.tools = tools;
113
+ }
114
+ }
115
+ function safeCreateUrl(url, baseUrl) {
116
+ try {
117
+ return (0, import_n8n_workflow.createResultOk)(new URL(url, baseUrl));
118
+ } catch (error) {
119
+ return (0, import_n8n_workflow.createResultError)(error);
120
+ }
121
+ }
122
+ function normalizeAndValidateUrl(input) {
123
+ const withProtocol = !/^https?:\/\//i.test(input) ? `https://${input}` : input;
124
+ const parsedUrl = safeCreateUrl(withProtocol);
125
+ if (!parsedUrl.ok) {
126
+ return (0, import_n8n_workflow.createResultError)(parsedUrl.error);
127
+ }
128
+ return parsedUrl;
129
+ }
130
+ async function connectMcpClient({
131
+ headers,
132
+ sseEndpoint,
133
+ name,
134
+ version
135
+ }) {
136
+ try {
137
+ const endpoint = normalizeAndValidateUrl(sseEndpoint);
138
+ if (!endpoint.ok) {
139
+ return (0, import_n8n_workflow.createResultError)({ type: "invalid_url", error: endpoint.error });
140
+ }
141
+ const transport = new import_sse.SSEClientTransport(endpoint.result, {
142
+ eventSourceInit: {
143
+ fetch: async (url, init) => await fetch(url, {
144
+ ...init,
145
+ headers: {
146
+ ...headers,
147
+ Accept: "text/event-stream"
148
+ }
149
+ })
150
+ },
151
+ requestInit: { headers }
152
+ });
153
+ const client = new import_client.Client(
154
+ { name, version: version.toString() },
155
+ { capabilities: { tools: {} } }
156
+ );
157
+ await client.connect(transport);
158
+ return (0, import_n8n_workflow.createResultOk)(client);
159
+ } catch (error) {
160
+ return (0, import_n8n_workflow.createResultError)({ type: "connection", error });
161
+ }
162
+ }
163
+ async function getAuthHeaders(ctx, authentication) {
164
+ switch (authentication) {
165
+ case "headerAuth": {
166
+ const header = await ctx.getCredentials("httpHeaderAuth").catch(() => null);
167
+ if (!header) return {};
168
+ return { headers: { [header.name]: header.value } };
169
+ }
170
+ case "bearerAuth": {
171
+ const result = await ctx.getCredentials("httpBearerAuth").catch(() => null);
172
+ if (!result) return {};
173
+ return { headers: { Authorization: `Bearer ${result.token}` } };
174
+ }
175
+ case "none":
176
+ default: {
177
+ return {};
178
+ }
179
+ }
180
+ }
181
+ // Annotate the CommonJS export names for ESM import in node:
182
+ 0 && (module.exports = {
183
+ McpToolkit,
184
+ connectMcpClient,
185
+ createCallTool,
186
+ getAllTools,
187
+ getAuthHeaders,
188
+ getErrorDescriptionFromToolCall,
189
+ getSelectedTools,
190
+ mcpToolToDynamicTool
191
+ });
192
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../nodes/mcp/McpClientTool/utils.ts"],"sourcesContent":["import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';\nimport { CompatibilityCallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport { Toolkit } from 'langchain/agents';\nimport { DynamicStructuredTool, type DynamicStructuredToolInput } from 'langchain/tools';\nimport {\n\tcreateResultError,\n\tcreateResultOk,\n\ttype IDataObject,\n\ttype IExecuteFunctions,\n\ttype Result,\n} from 'n8n-workflow';\nimport { type ZodTypeAny } from 'zod';\n\nimport { convertJsonSchemaToZod } from '@utils/schemaParsing';\n\nimport type { McpAuthenticationOption, McpTool, McpToolIncludeMode } 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, onError: (error: string | undefined) => void) =>\n\tasync (args: IDataObject) => {\n\t\tlet result: Awaited<ReturnType<Client['callTool']>>;\n\t\ttry {\n\t\t\tresult = await client.callTool({ name, arguments: args }, CompatibilityCallToolResultSchema);\n\t\t} catch (error) {\n\t\t\treturn onError(getErrorDescriptionFromToolCall(error));\n\t\t}\n\n\t\tif (result.isError) {\n\t\t\treturn onError(getErrorDescriptionFromToolCall(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) {\n\treturn new DynamicStructuredTool({\n\t\tname: tool.name,\n\t\tdescription: tool.description ?? '',\n\t\tschema: convertJsonSchemaToZod(tool.inputSchema),\n\t\tfunc: onCallTool,\n\t\tmetadata: { isFromToolkit: true },\n\t});\n}\n\nexport class McpToolkit extends Toolkit {\n\tconstructor(public tools: Array<DynamicStructuredTool<ZodTypeAny>>) {\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\ntype ConnectMcpClientError =\n\t| { type: 'invalid_url'; error: Error }\n\t| { type: 'connection'; error: Error };\nexport async function connectMcpClient({\n\theaders,\n\tsseEndpoint,\n\tname,\n\tversion,\n}: {\n\tsseEndpoint: string;\n\theaders?: Record<string, string>;\n\tname: string;\n\tversion: number;\n}): Promise<Result<Client, ConnectMcpClientError>> {\n\ttry {\n\t\tconst endpoint = normalizeAndValidateUrl(sseEndpoint);\n\n\t\tif (!endpoint.ok) {\n\t\t\treturn createResultError({ type: 'invalid_url', error: endpoint.error });\n\t\t}\n\n\t\tconst transport = 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\n\t\tconst client = new Client(\n\t\t\t{ name, version: version.toString() },\n\t\t\t{ capabilities: { tools: {} } },\n\t\t);\n\n\t\tawait client.connect(transport);\n\t\treturn createResultOk(client);\n\t} catch (error) {\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 'none':\n\t\tdefault: {\n\t\t\treturn {};\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AACvB,iBAAmC;AACnC,mBAAkD;AAClD,oBAAwB;AACxB,mBAAuE;AACvE,0BAMO;AAGP,2BAAuC;AAIvC,eAAsB,YAAY,QAAgB,QAAqC;AACtF,QAAM,EAAE,OAAO,WAAW,IAAI,MAAM,OAAO,UAAU,EAAE,OAAO,CAAC;AAE/D,MAAI,YAAY;AACf,WAAQ,MAAoB,OAAO,MAAM,YAAY,QAAQ,UAAU,CAAC;AAAA,EACzE;AAEA,SAAO;AACR;AAEO,SAAS,iBAAiB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAKG;AACF,UAAQ,MAAM;AAAA,IACb,KAAK,YAAY;AAChB,UAAI,CAAC,cAAc,OAAQ,QAAO;AAClC,YAAM,UAAU,IAAI,IAAI,YAAY;AACpC,aAAO,MAAM,OAAO,CAAC,SAAS,QAAQ,IAAI,KAAK,IAAI,CAAC;AAAA,IACrD;AAAA,IACA,KAAK,UAAU;AACd,YAAM,SAAS,IAAI,IAAI,gBAAgB,CAAC,CAAC;AACzC,aAAO,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,IAAI,KAAK,IAAI,CAAC;AAAA,IACrD;AAAA,IACA,KAAK;AAAA,IACL;AACC,aAAO;AAAA,EACT;AACD;AAEO,MAAM,kCAAkC,CAAC,WAAwC;AACvF,MAAI,UAAU,OAAO,WAAW,UAAU;AACzC,QAAI,aAAa,UAAU,MAAM,QAAQ,OAAO,OAAO,GAAG;AACzD,YAAM,eAAgB,OAAO,QAAkD;AAAA,QAC9E,CAAC,YAAY,WAAW,OA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cAAc;AAClB,YAAM,SAAS,MAAM,IACnB,eAAkC,gBAAgB,EAClD,MAAM,MAAM,IAAI;AAElB,UAAI,CAAC,OAAQ,QAAO,CAAC;AAErB,aAAO,EAAE,SAAS,EAAE,eAAe,UAAU,OAAO,KAAK,GAAG,EAAE;AAAA,IAC/D;AAAA,IACA,KAAK;AAAA,IACL,SAAS;AACR,aAAO,CAAC;AAAA,IACT;AAAA,EACD;AACD;","names":[]}
@@ -0,0 +1,39 @@
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 FlushingSSEServerTransport_exports = {};
20
+ __export(FlushingSSEServerTransport_exports, {
21
+ FlushingSSEServerTransport: () => FlushingSSEServerTransport
22
+ });
23
+ module.exports = __toCommonJS(FlushingSSEServerTransport_exports);
24
+ var import_sse = require("@modelcontextprotocol/sdk/server/sse.js");
25
+ class FlushingSSEServerTransport extends import_sse.SSEServerTransport {
26
+ constructor(_endpoint, response) {
27
+ super(_endpoint, response);
28
+ this.response = response;
29
+ }
30
+ async send(message) {
31
+ await super.send(message);
32
+ this.response.flush();
33
+ }
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ FlushingSSEServerTransport
38
+ });
39
+ //# sourceMappingURL=FlushingSSEServerTransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../nodes/mcp/McpTrigger/FlushingSSEServerTransport.ts"],"sourcesContent":["import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';\nimport type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';\nimport type { Response } from 'express';\n\nexport type CompressionResponse = Response & {\n\t/**\n\t * `flush()` is defined in the compression middleware.\n\t * This is necessary because the compression middleware sometimes waits\n\t * for a certain amount of data before sending the data to the client\n\t */\n\tflush: () => void;\n};\n\nexport class FlushingSSEServerTransport extends SSEServerTransport {\n\tconstructor(\n\t\t_endpoint: string,\n\t\tprivate response: CompressionResponse,\n\t) {\n\t\tsuper(_endpoint, response);\n\t}\n\n\tasync send(message: JSONRPCMessage): Promise<void> {\n\t\tawait super.send(message);\n\t\tthis.response.flush();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAmC;AAa5B,MAAM,mCAAmC,8BAAmB;AAAA,EAClE,YACC,WACQ,UACP;AACD,UAAM,WAAW,QAAQ;AAFjB;AAAA,EAGT;AAAA,EAEA,MAAM,KAAK,SAAwC;AAClD,UAAM,MAAM,KAAK,OAAO;AACxB,SAAK,SAAS,MAAM;AAAA,EACrB;AACD;","names":[]}