Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

A restarted MCP server keeps its apps, and the restart test waits for the key card's own turn

milind-soni6d25919204b7
diff --git a/server/host/mcp-servers-host.test.ts b/server/host/mcp-servers-host.test.ts
index 53e9004d55..948e160e90 100644
--- a/server/host/mcp-servers-host.test.ts
+++ b/server/host/mcp-servers-host.test.ts
@@ -4,6 +4,7 @@ import { join } from "node:path";
import { afterEach, expect, it } from "vitest";
import type { AppConfig } from "../config.ts";
+import { mcpServerConfigHash } from "../mcp-app-catalog.ts";
import { claimedNotice, createMcpServersHost } from "./mcp-servers-host.ts";
const dirs: string[] = [];
@@ -128,6 +129,7 @@ it("a restart, or turning a server off and on, shows in what the next turn start
host.health.changed("notes");
const restarted = JSON.stringify(host.mounted(PAUL).notes);
expect(restarted).not.toBe(fresh);
+ expect(mcpServerConfigHash(JSON.parse(restarted)), "still the server the apps catalog learned").toBe(mcpServerConfigHash(JSON.parse(fresh)));
const entry = cfg.mcpServers!.notes as { enabled: boolean };
entry.enabled = false;
diff --git a/server/host/mcp-servers-host.ts b/server/host/mcp-servers-host.ts
index cd81ef3024..5e6ecba543 100644
--- a/server/host/mcp-servers-host.ts
+++ b/server/host/mcp-servers-host.ts
@@ -7,6 +7,7 @@ import type { AppConfig } from "../config.ts";
import { customMcpServers } from "../config.ts";
import type { McpServerSpec, StdioMcpSpec } from "../contracts.ts";
import { addBotMcpServer, claimBotMcpServers, keepForBot, withoutBotMcpServers, type BotKept, type BotMcpServerAdd } from "../mcp-bot-servers.ts";
+import { MCP_RESTART_ENV } from "../mcp-app-catalog.ts";
import { createMcpHealth, nameList, toolLabel, type McpHealthDeps } from "../mcp-health.ts";
import { probeMcpServer } from "../mcp-probe.ts";
import { isRemoteMcpServer, parseStoredMcpServer, type StoredStdioMcpServer } from "../mcp-registry.ts";
@@ -57,7 +58,7 @@ export function enabledCommandServers(cfg: AppConfig): Record<string, StdioMcpSp
function withRestarts(servers: Record<string, McpServerSpec>, restarts: ReadonlyMap<string, number>): Record<string, McpServerSpec> {
return Object.fromEntries(Object.entries(servers).map(([name, server]) => {
const count = restarts.get(name);
- return [name, count && "command" in server ? { ...server, env: { ...server.env, OMB_MCP_RESTART: String(count) } } : server];
+ return [name, count && "command" in server ? { ...server, env: { ...server.env, [MCP_RESTART_ENV]: String(count) } } : server];
}));
}
diff --git a/server/mcp-app-catalog.ts b/server/mcp-app-catalog.ts
index 3281218b30..d679a0d066 100644
--- a/server/mcp-app-catalog.ts
+++ b/server/mcp-app-catalog.ts
@@ -37,12 +37,17 @@ function isRecord(value: unknown): value is Json {
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
}
-/** Headers are left out, so a refreshed sign-in token is the same server; hashed, so no credential is stored. */
+/** How many times a command server was restarted, in the spec a turn mounts (host/mcp-servers-host.ts). */
+export const MCP_RESTART_ENV = "OMB_MCP_RESTART";
+
+/** Headers are left out, so a refreshed sign-in token is the same server, and so is the restart count, so a restarted
+ * server keeps its apps; hashed, so no credential is stored. */
export function mcpServerConfigHash(server: McpServerSpec | Json): string {
const record = server as Json;
+ const { [MCP_RESTART_ENV]: _restarts, ...env } = isRecord(record.env) ? record.env : {};
const identity = typeof record.url === "string"
? { type: record.type === "sse" ? "sse" : "http", url: record.url }
- : { command: record.command, args: Array.isArray(record.args) ? record.args : [], env: isRecord(record.env) ? record.env : {} };
+ : { command: record.command, args: Array.isArray(record.args) ? record.args : [], env };
return createHash("sha256").update(JSON.stringify(identity)).digest("hex");
}
diff --git a/server/mcp-restart.e2e.test.ts b/server/mcp-restart.e2e.test.ts
index 2aab8bf89b..b65625c6b9 100644
--- a/server/mcp-restart.e2e.test.ts
+++ b/server/mcp-restart.e2e.test.ts
@@ -59,6 +59,10 @@ it("restart keeps the key and replaces the warm process, and so does turning the
expect(added.status, JSON.stringify(added.body)).toBe(201);
expect(added.body.text).toContain("Test: it started and listed its tools");
await setup.done();
+ // Saving the key answered the card the setup turn asked with, so that turn goes on once more. It runs now, while nothing
+ // else is sent: later it would take the thread or the warm process from a turn this test checks.
+ await expect.poll(() => { try { return JSON.stringify(dump().prompt).includes("OpenMausBot secret update"); } catch { return false; } }, { timeout: 30_000 }).toBe(true);
+ await setup.done();
const launched = await turn();
await launched.done();