penpot/mcp/packages/plugin/src/ReconnectPolicy.ts
Andrey Antukh dad6026132
🐛 Test and document MCP plugin terminal-close handling (#11906)
Extract the WebSocket close-code decision into a pure ReconnectPolicy
module and cover it with node:test. The plugin now names the 1008
policy-violation code instead of using a magic number, and the terminal
behavior of a 1008 close is pinned by a regression test so a future
refactor cannot reintroduce the reconnect storm.

Document the contract in mem:mcp/core: 1008 is terminal, it comes from a
duplicate user token or a missing token in multi-user mode, and recovery
is manual via "Connect here".

Closes #11510

AI-assisted-by: deepseek-v4.1-flash
2026-09-24 15:57:23 +02:00

19 lines
691 B
TypeScript

/**
* WebSocket close code the MCP server uses for policy violations.
*
* The server rejects a second plugin connection for the same user token, and
* connections missing a token in multi-user mode, with this code.
*/
export const WS_CLOSE_POLICY_VIOLATION = 1008;
/**
* Returns whether a WebSocket close should trigger an automatic reconnect.
*
* Policy violations are terminal: the server refuses the connection again
* immediately, so retrying only repeats the rejection. Other closes (for
* example a dropped or restarted server) are retried with backoff.
*/
export function shouldReconnectAfterClose(code: number): boolean {
return code !== WS_CLOSE_POLICY_VIOLATION;
}