Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(mcp): keep personal credentials out of shared config
Sebastian Bc005a8143e07
diff --git a/server/cloud-team-gateway-mcp.e2e.test.ts b/server/cloud-team-gateway-mcp.e2e.test.tsindex d60dd9d6d8..75f30844bc 100644--- a/server/cloud-team-gateway-mcp.e2e.test.ts+++ b/server/cloud-team-gateway-mcp.e2e.test.ts@@ -40,7 +40,7 @@ beforeAll(async () => {requireHeaders: { "CF-Access-Client-Id": CLIENT_ID, "CF-Access-Client-Secret": CLIENT_SECRET },callResult: (params) => ({ content: [{ type: "text", text: `order ${String((params as { arguments?: { id?: unknown } }).arguments?.id)} shipped` }] }),});- fx = await launchCloudSendFixture({ onePasswordToken: TOKEN, team: { id: "team-acme-1", name: "Acme", engine: ENGINE } });+ fx = await launchCloudSendFixture({ onePasswordToken: TOKEN, team: { id: "team-acme-1", name: "Acme", engine: ENGINE, env: { OMB_BOT_BOX: "0" } } });team = fx.team!;admin = (await team.pair(ADMIN)).token!;ada = (await team.pair(ADA)).token!;@@ -134,11 +134,20 @@ it("keeps a one-key server Only for me: the admin's own chat gets it with theirconst own = "Bearer ben-own-key-5521";const mail = await startFakeHttpMcp({ tools: [{ name: "read_inbox" }], requireHeader: { name: "Authorization", value: own } });try {- expect((await as(admin, "POST", "/api/mcp/servers", { name: "mail", type: "http", url: mail.url, headers: { Authorization: own } })).status).toBe(201);+ const shared = { type: "http", url: mail.url, headers: { Authorization: "" }, enabled: false };+ expect((await as(admin, "POST", "/api/mcp/servers", { name: "mail", ...shared })).status).toBe(201);expect((await as(admin, "PUT", "/api/team/connection-scopes", { kind: "mcp", id: "mail", scope: "person" })).body).toEqual({ scopes: { apps: [], mcp: ["mail"] } });expect((await as(admin, "PUT", "/api/team/my-connections/mcp/mail/key", { value: own })).body).toEqual({ ok: true });+ expect((await as(admin, "PUT", "/api/mcp/servers/mail", shared)).status).toBe(200);+ const saved = () => JSON.parse(readFileSync(join(team.home, ".openmausbot/config.json"), "utf8"));+ expect(saved().mcpServers.mail.headers).toEqual({ Authorization: "" });+ expect((await as(admin, "GET", "/api/team/my-connections")).body.mcp).toContainEqual(expect.objectContaining({ name: "mail", connected: true, how: "key" }));expect((await as(admin, "POST", "/api/mcp/servers/mail/test")).body).toMatchObject({ ok: true });+ expect((await as(admin, "POST", "/api/mcp/servers/mail/test")).body).toMatchObject({ ok: true });+ const otherAdmin = (await team.pair({ email: "[email protected]", role: "admin" })).token!;+ expect((await as(otherAdmin, "POST", "/api/mcp/servers/mail/test")).body).toMatchObject({ ok: false });expect((await as(admin, "PATCH", "/api/mcp/servers/mail", { enabled: true })).status).toBe(200);+ expect(saved().mcpServers.mail.headers).toEqual({ Authorization: "" });const bens = await turn(admin, "Check my inbox.", [{ name: "read_inbox", server: "mail", input: {} }], "remote execution recorded");expect(bens.mcpConfig.mcpServers.mail).toMatchObject({ url: mail.url, headers: { Authorization: own } });@@ -147,6 +156,11 @@ it("keeps a one-key server Only for me: the admin's own chat gets it with theirexpect(Object.keys(adas.mcpConfig.mcpServers)).not.toContain("mail");expect(JSON.stringify(adas)).not.toContain("ben-own-key-5521");expect(mail.calls).toHaveLength(1);+ expect((await as(admin, "PUT", "/api/team/connection-scopes", { kind: "mcp", id: "mail", scope: "team" })).status).toBe(200);+ const seen = mail.seenHeaders.length;+ expect((await as(admin, "POST", "/api/mcp/servers/mail/test")).body).toMatchObject({ ok: false });+ expect(mail.seenHeaders.slice(seen).every((headers) => headers.authorization !== own)).toBe(true);+ expect(saved().mcpServers.mail.headers).toEqual({ Authorization: "" });} finally {await mail.close();}diff --git a/server/index.ts b/server/index.tsindex ac530bbb91..1eb61ec497 100644--- a/server/index.ts+++ b/server/index.ts@@ -12780,7 +12780,7 @@ ROUTES.push(createInstanceRoutes({cliProbeEnvironment, threadBusy, botForThread, activeGroupTurnForBot, checkInstance: testedAi.check,}));ROUTES.push(createMcpServerRoutes({- cfg, sessions, mcpOAuth,+ cfg, sessions, mcpOAuth, teamConnections,cloudHome: CLOUD_HOME,fallbackPublicUrl: FALLBACK_PUBLIC_URL,mcpConfigBusy: { get: () => mcpConfigBusy, set: (busy) => { mcpConfigBusy = busy; } },diff --git a/server/routes/mcp-servers.ts b/server/routes/mcp-servers.tsindex d0dc6b1ecd..625d208aa9 100644--- a/server/routes/mcp-servers.ts+++ b/server/routes/mcp-servers.ts@@ -2,18 +2,22 @@ import type { ChatAppsMcp } from "../chat-apps-mcp.ts";import type { CloudHomeConfig } from "../cloud-home.ts";import type { AppConfig } from "../config.ts";import { hostedWorkspaceConfiguration } from "../enterprise.ts";+import type { TeamConnectionsHost } from "../host/team-connections-host.ts";import { McpOAuthError, McpSignInError, mcpCallbackOrigin, withMcpSignIn, type McpOAuthManager } from "../mcp-oauth.ts";import { probeMcpServer } from "../mcp-probe.ts";import { MAX_MCP_SERVERS, isRemoteMcpServer, mcpServerBody, parseMcpServerMutation, parseMcpServersImport, parseStoredMcpServer, type McpRunsOn } from "../mcp-registry.ts";+import { personKey } from "../person-key.ts";import { isLoopbackHost, isProxied, provesSameOrigin, requestOrigin } from "../request-auth.ts";import type { SessionRegistry } from "../sessions.ts";import type { BusyFlag } from "./config.ts";import { PASS, type RouteHandler } from "./table.ts";+import { sessionMember } from "./team-phone.ts";export interface McpServerRouteDeps {cfg: Pick<AppConfig, "mcpServers">;sessions: Pick<SessionRegistry, "isLive">;mcpOAuth: McpOAuthManager;+ teamConnections: Pick<TeamConnectionsHost, "personMcp" | "people">;cloudHome: Pick<CloudHomeConfig, "publicOrigin"> | null;fallbackPublicUrl: string | null;mcpConfigBusy: BusyFlag;@@ -73,12 +77,22 @@ export function createMcpServerRoutes(deps: McpServerRouteDeps): RouteHandler {try {const name = mcpTest[1];let target = parsed.server;- if (isRemoteMcpServer(target) && mcpOAuth.authState(name, target.url) === "signed-in") {- const signedIn = (await withMcpSignIn({ [name]: target }, mcpOAuth))[name];+ let oauth = mcpOAuth;+ const personal = deps.teamConnections.personMcp().includes(name);+ if (personal && isRemoteMcpServer(target)) {+ const member = auth.kind === "session" ? sessionMember(auth.session) : null;+ if (!member) return json(res, 403, { error: "Sign in to the team to test your own connection." });+ const person = personKey({ id: "", email: member.member.email });+ oauth = deps.teamConnections.people.oauth(person);+ const key = deps.teamConnections.people.key(person, name, target.url);+ target = { ...target, headers: key ? { [key.header]: key.value } : {} };+ }+ if (isRemoteMcpServer(target) && oauth.authState(name, target.url) === "signed-in") {+ const signedIn = (await withMcpSignIn({ [name]: target }, oauth))[name];if (signedIn) target = { ...signedIn, enabled: target.enabled } as typeof target;}- const result = await probeMcpServer(target, undefined, controller.signal, appCatalog?.probeOptions(name, parsed.server) ?? {});- if (!result.ok && result.auth === "required" && isRemoteMcpServer(target)) mcpOAuth.markNeedsSignIn(name, target.url);+ const result = await probeMcpServer(target, undefined, controller.signal, personal ? {} : appCatalog?.probeOptions(name, parsed.server) ?? {});+ if (!result.ok && result.auth === "required" && isRemoteMcpServer(target)) oauth.markNeedsSignIn(name, target.url);return json(res, 200, result);} finally {res.off("close", disconnect);diff --git a/src/components/McpServersPanel.add.test.ts b/src/components/McpServersPanel.add.test.tsindex d732288de8..1b6f404108 100644--- a/src/components/McpServersPanel.add.test.ts+++ b/src/components/McpServersPanel.add.test.ts@@ -242,8 +242,19 @@ describe("Adding an MCP server on a Team Cloud", () => {expect(calls("PUT")).toEqual([{ url: "/api/team/connection-scopes", body: { kind: "mcp", id: "mail", scope: "person" } },{ url: "/api/team/my-connections/mcp/mail/key", body: { value: "Bearer mail-key-12345" } },- { url: "/api/mcp/servers/mail", body: { type: "http", url: "https://mail.example.com/mcp", headers: { [header]: "Bearer mail-key-12345" }, enabled: false } },+ { url: "/api/mcp/servers/mail", body: { type: "http", url: "https://mail.example.com/mcp", headers: { [header]: "" }, enabled: false } },]);+ expect(fixture.sharedHeaders.mail).toEqual({ [header]: "" });+ expect(calls("POST", "/api/mcp/servers/mail/test")).toHaveLength(1);+ expect(fixture.servers).toEqual([expect.objectContaining({ name: "mail", enabled: true })]);+ expect(host.textContent).toContain(`Headers saved: ${header}`);+ expect(host.textContent).toContain("Connected: 12 tools");+ fixture.test = { ok: false, error: "Could not reach this address.", reason: "unreachable" };+ await click("Test");+ fixture.test = { ok: true, tools: [{ name: "a" }], total: 12 };+ await click("Try again");+ expect(calls("POST", "/api/mcp/servers/mail/test")).toHaveLength(3);+ expect(fixture.sharedHeaders.mail).toEqual({ [header]: "" });expect(host.textContent).toContain("Connected: 12 tools");});diff --git a/src/components/McpServersPanel.tsx b/src/components/McpServersPanel.tsxindex 1eab4d2933..864129255f 100644--- a/src/components/McpServersPanel.tsx+++ b/src/components/McpServersPanel.tsx@@ -192,7 +192,7 @@ export function McpServersPanel({ embedded = false, whopCard = false, hideWhop =await api("/api/team/connection-scopes", { method: "PUT", body: JSON.stringify({ kind: "mcp", id: item.name, scope: "person" }) });await api(`/api/team/my-connections/mcp/${encodeURIComponent(item.name)}/key`, { method: "PUT", body: JSON.stringify({ value: item.ownKey }) });latest = listed((await api(`/api/mcp/servers/${encodeURIComponent(item.name)}`, {- method: "PUT", body: JSON.stringify({ ...item.body, enabled: false }),+ method: "PUT", body: JSON.stringify({ ...body, enabled: false }),})).servers);}added.push(item.name);