Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Train fix: the MCP route takes vaultKeys only when its host says the person owns every Vault item
milind-soni7e91d3073d18
diff --git a/server/index.ts b/server/index.tsindex c69b3e81ff..8ea1300d52 100644--- a/server/index.ts+++ b/server/index.ts@@ -12398,7 +12398,7 @@ ROUTES.push(createMcpServerRoutes({cfg, bot: (id) => store.bot(id), sessions, mcpOAuth, teamConnections,cloudHome: CLOUD_HOME,fallbackPublicUrl: FALLBACK_PUBLIC_URL,- mcpServerResponse, savedCustomDomain, appCatalog: chatAppsMcp, config: mcpConfig, lender: sessionLendingPrincipal, connectionHealth, place: (server, auth) => lentMcp.place(server, { principal: sessionLendingPrincipal(auth), ...(auth.kind === "session" ? { session: auth.session.id } : {}), newest: true }) }));+ mcpServerResponse, savedCustomDomain, appCatalog: chatAppsMcp, config: mcpConfig, lender: sessionLendingPrincipal, connectionHealth, ownsVault: () => !CLOUD_TEAM && !HOSTED_WORKSPACE, place: (server, auth) => lentMcp.place(server, { principal: sessionLendingPrincipal(auth), ...(auth.kind === "session" ? { session: auth.session.id } : {}), newest: true }) }));ROUTES.push(createSetupImportRoutes({ local: DESKTOP_MANAGED && !CLOUD_HOME && !HOSTED_WORKSPACE, cfg, mcpPolicyRefusal, persistMcpServers: persistAnnouncedMcpServers,mcpConfigBusy: mcpConfig.busy }));ROUTES.push(createComputerRoutes({diff --git a/server/routes/mcp-servers.test.ts b/server/routes/mcp-servers.test.tsindex 3c7cd25019..746e74b381 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: { 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 } } = {}) {+async function serve(options: { ownsVault?: boolean; 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,8 @@ async function serve(options: { routeHome?: Parameters<typeof createMcpServerRou});const route = createMcpServerRoutes({cfg, bot: (id) => options.bots?.find((bot) => bot.id === id) ?? null, sessions, mcpOAuth, teamConnections,- cloudHome: options.routeHome ?? null,+ cloudHome: null,+ ownsVault: () => options.ownsVault ?? true,fallbackPublicUrl: null,mcpServerResponse,savedCustomDomain: () => null,@@ -105,7 +106,7 @@ it("a server arriving from a move is given the Vault items it names, by id only;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 { post } = await serve({ ownsVault: false, 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);diff --git a/server/routes/mcp-servers.ts b/server/routes/mcp-servers.tsindex 69816b0082..452f04759f 100644--- a/server/routes/mcp-servers.ts+++ b/server/routes/mcp-servers.ts@@ -43,6 +43,9 @@ export interface McpServerRouteDeps extends Pick<McpConfigDeps, "cfg" | "sessionlender?(auth: RequestAuth): string | null;/** A server the person adds that needs their own computer, marked as running on the one of theirs lent now. */place?(server: StoredMcpServer, auth: RequestAuth): Promise<{ ok: true; server: StoredMcpServer } | { ok: false; error: string }>;+ /** Whoever may change servers here owns every Vault item (not a Team Cloud or a hosted workspace), so a server arriving+ * in a move may be given the items its `vault:<id>` keys name. */+ ownsVault?(): boolean;/** Who added a server and what Test found, for the team's connections (server/host/connection-health-host.ts). */connectionHealth?: {added(kind: "mcp", name: string, email: string | null): void;@@ -70,7 +73,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 ownsVault = () => deps.ownsVault?.() === true;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 } : {}) });