feat(MCP Client Tool Node): Add MCP Client Tool Node to connect to MCP servers over SSE (#14464)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
Co-authored-by: JP van Oosten <jp@n8n.io>
This commit is contained in:
Elias Meire
2025-04-09 17:31:53 +02:00
committed by GitHub
parent b52f9f0f6c
commit 34252f53f9
24 changed files with 926 additions and 35 deletions

View File

@@ -1,4 +1,5 @@
import { DynamicTool, type Tool } from '@langchain/core/tools';
import { Toolkit } from 'langchain/agents';
import { createMockExecuteFunction } from 'n8n-nodes-base/test/nodes/Helpers';
import { NodeOperationError } from 'n8n-workflow';
import type { ISupplyDataFunctions, IExecuteFunctions, INode } from 'n8n-workflow';
@@ -242,6 +243,34 @@ describe('getConnectedTools', () => {
const tools = await getConnectedTools(mockExecuteFunctions, true, false);
expect(tools[0]).toBe(mockN8nTool);
});
it('should flatten tools from a toolkit', async () => {
class MockToolkit extends Toolkit {
tools: Tool[];
constructor(tools: unknown[]) {
super();
this.tools = tools as Tool[];
}
}
const mockTools = [
{ name: 'tool1', description: 'desc1' },
new MockToolkit([
{ name: 'toolkitTool1', description: 'toolkitToolDesc1' },
{ name: 'toolkitTool2', description: 'toolkitToolDesc2' },
]),
];
mockExecuteFunctions.getInputConnectionData = jest.fn().mockResolvedValue(mockTools);
const tools = await getConnectedTools(mockExecuteFunctions, false);
expect(tools).toEqual([
{ name: 'tool1', description: 'desc1' },
{ name: 'toolkitTool1', description: 'toolkitToolDesc1' },
{ name: 'toolkitTool2', description: 'toolkitToolDesc2' },
]);
});
});
describe('unwrapNestedOutput', () => {