Disallow multiple plugin instances being connected in parallel

This commit is contained in:
Dominik Jain 2025-10-16 19:20:17 +02:00
parent e3a9771f9c
commit 670b0d6b07

View File

@ -102,12 +102,18 @@ export class PluginBridge {
public async executePluginTask<TResult extends PluginTaskResult<any>>(
task: PluginTask<any, TResult>
): Promise<TResult> {
// Check if there are connected clients
// Check for a single connected client
if (this.connectedClients.size === 0) {
throw new Error(
`No Penpot plugin instances are currently connected. Please ensure the plugin is running and connected.`
);
}
if (this.connectedClients.size > 1) {
throw new Error(
`Multiple (${this.connectedClients.size}) Penpot MCP Plugin instances are connected. ` +
`Ask the user to ensure that only one instance is connected at a time.`
);
}
// Register the task for result correlation
this.pendingTasks.set(task.id, task);
@ -147,7 +153,7 @@ export class PluginBridge {
}, this.taskTimeoutSecs * 1000);
this.taskTimeouts.set(task.id, timeoutHandle);
this.logger.info(`Sent task ${task.id} to ${sentCount} connected clients`);
this.logger.info(`Sent task ${task.id} to ${sentCount} connected client`);
return await task.getResultPromise();
}