Skip to content

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

Team setup: let a Chief propose a bot's MCP servers, confirmed on the owner's card

Brunof4bcc780f15a
diff --git a/packages/phone-protocol/src/team-setup.ts b/packages/phone-protocol/src/team-setup.ts
index c4a01a30f0..7f3460a3f9 100644
--- a/packages/phone-protocol/src/team-setup.ts
+++ b/packages/phone-protocol/src/team-setup.ts
@@ -10,6 +10,8 @@ export interface TeamSetupFields {
section?: string;
modelSelection?: ModelSelection;
chiefOfStaff?: boolean;
+ /** Update only: the bot's MCP servers by name. Always confirmed by the owner on a card, never applied on its own. */
+ mcpServers?: string[];
}
export interface TeamSetupOperation {
@@ -27,7 +29,7 @@ export interface TeamSetupResult {
error?: string;
}
-/** The complete, reviewed operation. It never accepts executable permissions. */
+/** The complete, reviewed operation. It never accepts executable permissions; an MCP server list waits for the owner's card. */
export interface TeamSetupRequest {
version: 1;
requestId: string;
diff --git a/server/drivers/agents-catalog-goldens/full.tools-list.json b/server/drivers/agents-catalog-goldens/full.tools-list.json
index 98b146d7fd..5b0397e2e2 100644
--- a/server/drivers/agents-catalog-goldens/full.tools-list.json
+++ b/server/drivers/agents-catalog-goldens/full.tools-list.json
@@ -741,7 +741,7 @@
},
{
"name": "propose_team_setup",
- "description": "Chief of Staff only: create specialists and change bots' profiles, models, Chiefs and teams as the person asked, all in ONE plan, with exact ids from list_team_setup. One operation per bot, at most 40 (8 new). A new team goes in newTeams with a specialist in this plan; teams you are not authorized for cannot be included. Models change defaults for new threads; execution permissions never change. It applies at once, with an Undo where possible: read the result before saying it did. It never raises another bot's execution permissions.",
+ "description": "Chief of Staff only: create specialists and change bots' profiles, models, Chiefs and teams as the person asked, all in ONE plan, with exact ids from list_team_setup. One operation per bot, at most 40 (8 new). A new team goes in newTeams with a specialist in this plan; teams you are not authorized for cannot be included. Models change defaults for new threads; an MCP server list always waits for the person; other execution permissions never change. It applies at once, with an Undo where possible: read the result before saying it did. It never raises another bot's execution permissions.",
"inputSchema": {
"type": "object",
"additionalProperties": false,
@@ -833,6 +833,14 @@
"instanceId",
"model"
]
+ },
+ "mcpServers": {
+ "type": "array",
+ "maxItems": 20,
+ "items": {
+ "type": "string"
+ },
+ "description": "update: the bot's full MCP server list by name."
}
}
}
diff --git a/server/drivers/agents-catalog.ts b/server/drivers/agents-catalog.ts
index 9bfb205b9b..2b877eb517 100644
--- a/server/drivers/agents-catalog.ts
+++ b/server/drivers/agents-catalog.ts
@@ -373,7 +373,7 @@ const TOOL_DEFINITIONS = [
},
{
name: "propose_team_setup",
- description: "Chief of Staff only: create specialists and change bots' profiles, models, Chiefs and teams as the person asked, all in ONE plan, with exact ids from list_team_setup. One operation per bot, at most 40 (8 new). A new team goes in newTeams with a specialist in this plan; teams you are not authorized for cannot be included. Models change defaults for new threads; execution permissions never change." + APPLIES_OUTCOME,
+ description: "Chief of Staff only: create specialists and change bots' profiles, models, Chiefs and teams as the person asked, all in ONE plan, with exact ids from list_team_setup. One operation per bot, at most 40 (8 new). A new team goes in newTeams with a specialist in this plan; teams you are not authorized for cannot be included. Models change defaults for new threads; an MCP server list always waits for the person; other execution permissions never change." + APPLIES_OUTCOME,
inputSchema: {
type: "object", additionalProperties: false,
properties: {
@@ -395,6 +395,7 @@ const TOOL_DEFINITIONS = [
modelSelection: { type: "object", additionalProperties: false, properties: {
instanceId: { type: "string" }, model: { type: "string" }, effort: { type: "string" }, variant: { type: "string" },
}, required: ["instanceId", "model"] },
+ mcpServers: { type: "array", maxItems: 20, items: { type: "string" }, description: "update: the bot's full MCP server list by name." },
} },
}, required: ["action", "fields"],
} },
diff --git a/server/index.ts b/server/index.ts
index f6b4a3b2e4..2d8bb30b96 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -216,6 +216,7 @@ import { decodeGeneratedImage } from "./generated-image.ts";
import { createMcpServersHost } from "./host/mcp-servers-host.ts"; import { createMcpKeys } from "./vault/mcp-keys.ts"; import { createLimitTakeover, signedOutStop } from "./host/limit-takeover.ts";
import {
isRemoteMcpServer,
+ mcpServerServes,
parseStoredMcpServer,
} from "./mcp-registry.ts";
import { attachCustomMcp } from "./mcp-result-budget.ts"; import { mcpToolProblem } from "./mcp-failure.ts";
@@ -9194,6 +9195,11 @@ const teamSetupRequests = new TeamSetupRequestService({
store, teams: teamSetupTeams, hasTeamAuthority, canPersist: proposalPersistence, maxBots: MAX_WORKSPACE_BOTS,
autoApply: appliesDirectly,
validateChange: (before, fields) => assertTeamComputerChangeIdle(before, { ...before, ...fields }),
+ mcpServerProblem: (name, botId) => {
+ const server = cfg.mcpServers?.[name];
+ if (!server) return "no such server";
+ return mcpServerServes(server, botId) ? null : "that server belongs to another bot";
+ },
ownsThread: (botId, threadId) => Boolean(connectorThread(botId, threadId)),
targetBusy: (botId, sourceThreadId) => {
if (!sourceThreadId) return Boolean(store.bot(botId)?.busy || hasDirectDispatch(botId) || activeGroupTurnForBot(botId) || routines?.activeRunForBot(botId));
diff --git a/server/team-setup-requests.test.ts b/server/team-setup-requests.test.ts
index 51fa3f42e7..d6e0d5fee9 100644
--- a/server/team-setup-requests.test.ts
+++ b/server/team-setup-requests.test.ts
@@ -54,6 +54,11 @@ function harness(caps?: Record<string, { driverKind: string; agentsMcp: boolean
const canPersist = vi.fn((): { ok: true } | { ok: false; status: number; error: string } => ({ ok: true }));
const service = new TeamSetupRequestService({ store, teams: () => teams, maxBots: 100, hasTeamAuthority,
canPersist, ownsThread: () => sourceExists, targetBusy, deleteBot, deletionRefusal, autoApply, validateChange,
+ mcpServerProblem: (name, botId) => {
+ const servers: Record<string, { bot?: string }> = { hindsight: {}, linear: {}, "clive-notes": { bot: "Clive" } };
+ if (!servers[name]) return "no such server";
+ return !servers[name].bot || servers[name].bot === botId ? null : "that server belongs to another bot";
+ },
validateModel: (selection, current) => {
if (!({ claude: ["sonnet", "opus"], codex: ["gpt-fixture"] }[selection.instanceId]?.includes(selection.model))) return "Model is not in the current catalog";
return current?.approvalMode === "full" && selection.instanceId !== current.modelSelection.instanceId ? "Existing permissions are incompatible" : null;
@@ -210,7 +215,7 @@ describe("reviewed Chief team setup", () => {
it("names where an unknown key is and what that level takes", () => {
const h = harness();
expect(() => h.propose([{ action: "update", botId: h.peer.id, fields: { model: "gpt" } }]))
- .toThrow(/^operations\.0\.fields: Unrecognized key: "model"\. It takes chiefOfStaff, name, title, description, soul, soulAppend, cwd, section, modelSelection\.$/);
+ .toThrow(/^operations\.0\.fields: Unrecognized key: "model"\. It takes chiefOfStaff, name, title, description, soul, soulAppend, cwd, section, modelSelection, mcpServers\.$/);
expect(() => h.service.propose({ botId: h.chief.id, threadId: h.chief.threadId, plan: { reason: "Requested", operations: [{ action: "update", botId: h.peer.id, fields: { title: "Lead" } }], teams: [] } }))
.toThrow(/^Unrecognized key: "teams"\. It takes reason, newTeams, operations\.$/);
});
@@ -595,6 +600,41 @@ describe("team setup that applies on its own", () => {
});
});
+describe("a bot's MCP servers in team setup", () => {
+ it("waits on the owner's card even under Full Access, then applies the list they confirmed", async () => {
+ const h = harness(); h.autoApply.mockReturnValue("full-access");
+ const response = await h.submit([{ action: "update", botId: h.peer.id, fields: { mcpServers: ["linear", "hindsight", "linear"] } }]);
+ expect(response).toMatchObject({ applied: false, state: "pending" });
+ expect(response.detail).toContain("MCP servers it can use: every enabled server → linear, hindsight");
+ expect(response.detail).toContain("Other execution permissions are unchanged.");
+ expect(h.apply).not.toHaveBeenCalled();
+ expect(h.peer.mcpServers).toBeUndefined();
+ expect(h.messages[0].card?.options).toEqual(["Apply setup", "Cancel"]);
+ expect(await h.resolve(response.requestId)).toMatchObject({ result: { state: "applied" } });
+ expect(h.peer.mcpServers).toEqual(["linear", "hindsight"]);
+ });
+ it("keeps a plan without MCP servers applying on its own", async () => {
+ const h = harness(); h.autoApply.mockReturnValue("full-access");
+ expect(await h.submit([{ action: "update", botId: h.peer.id, fields: { title: "Researcher" } }])).toMatchObject({ applied: true });
+ });
+ it("cancels when the bot's list changed after the card was shown", async () => {
+ const h = harness();
+ const card = h.propose([{ action: "update", botId: h.peer.id, fields: { mcpServers: ["hindsight"] } }]);
+ h.peer.mcpServers = ["linear"];
+ expect((await h.resolve(card.requestId))?.result.state).toBe("cancelled");
+ expect(h.peer.mcpServers).toEqual(["linear"]);
+ });
+ it("refuses a new bot, an unknown server, another bot's own server, and a busy bot", () => {
+ const h = harness();
+ expect(() => h.propose([{ ...specialist("Mira", "Work"), fields: { ...specialist("Mira", "Work").fields, mcpServers: ["hindsight"] } }])).toThrow(/existing bot/);
+ expect(() => h.propose([{ action: "update", botId: h.peer.id, fields: { mcpServers: ["nope"] } }])).toThrow(/no such server/);
+ expect(() => h.propose([{ action: "update", botId: h.peer.id, fields: { mcpServers: ["clive-notes"] } }])).toThrow(/another bot/);
+ h.peer.busy = true;
+ expect(() => h.propose([{ action: "update", botId: h.peer.id, fields: { mcpServers: ["hindsight"] } }])).toThrow(/Stop @Ada/);
+ expect(h.messages).toHaveLength(0);
+ });
+});
+
describe("team setup below Full access", () => {
const undo = (h: ReturnType<typeof harness>, requestId: string) => h.service.undo({ botId: h.chief.id, threadId: h.chief.threadId, requestId });
diff --git a/server/team-setup-requests.ts b/server/team-setup-requests.ts
index 4c13d8120e..b6230f3c9f 100644
--- a/server/team-setup-requests.ts
+++ b/server/team-setup-requests.ts
@@ -9,6 +9,7 @@ import { recordProfileChange, type HistoryActor } from "./profile-versions.ts";
import { validateBotCwd } from "./bot-cwd.ts";
import { UNDO_STALE, type DirectApply } from "./direct-apply.ts";
import { harnessCapabilityLines, type DriverCapabilities } from "./harness-capabilities.ts";
+import { MAX_MCP_SERVERS, mcpServerNameError } from "./mcp-registry.ts";
import { redactSecretsInText } from "./redact.ts"; import { chiefLevel } from "./chief-level.ts"; import { defaultBotRefusal } from "./default-bot.ts";
import type { BotRecord, OptionCardData } from "./store.ts"; import { outsideDepartmentReason } from "./peer-roster.ts";
import type { TeamSetupFields, TeamSetupOperation, TeamSetupRequest, TeamSetupResult, TeamSetupUndo } from "../shared/team-setup.ts";
@@ -28,7 +29,10 @@ const fieldsSchema = z.object({
cwd: z.string().optional(),
section: z.string().trim().max(60).refine(fitsOnOneLine).refine((value) => redactSecretsInText(value) === value, "Team names cannot contain credentials").optional(),
modelSelection: z.object({ instanceId: z.string().trim().min(1), model: z.string().trim().min(1), effort: z.string().optional(), variant: z.string().optional() }).strict().optional(),
+ mcpServers: z.array(z.string()).max(MAX_MCP_SERVERS, `Select at most ${MAX_MCP_SERVERS} MCP servers.`).optional(),
}).strict();
+/** A Chief may never apply a bot's MCP servers on its own: the owner confirms them on a card. */
+const touchesMcp = (request: TeamSetupRequest) => request.operations.some((operation) => operation.fields.mcpServers !== undefined);
const planSchema = z.object({
reason: z.string().trim().min(1).max(500),
newTeams: z.array(teamName).max(8).default([]),
@@ -77,6 +81,7 @@ export function teamSetupRevision(bot: BotRecord, fields?: TeamSetupFields): str
if (fields.section !== undefined) scope.section = section(bot.section);
if (fields.modelSelection !== undefined) scope.modelSelection = bot.modelSelection;
if (fields.chiefOfStaff !== undefined) scope.chiefOfStaff = Boolean(bot.chiefOfStaff);
+ if (fields.mcpServers !== undefined) scope.mcpServers = bot.mcpServers ?? null;
return createHash("sha256").update(JSON.stringify(scope)).digest("hex");
}
@@ -101,6 +106,8 @@ interface Options {
autoApply?(botId: string, threadId: string): DirectApply | null;
driverCapabilities?(instanceId: string): DriverCapabilities | undefined;
validateChange?(before: BotRecord, fields: TeamSetupFields): void;
+ /** Why this MCP server cannot be given to this bot (unknown, or another bot's own); null when it can. */
+ mcpServerProblem?(name: string, botId: string): string | null;
maxBots: number;
ownsThread(botId: string, threadId: string): boolean;
/** `request` only for a reviewed deletion; Undo of a creation deletes without one. */
@@ -134,7 +141,7 @@ export class TeamSetupRequestService {
}
private fields(input: z.infer<typeof fieldsSchema>, current?: BotRecord): TeamSetupFields {
- const { section: targetSection, modelSelection, chiefOfStaff, cwd: rawCwd, ...profile } = input;
+ const { section: targetSection, modelSelection, chiefOfStaff, cwd: rawCwd, mcpServers, ...profile } = input;
const safe = Object.fromEntries(Object.entries(profile).map(([key, value]) => [key, redactSecretsInText(value!)]));
const parsed = parseBotProfilePatch(safe, true);
if (!parsed.ok) throw new TeamSetupError(parsed.error);
@@ -153,6 +160,15 @@ export class TeamSetupRequestService {
if (error) throw new TeamSetupError(error);
result.modelSelection = selection;
}
+ if (mcpServers !== undefined) {
+ if (!current) throw new TeamSetupError("MCP servers can only be chosen for an existing bot; a new bot starts with the Chief's apps");
+ const names = [...new Set(mcpServers)];
+ for (const name of names) {
+ const problem = mcpServerNameError(name) ?? this.options.mcpServerProblem?.(name, current.id) ?? null;
+ if (problem) throw new TeamSetupError(`MCP server ${JSON.stringify(name)}: ${problem}`);
+ }
+ result.mcpServers = names;
+ }
return result;
}
@@ -273,9 +289,10 @@ export class TeamSetupRequestService {
proposeDeletion(args: DeletionArgs) { return this.card(this.prepareDeletion(args), args.from); }
async submit(args: SetupArgs & SubmitAuthority) {
- const grant = this.options.autoApply?.(args.botId, args.threadId) ?? null;
- if (grant) return { ...await this.applyImmediately(this.prepare(args), args.from, args.canCommit), appliedBy: grant };
- return { ...this.propose(args), applied: false, state: "pending" as const };
+ const request = this.prepare(args);
+ const grant = touchesMcp(request) ? null : this.options.autoApply?.(args.botId, args.threadId) ?? null;
+ if (grant) return { ...await this.applyImmediately(request, args.from, args.canCommit), appliedBy: grant };
+ return { ...this.card(request, args.from), applied: false, state: "pending" as const };
}
async submitDeletion(args: DeletionArgs & SubmitAuthority) {
@@ -315,6 +332,9 @@ export class TeamSetupRequestService {
this.options.driverCapabilities((value as ModelSelection).instanceId),
));
}
+ } else if (key === "mcpServers") {
+ const list = (names?: string[] | null) => names == null ? "every enabled server" : names.length ? names.join(", ") : "none";
+ lines.push(`MCP servers it can use: ${current ? `${list(current.mcpServers)} → ` : ""}${list(value as string[])}`);
} else {
const before = current ? (key === "section" ? current.section || "General" : String(current[key as keyof BotRecord] ?? "")) : undefined;
const after = key === "section" ? (value as string) || "General" : String(value);
@@ -327,7 +347,7 @@ export class TeamSetupRequestService {
if (request.operations.some((operation) => operation.action === "create")) {
lines.push(`New bots stay owner-owned after creation: the same connected apps as @${chief.name}, the workspace's default access level, a private workspace by default, avatar untouched.`);
}
- lines.push("Existing execution permissions are unchanged.");
+ lines.push(touchesMcp(request) ? "Other execution permissions are unchanged." : "Existing execution permissions are unchanged.");
}
if (!immediate) lines.push("After this decision the Chief continues once with the result.");
const title = request.deletion ? `Delete @${request.deletion.name}?`