feat: make MCP server registrations persistent across peer disconnects
Some checks failed
CI / Lint (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Broker tests (Postgres) (push) Has been cancelled
CI / Docker build (linux/amd64) (push) Has been cancelled

Persistent MCP servers (opt-in via `persistent: true`) survive host
disconnects — they appear as offline in mcp_list and auto-restore when
the host reconnects. Ephemeral servers (default) still clean up on
disconnect. Offline servers return a clear error on mcp_call with
time-since-disconnect info.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-04-08 00:22:06 +01:00
parent 56b1cc0756
commit 5398ca6833
5 changed files with 82 additions and 9 deletions

View File

@@ -931,6 +931,7 @@ export class BrokerClient {
serverName: string,
description: string,
tools: Array<{ name: string; description: string; inputSchema: Record<string, unknown> }>,
persistent?: boolean,
): Promise<{ serverName: string; toolCount: number } | null> {
if (!this.ws || this.ws.readyState !== this.ws.OPEN) return null;
return new Promise((resolve) => {
@@ -938,7 +939,7 @@ export class BrokerClient {
this.mcpRegisterResolvers.set(reqId, { resolve, timer: setTimeout(() => {
if (this.mcpRegisterResolvers.delete(reqId)) resolve(null);
}, 5_000) });
this.ws!.send(JSON.stringify({ type: "mcp_register", serverName, description, tools, _reqId: reqId }));
this.ws!.send(JSON.stringify({ type: "mcp_register", serverName, description, tools, ...(persistent ? { persistent: true } : {}), _reqId: reqId }));
});
}