Skip to content

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

Count a bot's own new MCP server under that bot for the per-bot limit

AdityaUmaleb57c6c098ebe
diff --git a/server/mcp-bot-servers.test.ts b/server/mcp-bot-servers.test.ts
index 92be2884ae..1e6ed3bf6f 100644
--- a/server/mcp-bot-servers.test.ts
+++ b/server/mcp-bot-servers.test.ts
@@ -147,6 +147,30 @@ describe("a bot adding a server where bots are boxed", () => {
});
});
+describe("a bot adding its own server when another bot already has 20 of its own", () => {
+ const paulsOwn = Object.fromEntries(Array.from({ length: 20 }, (_, i) => [`paul${i}`, { command: "npx", args: [`p${i}`], env: {}, enabled: false, bot: "paul" }]));
+
+ it("counts a server in this bot's own folder as its own, so it fits", () => {
+ const data = dataDir();
+ const script = file(join(data, "workspaces", "iris", "srv", "server.py"));
+ const added = addBotMcpServer(paulsOwn, { name: "linear", ...python(script) }, "iris", data, true);
+ if (!added.ok) throw new Error(added.error);
+ expect(added.server).toMatchObject({ bot: "iris", enabled: false });
+ });
+
+ it("still refuses one every bot would use, and never takes the owner from the request", () => {
+ const data = dataDir();
+ const notes = { name: "notes", command: "npx", args: ["-y", "@x/notes-mcp"] };
+ expect(addBotMcpServer(paulsOwn, notes, "iris", data, true))
+ .toMatchObject({ ok: false, status: 400, error: expect.stringMatching(/at most 20 MCP servers/) });
+ expect(addBotMcpServer(paulsOwn, { ...notes, bot: "iris" }, "iris", data, true))
+ .toMatchObject({ ok: false, status: 400, error: expect.stringMatching(/at most 20 MCP servers/) });
+ const script = file(join(data, "workspaces", "iris", "srv", "server.py"));
+ expect(addBotMcpServer(paulsOwn, { name: "linear", ...python(script) }, "iris", data, false))
+ .toMatchObject({ ok: false, status: 400, error: expect.stringMatching(/at most 20 MCP servers/) });
+ });
+});
+
describe("a bot adding a server that names the server's own files, where bots are boxed", () => {
it("is refused for settings, sessions, the chats and the data folder itself, however the path is written", () => {
const data = dataDir();
diff --git a/server/mcp-bot-servers.ts b/server/mcp-bot-servers.ts
index bae0c301a4..abdacdc683 100644
--- a/server/mcp-bot-servers.ts
+++ b/server/mcp-bot-servers.ts
@@ -7,7 +7,7 @@ import { basename, delimiter, isAbsolute, join, relative, resolve, sep } from "n
import type { StdioMcpSpec } from "./contracts.ts";
import { engineInstallRoots } from "./engine-roots.ts";
-import { addDisabledMcpServer, isRemoteMcpServer, parseStoredMcpServer, type DisabledMcpServerAdd, type StoredStdioMcpServer } from "./mcp-registry.ts";
+import { addDisabledMcpServer, isRemoteMcpServer, parseStoredMcpServer, type DisabledMcpServerAdd, type StoredMcpServer, type StoredStdioMcpServer } from "./mcp-registry.ts";
const ID = /^[A-Za-z0-9_-]{1,128}$/;
/** What one server's files copied out of a conversation folder may add up to. */
@@ -161,9 +161,16 @@ export function keepForBot(server: StoredStdioMcpServer, botId: string, dataDir:
return { ok: true, server: boxed ? { ...kept.server, bot: botId } : kept.server, moved: kept.moved };
}
+/** The bot keepForBot will make this server's own: boxed, one whose files are in only this bot's folders. */
+function ownerFor(server: StoredMcpServer, botId: string, dataDir: string, boxed: boolean): string | undefined {
+ if (!boxed || isRemoteMcpServer(server)) return undefined;
+ const use = botFolderUse(server, dataDir);
+ return use && use !== "several" && use.botId === botId ? botId : undefined;
+}
+
/** A bot's mcp_server add: saved off first, its files kept as keepForBot says. */
export function addBotMcpServer(current: Record<string, unknown>, body: unknown, botId: string, dataDir: string, boxed: boolean): BotMcpServerAdd {
- const added = addDisabledMcpServer(current, body);
+ const added = addDisabledMcpServer(current, body, (server) => ownerFor(server, botId, dataDir, boxed));
if (!added.ok || isRemoteMcpServer(added.server)) return added;
const kept = keepForBot(added.server, botId, dataDir, boxed);
if (!kept.ok) return kept;
diff --git a/server/mcp-registry.ts b/server/mcp-registry.ts
index edcf8fd288..b2596df8c2 100644
--- a/server/mcp-registry.ts
+++ b/server/mcp-registry.ts
@@ -422,8 +422,13 @@ export type DisabledMcpServerAdd =
const BOT_CANNOT_SWITCH = "A bot cannot change the on/off switch. The server is saved off, and only the user can turn it on in MCP server settings.";
-/** Never probes or launches; the caller still applies organisation policy before writing. */
-export function addDisabledMcpServer(current: Record<string, unknown>, body: unknown): DisabledMcpServerAdd {
+/** Never probes or launches; the caller still applies organisation policy before writing. `ownerOf` names the bot the
+ * server will belong to (worked out by the caller, never taken from the body), so the per-bot limit counts it there. */
+export function addDisabledMcpServer(
+ current: Record<string, unknown>,
+ body: unknown,
+ ownerOf?: (server: StoredMcpServer) => string | undefined,
+): DisabledMcpServerAdd {
if (!body || typeof body !== "object" || Array.isArray(body)) {
return { ok: false, status: 400, error: "Expected an MCP server object with a name." };
}
@@ -435,7 +440,8 @@ export function addDisabledMcpServer(current: Record<string, unknown>, body: unk
}
const parsed = parseMcpServerMutation(name, pickMcpServerFields(record));
if (!parsed.ok) return { ok: false, status: 400, error: parsed.error };
- const limit = mcpServerLimitError(current, [parsed.server]);
+ const owner = ownerOf?.(parsed.server);
+ const limit = mcpServerLimitError(current, [owner ? { ...parsed.server, bot: owner } : parsed.server]);
if (limit) return { ok: false, status: 400, error: limit };
if (parsed.server.enabled !== false) return { ok: false, status: 400, error: BOT_CANNOT_SWITCH };
return { ok: true, name, server: parsed.server, next: { ...current, [name]: parsed.server } };