Skip to content

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

fix(mcp): preserve panel OAuth for personal connection tests

Sebastian B07b88a336e0e
diff --git a/server/cloud-team-connections.e2e.test.ts b/server/cloud-team-connections.e2e.test.ts
index 62002beffa..397c9ddf93 100644
--- a/server/cloud-team-connections.e2e.test.ts
+++ b/server/cloud-team-connections.e2e.test.ts
@@ -257,6 +257,37 @@ it("disconnects her own, and switching back to the team gives every turn the tea
expect(gmailCallsBy(teamUser)).toBe(teamBefore + 1);
}, hostTimeout(120_000));
+it.each([false, true])("tests a person-scoped OAuth server after panel sign-in (registered client: %s)", async (registered) => {
+ const provider = await startFakeOAuth({ preRegistered: { "panel-client": null } });
+ const server = await startFakeHttpMcp({ acceptBearer: provider.isValid, wwwAuthenticate: provider.challenge });
+ const path = "/api/mcp/servers/panel_oauth";
+ try {
+ expect((await team.as(owner, "POST", "/api/mcp/servers", {
+ name: "panel_oauth", type: "http", url: server.url,
+ ...(registered ? { oauth: { clientId: "panel-client" }, headers: { "X-Workspace": "acme" } } : {}),
+ })).status).toBe(201);
+ expect((await team.as(owner, "PUT", "/api/team/connection-scopes", { kind: "mcp", id: "panel_oauth", scope: "person" })).status).toBe(200);
+ expect((await team.as(owner, "POST", `${path}/test`, {})).body.auth).toBe("required");
+ const started = await team.as(owner, "POST", `${path}/sign-in`, {});
+ expect(started.status, JSON.stringify(started.body)).toBe(200);
+ const redirect = await fetch(started.body.auth.authorizationUrl, { redirect: "manual" });
+ const flowPath = `${path}/sign-in/${started.body.auth.flowId}`;
+ const completed = await team.as(owner, "POST", flowPath, { callbackUrl: redirect.headers.get("location") });
+ expect(completed.status, JSON.stringify(completed.body)).toBe(200);
+ expect(completed.body.auth.phase).toBe("succeeded");
+ expect((await team.as(owner, "GET", flowPath)).body.auth.phase).toBe("succeeded");
+ const tested = await team.as(owner, "POST", `${path}/test`, {});
+ expect(tested.status).toBe(200);
+ expect(tested.body).toMatchObject({ ok: true, tools: [{ name: "read_notes" }] });
+ expect((await team.as(owner, "POST", `${path}/sign-out`, {})).status).toBe(200);
+ expect((await team.as(owner, "POST", `${path}/test`, {})).body.auth).toBe("required");
+ } finally {
+ await team.as(owner, "DELETE", path);
+ await server.close();
+ await provider.close();
+ }
+}, hostTimeout(60_000));
+
it("skips automatic personal MCP probes after setup and restart while still probing team servers", async () => {
const ownAuthorization = "Bearer own-probe-key";
const teamAuthorization = "Bearer team-probe-key";
diff --git a/server/routes/mcp-servers.ts b/server/routes/mcp-servers.ts
index 625d208aa9..3af4916f52 100644
--- a/server/routes/mcp-servers.ts
+++ b/server/routes/mcp-servers.ts
@@ -79,7 +79,7 @@ export function createMcpServerRoutes(deps: McpServerRouteDeps): RouteHandler {
let target = parsed.server;
let oauth = mcpOAuth;
const personal = deps.teamConnections.personMcp().includes(name);
- if (personal && isRemoteMcpServer(target)) {
+ if (personal && isRemoteMcpServer(target) && !target.oauth && Object.keys(target.headers).length > 0) {
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 });