n8n-nodes-mcp-local 0.1.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/LICENSE +21 -0
- package/README.md +118 -0
- package/dist/credentials/McpServerApi.credentials.d.ts +14 -0
- package/dist/credentials/McpServerApi.credentials.d.ts.map +1 -0
- package/dist/credentials/McpServerApi.credentials.js +38 -0
- package/dist/credentials/McpServerApi.credentials.js.map +1 -0
- package/dist/credentials/index.d.ts +2 -0
- package/dist/credentials/index.d.ts.map +1 -0
- package/dist/credentials/index.js +6 -0
- package/dist/credentials/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/McpToolsProvider/McpToolsProvider.node.d.ts +26 -0
- package/dist/nodes/McpToolsProvider/McpToolsProvider.node.d.ts.map +1 -0
- package/dist/nodes/McpToolsProvider/McpToolsProvider.node.js +536 -0
- package/dist/nodes/McpToolsProvider/McpToolsProvider.node.js.map +1 -0
- package/dist/nodes/McpToolsProvider/mcp.svg +7 -0
- package/dist/types.d.ts +71 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/schemaConverter.d.ts +83 -0
- package/dist/utils/schemaConverter.d.ts.map +1 -0
- package/dist/utils/schemaConverter.js +203 -0
- package/dist/utils/schemaConverter.js.map +1 -0
- package/dist/utils/toolsCache.d.ts +57 -0
- package/dist/utils/toolsCache.d.ts.map +1 -0
- package/dist/utils/toolsCache.js +262 -0
- package/dist/utils/toolsCache.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP Tools Provider Node
|
|
4
|
+
*
|
|
5
|
+
* Lädt Tools von einem MCP Server via STDIO und stellt sie
|
|
6
|
+
* dem AI Agent als LangChain Tools zur Verfügung.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Tool caching for instant dropdown loading
|
|
10
|
+
* - Tool selection (all, selected, except)
|
|
11
|
+
* - Debug mode for troubleshooting
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.McpToolsProvider = void 0;
|
|
15
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
16
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
|
|
17
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
18
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
19
|
+
const tools_1 = require("@langchain/core/tools");
|
|
20
|
+
const schemaConverter_js_1 = require("../../utils/schemaConverter.js");
|
|
21
|
+
const toolsCache_js_1 = require("../../utils/toolsCache.js");
|
|
22
|
+
/**
|
|
23
|
+
* Wraps a tool with a Proxy to intercept _call method for n8n logging
|
|
24
|
+
* This mimics how n8n's internal logWrapper works
|
|
25
|
+
*/
|
|
26
|
+
function logWrapperTool(tool, executionContext) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
const toolAny = tool;
|
|
29
|
+
return new Proxy(tool, {
|
|
30
|
+
get: (target, prop) => {
|
|
31
|
+
// Intercept the _call method (this is what LangChain calls internally)
|
|
32
|
+
if (prop === '_call') {
|
|
33
|
+
return async (query) => {
|
|
34
|
+
// Log input to n8n
|
|
35
|
+
const inputData = {
|
|
36
|
+
query,
|
|
37
|
+
tool: {
|
|
38
|
+
name: target.name,
|
|
39
|
+
description: target.description,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
let runIndex = 0;
|
|
43
|
+
try {
|
|
44
|
+
const result = executionContext.addInputData(n8n_workflow_1.NodeConnectionTypes.AiTool, [[{ json: inputData }]]);
|
|
45
|
+
runIndex = result.index;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Input data logging failed - continue anyway
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
// Call the original _call method using any cast to bypass protected
|
|
52
|
+
const originalCall = toolAny._call.bind(target);
|
|
53
|
+
const response = await originalCall(query);
|
|
54
|
+
// Log output to n8n
|
|
55
|
+
try {
|
|
56
|
+
executionContext.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiTool, runIndex, [[{ json: { response } }]]);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Output data logging failed - continue anyway
|
|
60
|
+
}
|
|
61
|
+
return typeof response === 'string' ? response : JSON.stringify(response);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const errorMessage = error.message;
|
|
65
|
+
try {
|
|
66
|
+
const nodeError = new n8n_workflow_1.NodeOperationError(executionContext.getNode(), errorMessage);
|
|
67
|
+
executionContext.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiTool, runIndex, nodeError);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Error output logging failed - continue anyway
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Return all other properties as-is
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
return target[prop];
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates a function that calls the MCP tool
|
|
84
|
+
* Similar to createCallTool from the official n8n MCP utils
|
|
85
|
+
*/
|
|
86
|
+
function createCallTool(toolName, mcpClient, timeout, onError) {
|
|
87
|
+
return async (args) => {
|
|
88
|
+
try {
|
|
89
|
+
const result = await mcpClient.callTool({ name: toolName, arguments: args }, types_js_1.CompatibilityCallToolResultSchema, { timeout });
|
|
90
|
+
// Handle different result formats
|
|
91
|
+
if (result.isError) {
|
|
92
|
+
const errorMsg = getErrorDescription(result) || `Tool "${toolName}" returned an error`;
|
|
93
|
+
onError(errorMsg);
|
|
94
|
+
return errorMsg;
|
|
95
|
+
}
|
|
96
|
+
if (result.toolResult !== undefined) {
|
|
97
|
+
return typeof result.toolResult === 'string'
|
|
98
|
+
? result.toolResult
|
|
99
|
+
: JSON.stringify(result.toolResult);
|
|
100
|
+
}
|
|
101
|
+
if (result.content !== undefined) {
|
|
102
|
+
if (Array.isArray(result.content)) {
|
|
103
|
+
return result.content
|
|
104
|
+
.map((item) => {
|
|
105
|
+
if (item.type === 'text')
|
|
106
|
+
return item.text;
|
|
107
|
+
if (item.type === 'image')
|
|
108
|
+
return `[Image: ${item.mimeType}]`;
|
|
109
|
+
if (item.type === 'resource')
|
|
110
|
+
return `[Resource: ${item.uri}]`;
|
|
111
|
+
return JSON.stringify(item);
|
|
112
|
+
})
|
|
113
|
+
.join('\n');
|
|
114
|
+
}
|
|
115
|
+
return typeof result.content === 'string'
|
|
116
|
+
? result.content
|
|
117
|
+
: JSON.stringify(result.content);
|
|
118
|
+
}
|
|
119
|
+
return JSON.stringify(result);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
const errorMsg = `Error calling tool "${toolName}": ${error.message}`;
|
|
123
|
+
onError(errorMsg);
|
|
124
|
+
return errorMsg;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Extract error description from MCP result
|
|
130
|
+
*/
|
|
131
|
+
function getErrorDescription(result) {
|
|
132
|
+
if (result && typeof result === 'object') {
|
|
133
|
+
const r = result;
|
|
134
|
+
if ('content' in r && Array.isArray(r.content)) {
|
|
135
|
+
const textContent = r.content.find((c) => c && typeof c === 'object' && c.type === 'text');
|
|
136
|
+
return textContent?.text;
|
|
137
|
+
}
|
|
138
|
+
if ('message' in r && typeof r.message === 'string') {
|
|
139
|
+
return r.message;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
// Default timeout for MCP operations (30 seconds)
|
|
145
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
146
|
+
class McpToolsProvider {
|
|
147
|
+
description = {
|
|
148
|
+
displayName: 'MCP Tools Provider',
|
|
149
|
+
name: 'mcpToolsProvider',
|
|
150
|
+
icon: 'file:mcp.svg',
|
|
151
|
+
group: ['transform'],
|
|
152
|
+
version: 1,
|
|
153
|
+
subtitle: 'MCP Server Tools',
|
|
154
|
+
description: 'Lädt Tools von einem STDIO MCP Server und stellt sie dem AI Agent zur Verfügung',
|
|
155
|
+
defaults: {
|
|
156
|
+
name: 'MCP Tools',
|
|
157
|
+
},
|
|
158
|
+
inputs: [],
|
|
159
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.AiTool],
|
|
160
|
+
outputNames: ['Tools'],
|
|
161
|
+
credentials: [
|
|
162
|
+
{
|
|
163
|
+
name: 'mcpServerApi',
|
|
164
|
+
required: true,
|
|
165
|
+
testedBy: 'mcpServerConnectionTest',
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
properties: [
|
|
169
|
+
// Tool Selection
|
|
170
|
+
{
|
|
171
|
+
displayName: 'Tools to Include',
|
|
172
|
+
name: 'toolsMode',
|
|
173
|
+
type: 'options',
|
|
174
|
+
default: 'all',
|
|
175
|
+
options: [
|
|
176
|
+
{
|
|
177
|
+
name: 'All',
|
|
178
|
+
value: 'all',
|
|
179
|
+
description: 'Include all tools from the MCP server',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: 'Selected',
|
|
183
|
+
value: 'selected',
|
|
184
|
+
description: 'Only include selected tools',
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: 'All Except',
|
|
188
|
+
value: 'except',
|
|
189
|
+
description: 'Include all tools except selected ones',
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
description: 'Which tools to include from the MCP server',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
displayName: 'Tools',
|
|
196
|
+
name: 'includeTools',
|
|
197
|
+
type: 'multiOptions',
|
|
198
|
+
default: [],
|
|
199
|
+
typeOptions: {
|
|
200
|
+
loadOptionsMethod: 'getTools',
|
|
201
|
+
},
|
|
202
|
+
displayOptions: {
|
|
203
|
+
show: {
|
|
204
|
+
toolsMode: ['selected'],
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
description: 'Select which tools to include. Test your credentials first to populate this list.',
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
displayName: 'Exclude Tools',
|
|
211
|
+
name: 'excludeTools',
|
|
212
|
+
type: 'multiOptions',
|
|
213
|
+
default: [],
|
|
214
|
+
typeOptions: {
|
|
215
|
+
loadOptionsMethod: 'getTools',
|
|
216
|
+
},
|
|
217
|
+
displayOptions: {
|
|
218
|
+
show: {
|
|
219
|
+
toolsMode: ['except'],
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
description: 'Select which tools to exclude. Test your credentials first to populate this list.',
|
|
223
|
+
},
|
|
224
|
+
// Options
|
|
225
|
+
],
|
|
226
|
+
};
|
|
227
|
+
// Methods for loadOptions and credentialTest
|
|
228
|
+
methods = {
|
|
229
|
+
credentialTest: {
|
|
230
|
+
async mcpServerConnectionTest(credential) {
|
|
231
|
+
const data = credential.data;
|
|
232
|
+
if (!data) {
|
|
233
|
+
return {
|
|
234
|
+
status: 'Error',
|
|
235
|
+
message: 'Credential data is missing',
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
const mcpPackage = data.mcpPackage;
|
|
239
|
+
const envVars = data.envVars;
|
|
240
|
+
if (!mcpPackage) {
|
|
241
|
+
return {
|
|
242
|
+
status: 'Error',
|
|
243
|
+
message: 'MCP Package name is required',
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
// Fetch tools and cache them
|
|
248
|
+
const tools = await (0, toolsCache_js_1.fetchAndCacheTools)(mcpPackage, envVars);
|
|
249
|
+
return {
|
|
250
|
+
status: 'OK',
|
|
251
|
+
message: `Connection successful, ${tools.length} tool${tools.length === 1 ? '' : 's'} available`,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
return {
|
|
256
|
+
status: 'Error',
|
|
257
|
+
message: `Connection failed: ${error.message}`,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
loadOptions: {
|
|
263
|
+
async getTools() {
|
|
264
|
+
try {
|
|
265
|
+
const credentials = await this.getCredentials('mcpServerApi');
|
|
266
|
+
const mcpPackage = credentials.mcpPackage;
|
|
267
|
+
const envVars = credentials.envVars;
|
|
268
|
+
if (!mcpPackage) {
|
|
269
|
+
return [
|
|
270
|
+
{
|
|
271
|
+
name: 'Configure credentials first',
|
|
272
|
+
value: '',
|
|
273
|
+
description: 'Enter MCP package name in credentials and test connection',
|
|
274
|
+
},
|
|
275
|
+
];
|
|
276
|
+
}
|
|
277
|
+
// Get tools from cache or fetch
|
|
278
|
+
const tools = await (0, toolsCache_js_1.getTools)(mcpPackage, envVars);
|
|
279
|
+
return tools.map((tool) => ({
|
|
280
|
+
name: tool.name,
|
|
281
|
+
value: tool.name,
|
|
282
|
+
description: tool.description,
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
return [
|
|
287
|
+
{
|
|
288
|
+
name: `Error: ${error.message}`,
|
|
289
|
+
value: '',
|
|
290
|
+
description: 'Test your credentials to load available tools',
|
|
291
|
+
},
|
|
292
|
+
];
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
async supplyData(itemIndex) {
|
|
298
|
+
const node = this.getNode();
|
|
299
|
+
const executionContext = this;
|
|
300
|
+
// Get tool selection parameters
|
|
301
|
+
const toolsMode = this.getNodeParameter('toolsMode', itemIndex, 'all');
|
|
302
|
+
const includeTools = this.getNodeParameter('includeTools', itemIndex, []);
|
|
303
|
+
const excludeTools = this.getNodeParameter('excludeTools', itemIndex, []);
|
|
304
|
+
// Get configuration from credentials
|
|
305
|
+
const credentials = await this.getCredentials('mcpServerApi');
|
|
306
|
+
const mcpPackage = credentials.mcpPackage;
|
|
307
|
+
if (!mcpPackage) {
|
|
308
|
+
throw new n8n_workflow_1.NodeOperationError(node, 'MCP Package name is required in credentials', { itemIndex });
|
|
309
|
+
}
|
|
310
|
+
// Build command: npx -y <package>
|
|
311
|
+
const command = 'npx';
|
|
312
|
+
const args = ['-y', mcpPackage];
|
|
313
|
+
// Parse environment variables from credentials
|
|
314
|
+
const envString = credentials.envVars;
|
|
315
|
+
const env = (0, toolsCache_js_1.parseEnvVars)(envString);
|
|
316
|
+
let transport;
|
|
317
|
+
try {
|
|
318
|
+
transport = new stdio_js_1.StdioClientTransport({
|
|
319
|
+
command,
|
|
320
|
+
args,
|
|
321
|
+
env,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
throw new n8n_workflow_1.NodeOperationError(node, `Failed to create STDIO transport: ${error.message}`, { itemIndex });
|
|
326
|
+
}
|
|
327
|
+
const client = new index_js_1.Client({ name: 'n8n-mcp-tools-provider', version: '1.0.0' }, { capabilities: {} });
|
|
328
|
+
try {
|
|
329
|
+
await Promise.race([
|
|
330
|
+
client.connect(transport),
|
|
331
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error(`Connection timeout after ${DEFAULT_TIMEOUT}ms`)), DEFAULT_TIMEOUT)),
|
|
332
|
+
]);
|
|
333
|
+
const { tools: mcpTools } = await client.listTools();
|
|
334
|
+
if (!mcpTools?.length) {
|
|
335
|
+
throw new n8n_workflow_1.NodeOperationError(node, 'MCP Server returned no tools', { itemIndex });
|
|
336
|
+
}
|
|
337
|
+
// Filter tools based on selection mode
|
|
338
|
+
const filteredMcpTools = (0, toolsCache_js_1.filterTools)(mcpTools, {
|
|
339
|
+
mode: toolsMode,
|
|
340
|
+
includeTools,
|
|
341
|
+
excludeTools,
|
|
342
|
+
});
|
|
343
|
+
if (filteredMcpTools.length === 0) {
|
|
344
|
+
throw new n8n_workflow_1.NodeOperationError(node, 'No tools available after filtering. Check your tool selection settings.', { itemIndex });
|
|
345
|
+
}
|
|
346
|
+
const nodeName = node.name;
|
|
347
|
+
// Create DynamicStructuredTools with MCP call function
|
|
348
|
+
const tools = filteredMcpTools.map((mcpTool) => {
|
|
349
|
+
const toolName = (0, schemaConverter_js_1.sanitizeToolName)(mcpTool.name);
|
|
350
|
+
const toolDescription = mcpTool.description || `MCP Tool: ${mcpTool.name}`;
|
|
351
|
+
const toolSchema = (0, schemaConverter_js_1.createToolSchema)(mcpTool.inputSchema);
|
|
352
|
+
// Create the call function for this tool
|
|
353
|
+
const callTool = createCallTool(mcpTool.name, client, DEFAULT_TIMEOUT, (errorMessage) => {
|
|
354
|
+
try {
|
|
355
|
+
const nodeError = new n8n_workflow_1.NodeOperationError(node, errorMessage, { itemIndex });
|
|
356
|
+
void executionContext.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiTool, itemIndex, nodeError);
|
|
357
|
+
}
|
|
358
|
+
catch {
|
|
359
|
+
// Error output failed - continue anyway
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
// Create the base tool
|
|
363
|
+
const baseTool = new tools_1.DynamicStructuredTool({
|
|
364
|
+
name: toolName,
|
|
365
|
+
description: toolDescription,
|
|
366
|
+
schema: toolSchema,
|
|
367
|
+
metadata: {
|
|
368
|
+
sourceNodeName: nodeName,
|
|
369
|
+
isFromToolkit: true,
|
|
370
|
+
},
|
|
371
|
+
func: callTool,
|
|
372
|
+
});
|
|
373
|
+
// Wrap with logging
|
|
374
|
+
return logWrapperTool(baseTool, executionContext);
|
|
375
|
+
});
|
|
376
|
+
// Return tools array directly - n8n's getConnectedTools handles arrays via flatMap
|
|
377
|
+
// Each tool will go through the else branch and get metadata added
|
|
378
|
+
return {
|
|
379
|
+
response: tools,
|
|
380
|
+
closeFunction: async () => {
|
|
381
|
+
try {
|
|
382
|
+
await client.close();
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
// Client close error - ignore
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
try {
|
|
392
|
+
await client.close();
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
// Cleanup close error - ignore
|
|
396
|
+
}
|
|
397
|
+
if (error instanceof n8n_workflow_1.NodeOperationError) {
|
|
398
|
+
throw error;
|
|
399
|
+
}
|
|
400
|
+
throw new n8n_workflow_1.NodeOperationError(node, `Failed to connect to MCP server: ${error.message}`, {
|
|
401
|
+
itemIndex,
|
|
402
|
+
description: `Package: ${mcpPackage}`,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
async execute() {
|
|
407
|
+
const node = this.getNode();
|
|
408
|
+
const items = this.getInputData();
|
|
409
|
+
const returnData = [];
|
|
410
|
+
// Get tool selection parameters
|
|
411
|
+
const toolsMode = this.getNodeParameter('toolsMode', 0, 'all');
|
|
412
|
+
const includeTools = this.getNodeParameter('includeTools', 0, []);
|
|
413
|
+
const excludeTools = this.getNodeParameter('excludeTools', 0, []);
|
|
414
|
+
// Get configuration from credentials
|
|
415
|
+
const credentials = await this.getCredentials('mcpServerApi');
|
|
416
|
+
const mcpPackage = credentials.mcpPackage;
|
|
417
|
+
if (!mcpPackage) {
|
|
418
|
+
throw new n8n_workflow_1.NodeOperationError(node, 'MCP Package name is required in credentials');
|
|
419
|
+
}
|
|
420
|
+
// Build command: npx -y <package>
|
|
421
|
+
const command = 'npx';
|
|
422
|
+
const args = ['-y', mcpPackage];
|
|
423
|
+
// Parse environment variables from credentials
|
|
424
|
+
const envString = credentials.envVars;
|
|
425
|
+
const env = (0, toolsCache_js_1.parseEnvVars)(envString);
|
|
426
|
+
let transport;
|
|
427
|
+
let client;
|
|
428
|
+
try {
|
|
429
|
+
transport = new stdio_js_1.StdioClientTransport({
|
|
430
|
+
command,
|
|
431
|
+
args,
|
|
432
|
+
env,
|
|
433
|
+
});
|
|
434
|
+
client = new index_js_1.Client({ name: 'n8n-mcp-tools-provider', version: '1.0.0' }, { capabilities: {} });
|
|
435
|
+
await Promise.race([
|
|
436
|
+
client.connect(transport),
|
|
437
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error(`Connection timeout after ${DEFAULT_TIMEOUT}ms`)), DEFAULT_TIMEOUT)),
|
|
438
|
+
]);
|
|
439
|
+
}
|
|
440
|
+
catch (error) {
|
|
441
|
+
throw new n8n_workflow_1.NodeOperationError(node, `MCP Server connection failed: ${error.message}`);
|
|
442
|
+
}
|
|
443
|
+
try {
|
|
444
|
+
const { tools: mcpTools } = await client.listTools();
|
|
445
|
+
if (!mcpTools?.length) {
|
|
446
|
+
throw new n8n_workflow_1.NodeOperationError(node, 'MCP Server returned no tools');
|
|
447
|
+
}
|
|
448
|
+
// Filter tools based on selection mode
|
|
449
|
+
const filteredMcpTools = (0, toolsCache_js_1.filterTools)(mcpTools, {
|
|
450
|
+
mode: toolsMode,
|
|
451
|
+
includeTools,
|
|
452
|
+
excludeTools,
|
|
453
|
+
});
|
|
454
|
+
for (let i = 0; i < items.length; i++) {
|
|
455
|
+
try {
|
|
456
|
+
const item = items[i];
|
|
457
|
+
const input = item.json;
|
|
458
|
+
let toolName;
|
|
459
|
+
let toolArguments = {};
|
|
460
|
+
if (input.tool && typeof input.tool === 'string') {
|
|
461
|
+
toolName = input.tool;
|
|
462
|
+
const { tool: _, ...restArgs } = input;
|
|
463
|
+
toolArguments = restArgs;
|
|
464
|
+
}
|
|
465
|
+
else if (input.tool_name && typeof input.tool_name === 'string') {
|
|
466
|
+
toolName = input.tool_name;
|
|
467
|
+
toolArguments = input.tool_input || {};
|
|
468
|
+
}
|
|
469
|
+
else if (input.name && typeof input.name === 'string') {
|
|
470
|
+
toolName = input.name;
|
|
471
|
+
toolArguments = input.arguments || {};
|
|
472
|
+
}
|
|
473
|
+
if (!toolName) {
|
|
474
|
+
throw new n8n_workflow_1.NodeOperationError(node, 'Tool name not found in input', { itemIndex: i });
|
|
475
|
+
}
|
|
476
|
+
const targetTool = filteredMcpTools.find((t) => t.name === toolName);
|
|
477
|
+
if (!targetTool) {
|
|
478
|
+
throw new n8n_workflow_1.NodeOperationError(node, `Tool "${toolName}" not found or not included in selection`, { itemIndex: i });
|
|
479
|
+
}
|
|
480
|
+
// Filter arguments to only include schema-defined properties
|
|
481
|
+
const inputSchema = targetTool.inputSchema;
|
|
482
|
+
const schemaProperties = inputSchema?.properties || {};
|
|
483
|
+
const allowedKeys = Object.keys(schemaProperties);
|
|
484
|
+
const filteredArguments = {};
|
|
485
|
+
for (const key of allowedKeys) {
|
|
486
|
+
if (key in toolArguments) {
|
|
487
|
+
filteredArguments[key] = toolArguments[key];
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const result = await client.callTool({ name: toolName, arguments: filteredArguments }, types_js_1.CallToolResultSchema, { timeout: DEFAULT_TIMEOUT });
|
|
491
|
+
let outputText;
|
|
492
|
+
if (result.content && Array.isArray(result.content)) {
|
|
493
|
+
outputText = result.content
|
|
494
|
+
.map((contentItem) => {
|
|
495
|
+
if (contentItem.type === 'text')
|
|
496
|
+
return contentItem.text;
|
|
497
|
+
if (contentItem.type === 'image')
|
|
498
|
+
return `[Image: ${contentItem.mimeType}]`;
|
|
499
|
+
if (contentItem.type === 'resource')
|
|
500
|
+
return `[Resource: ${contentItem.uri}]`;
|
|
501
|
+
return JSON.stringify(contentItem);
|
|
502
|
+
})
|
|
503
|
+
.join('\n');
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
outputText = JSON.stringify(result, null, 2);
|
|
507
|
+
}
|
|
508
|
+
returnData.push({
|
|
509
|
+
json: { response: outputText },
|
|
510
|
+
pairedItem: { item: i },
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
catch (error) {
|
|
514
|
+
if (error instanceof n8n_workflow_1.NodeOperationError) {
|
|
515
|
+
throw error;
|
|
516
|
+
}
|
|
517
|
+
returnData.push({
|
|
518
|
+
json: { error: error.message },
|
|
519
|
+
pairedItem: { item: i },
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
finally {
|
|
525
|
+
try {
|
|
526
|
+
await client.close();
|
|
527
|
+
}
|
|
528
|
+
catch {
|
|
529
|
+
// Execute cleanup error - ignore
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return [returnData];
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
exports.McpToolsProvider = McpToolsProvider;
|
|
536
|
+
//# sourceMappingURL=McpToolsProvider.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"McpToolsProvider.node.js","sourceRoot":"","sources":["../../../src/nodes/McpToolsProvider/McpToolsProvider.node.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAiBH,+CAAuE;AAEvE,wEAAmE;AACnE,wEAAiF;AACjF,iEAA6G;AAC7G,iDAA8D;AAE9D,uEAAoF;AACpF,6DAAoG;AAGpG;;;GAGG;AACH,SAAS,cAAc,CACrB,IAA2B,EAC3B,gBAAsC;IAEtC,8DAA8D;IAC9D,MAAM,OAAO,GAAG,IAAW,CAAC;IAE5B,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE;QACrB,GAAG,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;YACpB,uEAAuE;YACvE,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;gBACrB,OAAO,KAAK,EAAE,KAA8B,EAAmB,EAAE;oBAC/D,mBAAmB;oBACnB,MAAM,SAAS,GAAG;wBAChB,KAAK;wBACL,IAAI,EAAE;4BACJ,IAAI,EAAE,MAAM,CAAC,IAAI;4BACjB,WAAW,EAAE,MAAM,CAAC,WAAW;yBAChC;qBACF,CAAC;oBAEF,IAAI,QAA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AAC,CAAC;oBAChB,CAAC;yBAAM,CAAC;wBACN,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;oBAC/C,CAAC;oBAED,UAAU,CAAC,IAAI,CAAC;wBACd,IAAI,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE;wBAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;qBACxB,CAAC,CAAC;gBACL,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,KAAK,YAAY,iCAAkB,EAAE,CAAC;wBACxC,MAAM,KAAK,CAAC;oBACd,CAAC;oBACD,UAAU,CAAC,IAAI,CAAC;wBACd,IAAI,EAAE,EAAE,KAAK,EAAG,KAAe,CAAC,OAAO,EAAE;wBACzC,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;qBACxB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACvB,CAAC;YAAC,MAAM,CAAC;gBACP,iCAAiC;YACnC,CAAC;QACH,CAAC;QAED,OAAO,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;CACF;AA3cD,4CA2cC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
2
|
+
<circle cx="12" cy="12" r="10"/>
|
|
3
|
+
<path d="M12 6v6l4 2"/>
|
|
4
|
+
<path d="M8 12h.01"/>
|
|
5
|
+
<path d="M16 12h.01"/>
|
|
6
|
+
<path d="M12 16h.01"/>
|
|
7
|
+
</svg>
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for n8n-nodes-mcp-tools
|
|
3
|
+
*
|
|
4
|
+
* Exports common types for better IDE support and type safety.
|
|
5
|
+
*/
|
|
6
|
+
import type { JsonSchema } from './utils/schemaConverter.js';
|
|
7
|
+
/**
|
|
8
|
+
* MCP Tool definition as returned by the MCP server
|
|
9
|
+
*/
|
|
10
|
+
export interface McpToolDefinition {
|
|
11
|
+
/** Unique tool name */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Human-readable description of what the tool does */
|
|
14
|
+
description?: string;
|
|
15
|
+
/** JSON Schema defining the tool's input parameters */
|
|
16
|
+
inputSchema?: JsonSchema;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for connecting to an MCP server
|
|
20
|
+
*/
|
|
21
|
+
export interface McpConfig {
|
|
22
|
+
/** npm package name of the MCP server (e.g., '@anthropic/mcp-server-memory') */
|
|
23
|
+
mcpPackage: string;
|
|
24
|
+
/** Command to execute (default: 'npx') */
|
|
25
|
+
command: string;
|
|
26
|
+
/** Arguments for the command */
|
|
27
|
+
args: string[];
|
|
28
|
+
/** Environment variables to pass to the MCP server process */
|
|
29
|
+
env: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Tool selection mode for filtering which tools to include
|
|
33
|
+
*/
|
|
34
|
+
export type ToolsMode = 'all' | 'selected' | 'except';
|
|
35
|
+
/**
|
|
36
|
+
* Options for filtering tools
|
|
37
|
+
*/
|
|
38
|
+
export interface ToolFilterOptions {
|
|
39
|
+
/** Tool selection mode */
|
|
40
|
+
mode: ToolsMode | string;
|
|
41
|
+
/** Tools to include (when mode is 'selected') */
|
|
42
|
+
includeTools: string[];
|
|
43
|
+
/** Tools to exclude (when mode is 'except') */
|
|
44
|
+
excludeTools: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Result from an MCP tool call
|
|
48
|
+
*/
|
|
49
|
+
export interface McpToolResult {
|
|
50
|
+
/** Whether the tool call resulted in an error */
|
|
51
|
+
isError?: boolean;
|
|
52
|
+
/** Tool result content (legacy format) */
|
|
53
|
+
toolResult?: unknown;
|
|
54
|
+
/** Tool result content (new format) */
|
|
55
|
+
content?: McpContentItem[] | unknown;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Content item in MCP tool result
|
|
59
|
+
*/
|
|
60
|
+
export interface McpContentItem {
|
|
61
|
+
/** Content type */
|
|
62
|
+
type: 'text' | 'image' | 'resource';
|
|
63
|
+
/** Text content (when type is 'text') */
|
|
64
|
+
text?: string;
|
|
65
|
+
/** MIME type (when type is 'image') */
|
|
66
|
+
mimeType?: string;
|
|
67
|
+
/** Resource URI (when type is 'resource') */
|
|
68
|
+
uri?: string;
|
|
69
|
+
}
|
|
70
|
+
export type { JsonSchema };
|
|
71
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uDAAuD;IACvD,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,8DAA8D;IAC9D,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,0BAA0B;IAC1B,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;IACzB,iDAAiD;IACjD,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,+CAA+C;IAC/C,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uCAAuC;IACvC,OAAO,CAAC,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,mBAAmB;IACnB,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;IACpC,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAGD,YAAY,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|