fix(tests): close existing connection before reconnecting in MCP protocol tests

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) <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2026-03-14 13:49:23 +01:00
parent fb0a501f1c
commit 71170d3f76

View File

@@ -134,6 +134,19 @@ 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);