Skip to content

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

Merge #5145: One copy for MCP secrets, and Vault secrets travel with Send to My Cloud

milind-soni0034a00c6fe4
diff --cc server/chat-apps-mcp.test.ts
index 545ccb5b5c,56cd8dc702..e0c18146cd
--- a/server/chat-apps-mcp.test.ts
+++ b/server/chat-apps-mcp.test.ts
@@@ -35,7 -35,7 +35,7 @@@ const REPORT =
const cleanup: Array<() => Promise<void> | void> = [];
afterEach(async () => { for (const step of cleanup.splice(0).reverse()) await step(); });
- function setup(options: { servers?: Record<string, Record<string, unknown>>; scope?: BotRecord["toolScope"]; approval?: "ask" | "full"; needsSignIn?: string[]; probe?: typeof probeMcpServer; oauth?: ChatAppsMcpOAuth; startupProbes?: boolean; probeAs?: (server: { bot?: string }) => { id?: string; cwd?: string } } = {}) {
-function setup(options: { keys?: Parameters<typeof createChatAppsMcp>[0]["keys"]; servers?: Record<string, Record<string, unknown>>; scope?: BotRecord["toolScope"]; approval?: "ask" | "full"; needsSignIn?: string[]; probe?: typeof probeMcpServer; oauth?: ChatAppsMcpOAuth; startupProbes?: boolean } = {}) {
++function setup(options: { keys?: Parameters<typeof createChatAppsMcp>[0]["keys"]; servers?: Record<string, Record<string, unknown>>; scope?: BotRecord["toolScope"]; approval?: "ask" | "full"; needsSignIn?: string[]; probe?: typeof probeMcpServer; oauth?: ChatAppsMcpOAuth; startupProbes?: boolean; probeAs?: (server: { bot?: string }) => { id?: string; cwd?: string } } = {}) {
const dataDir = mkdtempSync(join(tmpdir(), "omb-chat-apps-mcp-"));
cleanup.push(() => removeTempDir(dataDir));
const threads = new Map<string, Message[]>();
@@@ -74,7 -74,7 +74,8 @@@
oauth: options.oauth ?? { authState: (name) => (options.needsSignIn?.includes(name) ? "needs-sign-in" : "none"), accessToken: async () => null, requireSignIn: () => {} },
startupProbes: options.startupProbes ?? false,
...(options.probe ? { probe: options.probe } : {}),
+ ...(options.probeAs ? { probeAs: options.probeAs } : {}),
+ ...(options.keys ? { keys: options.keys } : {}),
log: (line) => lines.push(line),
});
cleanup.push(() => { mcp.close(); apps.close(); });
diff --cc server/chat-apps-mcp.ts
index a43b7a9490,d2cdfebcfb..aaf548ae17
--- a/server/chat-apps-mcp.ts
+++ b/server/chat-apps-mcp.ts
@@@ -42,10 -43,10 +43,12 @@@ export interface ChatAppsMcpDeps
store: ChatAppsMcpStore;
apps: ChatApps;
storedServers(): Record<string, unknown>;
+ /** A server's `vault:<id>` keys, read when it is probed. */
+ keys?: McpKeys;
mountedServers(bot: BotRecord): Record<string, McpServerSpec>;
personMcp?(): readonly string[];
+ /** How a command server is started outside a turn: as the turns of its bot, or of any bot (server/mcp-probe.ts `asBot`). */
+ probeAs?(server: { bot?: string }): NonNullable<McpProbeOptions["asBot"]>;
oauth: ChatAppsMcpOAuth;
dataDir?: string;
catalog?: McpAppCatalog;
@@@ -402,10 -396,13 +405,13 @@@ export function createChatAppsMcp(deps
const stored = storedServer(name, deps.storedServers()[name]);
if (!stored?.enabled || stored.apps === false || stored.runsOn) return;
if (isRemoteMcpServer(stored) && deps.oauth.authState(name, stored.url) === "needs-sign-in") return;
- const target = isRemoteMcpServer(stored) ? await signedIn(name, stored) : stored;
+ await deps.keys?.warm(name, stored);
+ const keyed = deps.keys ? deps.keys.resolve(name, stored) : { ok: true as const, server: stored };
+ if (!keyed.ok) return;
+ const target = isRemoteMcpServer(keyed.server) ? await signedIn(name, keyed.server) : keyed.server;
if (!target) return;
const probed = { ...target, enabled: true } as StoredMcpServer;
- const result = await probe(probed, BACKGROUND_PROBE_MS, undefined, { ...probeOptions(name, stored), ...(isRemoteMcpServer(probed) ? {} : { asBot: asBot(name) }) });
- const result = await probe(probed, BACKGROUND_PROBE_MS, undefined, probeOptions(name, keyed.server));
++ const result = await probe(probed, BACKGROUND_PROBE_MS, undefined, { ...probeOptions(name, keyed.server), ...(isRemoteMcpServer(probed) ? {} : { asBot: asBot(name) }) });
if (!result.ok && result.auth === "required" && isRemoteMcpServer(probed) && !sendsCredentials(probed)) deps.oauth.requireSignIn(name, probed.url);
log(`probed ${name}: ${result.ok ? `apps=${catalog.get(name, stored)?.apps === true}` : result.auth === "required" ? "needs sign-in" : "failed"}`);
}).catch((error: unknown) => log(`probe of ${name} failed: ${String(error)}`));
diff --cc server/host/mcp-config.ts
index ff47baf384,b1ee3d23d3..7e0da9d4e8
--- a/server/host/mcp-config.ts
+++ b/server/host/mcp-config.ts
@@@ -260,7 -275,7 +275,7 @@@ export function createMcpConfig(deps: M
sentSignIn = true;
}
}
- const options = { tryReadOnlyTool: true, ...(personal ? {} : appCatalog?.probeOptions(name, parsed.server) ?? {}), ...(asBot ? { asBot } : isRemoteMcpServer(target) ? {} : { asBot: deps.probeAs?.(target) ?? {} }) };
- const options = { ...(personal ? {} : appCatalog?.probeOptions(name, cataloged) ?? {}), ...(asBot ? { asBot } : isRemoteMcpServer(target) ? {} : { asBot: deps.probeAs?.(target) ?? {} }) };
++ const options = { tryReadOnlyTool: true, ...(personal ? {} : appCatalog?.probeOptions(name, cataloged) ?? {}), ...(asBot ? { asBot } : isRemoteMcpServer(target) ? {} : { asBot: deps.probeAs?.(target) ?? {} }) };
const viaBots = isRemoteMcpServer(target) ? deps.botsPath?.() ?? null : null;
const result = viaBots && isRemoteMcpServer(target)
? await probeAsBots(viaBots, name, target, signal, options)
diff --cc server/host/team-connections-host.ts
index 3b88555812,f1510112be..0960793718
--- a/server/host/team-connections-host.ts
+++ b/server/host/team-connections-host.ts
@@@ -15,8 -15,8 +15,8 @@@ import type * as Composio from "../comp
import type { AppConfig } from "../config.ts";
import type { McpServerSpec } from "../contracts.ts";
import { serviceSlugFor } from "../connector-verdict.ts";
-import { type McpOAuthManager, type McpSignInPhase, withMcpSignIn, withoutPendingSignIn } from "../mcp-oauth.ts";
+import { type McpOAuthManager, type McpRefreshOutcome, type McpSignInPhase, withMcpSignIn, withoutPendingSignIn } from "../mcp-oauth.ts";
- import { isRemoteMcpServer, parseStoredMcpServer } from "../mcp-registry.ts";
+ import { isRemoteMcpServer, parseStoredMcpServer, type McpOAuthClientConfig } from "../mcp-registry.ts";
import { OWN_APPS_SERVER } from "../../shared/own-apps.ts";
import { appLabel, ConnectionScopes, PeopleConnections, personAppOf, SCOPES_FILE, type BrokerAccess } from "../team-connections.ts";
import { APP_TOOL_NAMES_ENV, APP_TOOLS_ENV, appToolsFor } from "../connector-app-tools.ts";
@@@ -77,11 -73,9 +79,11 @@@ export function createTeamConnectionsHo
const people = new PeopleConnections({
dataDir: deps.dataDir,
brokerUrl: deps.brokerUrl,
- clients: (name, url) => { const server = teamServer(name); return server && isRemoteMcpServer(server) && server.url === url ? server.oauth : undefined; },
+ clients: (name, url) => { const server = teamServer(name); return server && isRemoteMcpServer(server) && server.url === url ? (server.oauth && deps.oauthClient ? deps.oauthClient(name, server.oauth) : server.oauth) : undefined; },
isOwnerLive: deps.isOwnerLive,
...(deps.onSettled ? { onSettled: deps.onSettled } : {}),
+ ...(deps.onRefresh ? { onRefresh: deps.onRefresh } : {}),
+ ...(deps.onPersonChanged ? { onChanged: deps.onPersonChanged } : {}),
});
const personApps = () => (team ? scopes.person("app") : []);
/** The apps connected for an installation, the team's or a member's own. A turn never waits on a refresh: what is known
diff --cc server/index.ts
index d84949232d,1d4b0b68a0..6091394d9f
--- a/server/index.ts
+++ b/server/index.ts
@@@ -1380,8 -1382,8 +1380,8 @@@ const mcpOAuth = new McpOAuthManager(
// Connector tool grants only filter tools/list; the relay's verdict decides each call.
const teamConnections = createTeamConnectionsHost({ team: CLOUD_TEAM, dataDir: DATA_DIR, cfg: () => cfg, adminOrigin: CLOUD_HOME?.adminOrigin ?? null, harnessUrl: `http://127.0.0.1:${PORT}`, audienceOf: teamHost.audienceOf,
requester: (threadId, generation) => actingPeople.requester(threadId, generation), personName: (person) => teamHost.personName(person), roster: () => (teamOwners.people?.list() ?? []).map((member) => ({ person: personKey({ id: "", email: member.email }), email: member.email, role: member.role })),
- mint: (capability) => mintInternalCapability({ ...capability, depth: 0, kind: "connectors", skillAuthoring: false, createdBots: 0, openedThreads: 0 }), mcpOAuth, isOwnerLive: (owner) => sessions.isLive(owner) || isCardOwnerLive(store, owner), onSettled: (name, phase, owner) => mcpSignInCards.settled(name, phase, owner),
- botMcp: (bot) => mcpServersHost.mounted(bot), oauthClient: mcpKeys.oauthClient, brokerUrl: () => (CLOUD_TEAM ? cloudConnectedAppsBrokerUrl() || null : null), composio }); teamConnections.primeApps();
+ mint: (capability) => mintInternalCapability({ ...capability, depth: 0, kind: "connectors", skillAuthoring: false, createdBots: 0, openedThreads: 0 }), mcpOAuth, isOwnerLive: (owner) => sessions.isLive(owner) || isCardOwnerLive(store, owner), onSettled: (name, phase, owner) => mcpSignInCards.settled(name, phase, owner), onRefresh: (person, name, outcome) => connectionHealth.refreshed(person, name, outcome), onPersonChanged: (person, kind, id) => connectionHealth.connectedAgain({ kind, id, person }),
- botMcp: (bot) => mcpServersHost.mounted(bot), brokerUrl: () => (CLOUD_TEAM ? cloudConnectedAppsBrokerUrl() || null : null), composio }); teamConnections.primeApps(); const connectionHealth = createConnectionHealthHost({ dataDir: CLOUD_TEAM ? DATA_DIR : null, mcpServers: () => cfg.mcpServers ?? {}, mcpOAuth, connections: teamConnections, bots: () => store.bots, botServers: (bot) => Object.keys(mcpServersHost.mounted(bot)), roster: () => teamOwners.people?.list() ?? [], personKey: (email) => personKey({ id: "", email }), personName: (email) => teamHost.people.profile(personKey({ id: "", email })).name || null, test: (name, signal) => mcpConfig.test(name, { signal, person: () => null }), asleep: () => cloudPowerNow()?.sleeping() ?? false, wokeAt: () => cloudPowerNow()?.sleptUntil() ?? null }); if (CLOUD_TEAM) connectionHealth.start();
++ botMcp: (bot) => mcpServersHost.mounted(bot), oauthClient: mcpKeys.oauthClient, brokerUrl: () => (CLOUD_TEAM ? cloudConnectedAppsBrokerUrl() || null : null), composio }); teamConnections.primeApps(); const connectionHealth = createConnectionHealthHost({ dataDir: CLOUD_TEAM ? DATA_DIR : null, mcpServers: () => cfg.mcpServers ?? {}, mcpOAuth, connections: teamConnections, bots: () => store.bots, botServers: (bot) => Object.keys(mcpServersHost.mounted(bot)), roster: () => teamOwners.people?.list() ?? [], personKey: (email) => personKey({ id: "", email }), personName: (email) => teamHost.people.profile(personKey({ id: "", email })).name || null, test: (name, signal) => mcpConfig.test(name, { signal, person: () => null }), asleep: () => cloudPowerNow()?.sleeping() ?? false, wokeAt: () => cloudPowerNow()?.sleptUntil() ?? null }); if (CLOUD_TEAM) connectionHealth.start();
// OpenCode reads provider keys (ANTHROPIC_API_KEY, OPENAI_API_KEY, …) from its environment. Wired before the first catalog probe below.
let openCodeOrganisationManaged = (): boolean => false;
const openCodeKeysAllowed = (): boolean => openCodeProviderKeysAllowed({
@@@ -12109,7 -12129,7 +12109,7 @@@ ROUTES.push(createBotMessageRoutes(
{ emoji, name: person.name ?? person.email, at: Date.now() }),
}));
const liveRoots = (threadId: string, botId: string | undefined) => { const bot = botId ? store.bot(botId) : store.botByThread(threadId); return bot ? messageFileRootsForThread(bot.id, threadId).filter((root) => root !== ATTACHMENTS_DIR) : null; }; const chatApps = createChatApps({ store, dataDir: DATA_DIR, liveRows: liveAppRows, liveRoots, paused: () => workspaceMaintenance.active || moveFreeze.frozen() });
- const chatAppsMcp = createChatAppsMcp({ store, apps: chatApps, dataDir: DATA_DIR, storedServers: () => cfg.mcpServers ?? {}, mountedServers: engineMcpServers, personMcp: teamConnections.personMcp, probeAs: (server) => mcpServersHost.probeAs(server), oauth: mcpOAuth });
-const chatAppsMcp = createChatAppsMcp({ store, apps: chatApps, dataDir: DATA_DIR, keys: mcpKeys, storedServers: () => cfg.mcpServers ?? {}, mountedServers: engineMcpServers, personMcp: teamConnections.personMcp, oauth: mcpOAuth });
++const chatAppsMcp = createChatAppsMcp({ store, apps: chatApps, dataDir: DATA_DIR, keys: mcpKeys, storedServers: () => cfg.mcpServers ?? {}, mountedServers: engineMcpServers, personMcp: teamConnections.personMcp, probeAs: (server) => mcpServersHost.probeAs(server), oauth: mcpOAuth });
ROUTES.push(createChatAppRoutes({ store, apps: chatApps, threadRefusal: cloudThreadRefusal, mcpRpc: chatAppsMcp.rpc, threadVisible: (auth, threadId) => (auth.kind !== "session" || sessions.isLive(auth.session.id)) && visibleTo(viewerFor(auth)).thread(threadId) }));
const { react } = createReactions({
store, reply: (input) => teamMessages.reactedIn(input.auth, input.threadId, input.target.id, input.answer, { sendId: input.sendId, sender: messageSender(input.auth) }) ?? personReplies.deliver({ ...input, about: "message" }),
diff --cc server/routes/mcp-servers.ts
index 55bad00ab2,c2d22f854b..bf4239f391
--- a/server/routes/mcp-servers.ts
+++ b/server/routes/mcp-servers.ts
@@@ -2,8 -2,8 +2,9 @@@ import { userError, userErrorFields } f
import { hostedWorkspaceConfiguration } from "../enterprise.ts";
import { runsElsewhere, type McpConfig, type McpConfigDeps, type McpConfigResult } from "../host/mcp-config.ts";
import { McpOAuthError, McpSignInError, mcpCallbackOrigin } from "../mcp-oauth.ts";
-import { isRemoteMcpServer, mcpServerBody, mcpServerServes, parseMcpServerMutation, parseMcpServersImport, parseStoredMcpServer, type StoredMcpServer } from "../mcp-registry.ts";
+import { isRemoteMcpServer, mcpServerBody, mcpServerNotFound, mcpServerServes, parseMcpServerMutation, parseMcpServersImport, parseStoredMcpServer, type StoredMcpServer } from "../mcp-registry.ts";
+import type { McpProbeResult } from "../mcp-probe.ts";
+ import { isVaultItemId } from "../vault/mcp-keys.ts";
import { personKey } from "../person-key.ts";
import type { RequestAuth } from "../request-auth.ts";
import { toolBudgetOf } from "../tool-budgets.ts";
@@@ -171,9 -170,7 +178,9 @@@ export function createMcpServerRoutes(d
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);
- return answer(res, json, config.add(name, placed.server, vaultKeysOf(body)));
++ const added = config.add(name, placed.server, vaultKeysOf(body));
+ if (added.status < 300) deps.connectionHealth?.added("mcp", name, auth.kind === "session" ? auth.session.email ?? null : null);
+ return answer(res, json, added);
}
// The {"mcpServers": {...}} block other agent tools write; imported servers stay disabled until enabled.