mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-03-16 23:43:07 +00:00
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:
@@ -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
|
// Track this transport for cleanup
|
||||||
this.transports.add(transport);
|
this.transports.add(transport);
|
||||||
|
|
||||||
const connection = await this.server.connect(transport);
|
const connection = await this.server.connect(transport);
|
||||||
this.connections.add(connection);
|
this.connections.add(connection);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user