Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Train fix: a Team Cloud or hosted workspace takes no vaultKeys on an MCP server
milind-soni5fe4e0286692
diff --git a/server/cloud-connections-host.ts b/server/cloud-connections-host.tsindex bb24df1ea3..ede03cb652 100644--- a/server/cloud-connections-host.ts+++ b/server/cloud-connections-host.ts@@ -70,7 +70,7 @@ export function createCloudConnectionsHost(deps: CloudConnectionsHostDeps) {...(deps.ownHome ? { ownHome: deps.ownHome } : {}),...(deps.cloudHome?.team ? { personalRefusal: (what: string) => personalConnectionRefusal(deps.cloudHome!.team!, what) } : {}),async list() {- return { computer, connections: await connections(), engines: await deps.engines().catch((): string[] => []), commands: programs(), vaultKeys: true as const,+ return { computer, connections: await connections(), engines: await deps.engines().catch((): string[] => []), commands: programs(), ...(deps.cloudHome?.team ? {} : { vaultKeys: true as const }),...(deps.cloudHome === null && !managedService() ? { managedApps: false as const } : {}) };},adoptShare: adoptComposioShare,diff --git a/server/routes/mcp-servers.test.ts b/server/routes/mcp-servers.test.tsindex 39f4d3a2d7..3c7cd25019 100644--- a/server/routes/mcp-servers.test.ts+++ b/server/routes/mcp-servers.test.ts@@ -29,7 +29,7 @@ afterEach(async () => {type Bot = { id: string; mcpServers?: string[] };-async function serve(options: { keys?: Parameters<typeof createMcpConfig>[0]["keys"]; botsPath?: () => BrokerPath | null; bots?: Bot[]; listed?: Record<string, Record<string, unknown>>; probeAs?: (server: { bot?: string }) => { id?: string; cwd?: string } } = {}) {+async function serve(options: { routeHome?: Parameters<typeof createMcpServerRoutes>[0]["cloudHome"]; keys?: Parameters<typeof createMcpConfig>[0]["keys"]; botsPath?: () => BrokerPath | null; bots?: Bot[]; listed?: Record<string, Record<string, unknown>>; probeAs?: (server: { bot?: string }) => { id?: string; cwd?: string } } = {}) {const cfg: Pick<AppConfig, "mcpServers"> = { mcpServers: {} };const changes: string[] = [];let busy = false;@@ -54,7 +54,7 @@ async function serve(options: { keys?: Parameters<typeof createMcpConfig>[0]["ke});const route = createMcpServerRoutes({cfg, bot: (id) => options.bots?.find((bot) => bot.id === id) ?? null, sessions, mcpOAuth, teamConnections,- cloudHome: null,+ cloudHome: options.routeHome ?? null,fallbackPublicUrl: null,mcpServerResponse,savedCustomDomain: () => null,@@ -103,6 +103,15 @@ it("a server arriving from a move is given the Vault items it names, by id only;expect(given).toEqual([["stripe", [item]]]);});+it("a Team Cloud takes no vaultKeys: an admin's server can't be given a member's saved secret", async () => {+ const given: Array<[string, readonly string[]]> = [];+ const { post } = await serve({ routeHome: { team: { name: "Team" } } as never, keys: { grant: (name: string, items: readonly string[]) => given.push([name, items]), warm: async () => {}, forgetServer: () => {}, resolve: (_n: string, server: object) => ({ ok: true, server }), oauthClient: (_n: string, o: object) => o, usedBy: () => [], given: () => [] } as never });+ const item = "cccccccc-cccc-4ccc-8ccc-cccccccccccc";+ const added = await post("/api/mcp/servers", { name: "stripe", command: "npx", args: ["x"], env: { KEY: `vault:${item}` }, vaultKeys: [item] });+ expect(added.status, await added.clone().text()).toBe(201);+ expect(given).toEqual([]);+});+it("adds a command server sent with type stdio, as other MCP clients write it, and keeps the old shape working", async () => {const { cfg, post } = await serve();const typed = await post("/api/mcp/servers", { name: "notes", type: "stdio", command: "npx", args: ["-y", "notes-mcp"] });diff --git a/server/routes/mcp-servers.ts b/server/routes/mcp-servers.tsindex bf4239f391..69816b0082 100644--- a/server/routes/mcp-servers.ts+++ b/server/routes/mcp-servers.ts@@ -26,10 +26,12 @@ function botMcpServers(listed: readonly ListedMcpServer[], bot: { id: string; mc}));}-/** The Vault items a server arriving in a move may read its `vault:<id>` keys from. */-const vaultKeysOf = (body: unknown): string[] | undefined => {+/** The Vault items a server arriving in a move may read its `vault:<id>` keys from.+ * Security: only where whoever may change servers owns every Vault item; on a Team Cloud or a hosted workspace an admin+ * could otherwise point a server of theirs at a member's saved secret. */+const vaultKeysOf = (body: unknown, ownsVault: boolean): string[] | undefined => {const keys = (body as { vaultKeys?: unknown } | null)?.vaultKeys;- return Array.isArray(keys) ? keys.filter(isVaultItemId) : undefined;+ return ownsVault && Array.isArray(keys) ? keys.filter(isVaultItemId) : undefined;};export interface McpServerRouteDeps extends Pick<McpConfigDeps, "cfg" | "sessions" | "mcpOAuth" | "teamConnections" | "cloudHome" | "fallbackPublicUrl" | "savedCustomDomain" | "appCatalog"> {@@ -68,6 +70,7 @@ export function createMcpServerRoutes(deps: McpServerRouteDeps): RouteHandler {cfg, sessions, mcpOAuth, cloudHome: CLOUD_HOME, fallbackPublicUrl: FALLBACK_PUBLIC_URL,mcpServerResponse, savedCustomDomain, config,} = deps;+ const ownsVault = () => !CLOUD_HOME?.team && !hostedWorkspaceConfiguration();const answer = (res: Parameters<typeof json>[0], send: typeof json, result: McpConfigResult) => "body" in result? send(res, result.status, withServerDetails(result.body)): send(res, result.status, { error: result.error, ...userErrorFields(result), ...(result.code ? { code: result.code } : {}) });@@ -178,7 +181,7 @@ export function createMcpServerRoutes(deps: McpServerRouteDeps): RouteHandler {if (!parsed.ok) return json(res, 400, { error: parsed.error });const placed = deps.place ? await deps.place(parsed.server, auth) : { ok: true as const, server: parsed.server };if (!placed.ok) return json(res, 409, { error: placed.error });- const added = config.add(name, placed.server, vaultKeysOf(body));+ const added = config.add(name, placed.server, vaultKeysOf(body, ownsVault()));if (added.status < 300) deps.connectionHealth?.added("mcp", name, auth.kind === "session" ? auth.session.email ?? null : null);return answer(res, json, added);}@@ -233,7 +236,7 @@ export function createMcpServerRoutes(deps: McpServerRouteDeps): RouteHandler {const { vaultKeys: _keys, ...fields } = (body ?? {}) as Record<string, unknown>;const parsed = parseMcpServerMutation(name, fields, existing.server);if (!parsed.ok) return json(res, 400, { error: parsed.error });- return answer(res, json, config.replace(name, parsed.server, vaultKeysOf(body)));+ return answer(res, json, config.replace(name, parsed.server, vaultKeysOf(body, ownsVault())));}return PASS;};