From 71170d3f765555249450a066af3d8fea74f590ee Mon Sep 17 00:00:00 2001 From: czlonkowski Date: Sat, 14 Mar 2026 13:49:23 +0100 Subject: [PATCH] fix(tests): close existing connection before reconnecting in MCP protocol tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MCP SDK 1.27+ enforces single-connection per Server instance, throwing "Already connected to a transport" when connect() is called twice. Updated test helper to close existing connections before reconnecting. Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en Co-Authored-By: Claude Opus 4.6 (1M context) --- tests/integration/mcp-protocol/test-helpers.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/integration/mcp-protocol/test-helpers.ts b/tests/integration/mcp-protocol/test-helpers.ts index 6648b86..10c1dfe 100644 --- a/tests/integration/mcp-protocol/test-helpers.ts +++ b/tests/integration/mcp-protocol/test-helpers.ts @@ -134,9 +134,22 @@ export class TestableN8NMCPServer { } } + // MCP SDK 1.27+ enforces single-connection per Server instance. + // Close existing connections before connecting a new transport. + for (const conn of this.connections) { + try { + if (conn && typeof conn.close === 'function') { + await conn.close(); + } + } catch { + // Ignore errors during cleanup + } + } + this.connections.clear(); + // Track this transport for cleanup this.transports.add(transport); - + const connection = await this.server.connect(transport); this.connections.add(connection); }