Skip to content

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

MCP Sign-in app: set a custom return address in the editor

erywim88bd43fbc4b2
diff --git a/server/host/mcp-chat.ts b/server/host/mcp-chat.ts
index 6826360be8..5eb7e88479 100644
--- a/server/host/mcp-chat.ts
+++ b/server/host/mcp-chat.ts
@@ -132,7 +132,7 @@ export function createMcpChat(deps: McpChatDeps) {
const servers = listMcpServers(cfg.mcpServers).map((server) => {
if (!("url" in server)) return server;
const auth = mcpOAuth.authState(server.name, server.url);
- const listed = server.oauth ? { ...server, oauth: { ...server.oauth, redirectUri: server.oauth.redirectUri ?? mcpOAuthRedirectUri(server.url) } } : server;
+ const listed = server.oauth ? { ...server, oauth: { ...server.oauth, redirectUri: server.oauth.redirectUri ?? mcpOAuthRedirectUri(server.url), redirectUriDefault: !server.oauth.redirectUri } } : server;
return auth === "none" ? listed : { ...listed, auth };
}).map(mcpServersHost.listing).map((server) => {
const managedBy = mcpManagedBy(server.name, server);
diff --git a/server/index.test.ts b/server/index.test.ts
index 0b816667bf..a5be0a0806 100644
--- a/server/index.test.ts
+++ b/server/index.test.ts
@@ -9040,7 +9040,7 @@ describe("harness HTTP API", () => {
expect(created.status).toBe(201);
expect(created.body.servers).toEqual([{
name: "corp", type: "http", url, headerKeys: [], enabled: false, apps: true, scope: "team",
- oauth: { clientId: "corp-app", scopes: ["mcp", "offline_access"], clientSecretConfigured: true, redirectUri: expect.stringMatching(/^http:\/\/127\.0\.0\.1:\d+\/mcp-oauth\/callback$/) },
+ oauth: { clientId: "corp-app", scopes: ["mcp", "offline_access"], clientSecretConfigured: true, redirectUri: expect.stringMatching(/^http:\/\/127\.0\.0\.1:\d+\/mcp-oauth\/callback$/), redirectUriDefault: true },
}]);
expect((await api("POST", "/api/mcp/servers/corp/test")).body.auth).toBe("required");
diff --git a/server/mcp-registry.test.ts b/server/mcp-registry.test.ts
index 59cc7c8dd3..e74d2a0bc8 100644
--- a/server/mcp-registry.test.ts
+++ b/server/mcp-registry.test.ts
@@ -329,6 +329,14 @@ describe("a url server's sign-in app", () => {
});
});
+ it("returns a cleared redirect uri to the default loopback address", () => {
+ const configured = { ...saved, oauth: { clientId: "corp-app", redirectUri: "https://maus.example/mcp-oauth/callback" } };
+ expect(parseMcpServerMutation("docs", { url, oauth: { clientId: "corp-app", redirectUri: "" } }, configured)).toEqual({
+ ok: true,
+ server: { type: "http", url, headers: {}, oauth: { clientId: "corp-app" }, enabled: true },
+ });
+ });
+
it("keeps a saved secret behind a placeholder only for the same client id", () => {
expect(parseMcpServerMutation("docs", { url, oauth: { clientId: "corp-app", clientSecret: true } }, saved)).toEqual({
ok: true,
diff --git a/server/mcp-registry.ts b/server/mcp-registry.ts
index d1295ba21d..a56bbb769c 100644
--- a/server/mcp-registry.ts
+++ b/server/mcp-registry.ts
@@ -40,8 +40,10 @@ export interface McpOAuthClientConfig {
redirectUri?: string;
}
-/** The return address a configured app may name: this server's https address, at the callback path. */
+/** The return address a configured app may name: this server's https address, at the callback path. An empty value asks
+ * for the default loopback address instead. */
export function mcpConfiguredRedirectError(value: string): string | null {
+ if (!value) return null;
let url: URL;
try {
url = new URL(value);
@@ -85,7 +87,7 @@ export interface RemoteMcpServerListing {
enabled: boolean;
resultBudget?: number;
apps: boolean;
- oauth?: { clientId: string; scopes: string[]; clientSecretConfigured: boolean; redirectUri?: string };
+ oauth?: { clientId: string; scopes: string[]; clientSecretConfigured: boolean; redirectUri?: string; redirectUriDefault?: boolean };
runsOn?: McpRunsOn;
bot?: string;
}
@@ -294,11 +296,13 @@ function resolveOAuthClient(
clientSecret = incoming.clientSecret;
}
const scopes = [...new Set(incoming.scopes ?? [])];
- if (incoming.redirectUri !== undefined) {
+ if (incoming.redirectUri) {
const redirectError = mcpConfiguredRedirectError(incoming.redirectUri);
if (redirectError) return { ok: false, error: redirectError };
}
- const redirectUri = incoming.redirectUri ?? (saved?.clientId === incoming.clientId ? saved.redirectUri : undefined);
+ const redirectUri = incoming.redirectUri === ""
+ ? undefined
+ : incoming.redirectUri ?? (saved?.clientId === incoming.clientId ? saved.redirectUri : undefined);
return {
ok: true,
value: {
diff --git a/src/components/McpServerEditor.tsx b/src/components/McpServerEditor.tsx
index 678bee2557..92339546d9 100644
--- a/src/components/McpServerEditor.tsx
+++ b/src/components/McpServerEditor.tsx
@@ -2,6 +2,7 @@ import { useState } from "react";
import { ChevronDown, ChevronRight, Loader2 } from "lucide-react";
import { cn } from "@/lib/cn";
+import { useCopyFeedback } from "@/lib/copy-text";
import { t } from "@/lib/i18n";
import { readMcpPaste, type McpPasteError } from "@/lib/mcp-paste";
@@ -47,6 +48,7 @@ export function McpServerEditor({ server, fixKeys = false, taken, team, busy, on
const draft = drafts.length === 1 ? drafts[0]! : null;
const setDraft = (update: (current: McpDraft) => McpDraft) => setDrafts((current) => current.length === 1 ? [update(current[0]!)] : current);
const savedOAuth = server && isRemoteMcpListing(server) ? server.oauth : undefined;
+ const redirectCopy = useCopyFeedback(savedOAuth?.redirectUri ?? "");
const secretKept = Boolean(savedOAuth?.clientSecretConfigured && !draft?.oauthForgetSecret);
const canKeepOwn = team && adding && draft !== null && soleKey(draft) !== null;
@@ -161,7 +163,14 @@ export function McpServerEditor({ server, fixKeys = false, taken, team, busy, on
</div>
<div className="sm:col-span-2">
<div className="text-[12px] font-medium text-ink">{t("mcp.oauth.title")}</div>
- <p className="mt-1 text-[11px] leading-relaxed text-ink-secondary">{savedOAuth ? t("mcp.oauth.hintRedirect", { uri: savedOAuth.redirectUri }) : t("mcp.oauth.hint")}</p>
+ <p className="mt-1 flex flex-wrap items-center gap-2 text-[11px] leading-relaxed text-ink-secondary">
+ <span>{savedOAuth ? t("mcp.oauth.hintRedirect", { uri: savedOAuth.redirectUri }) : t("mcp.oauth.hint")}</span>
+ {savedOAuth && (
+ <button type="button" onClick={redirectCopy.copy} className="shrink-0 rounded border border-hairline/60 px-1.5 py-0.5 text-[11px] text-ink-secondary hover:text-ink">
+ {t(redirectCopy.state === "copied" ? "mcp.oauth.copied" : redirectCopy.state === "failed" ? "mcp.oauth.copyFailed" : "mcp.oauth.copy")}
+ </button>
+ )}
+ </p>
<div className="mt-2 grid gap-4 sm:grid-cols-2">
<label className="block">
<span className={LABEL}>{t("mcp.oauth.clientId")}</span>
@@ -186,6 +195,12 @@ export function McpServerEditor({ server, fixKeys = false, taken, team, busy, on
<input value={draft.oauthScopes} placeholder="offline_access api://my-app/mcp.read" spellCheck={false} className={cn(FIELD, "font-mono text-[12px]")}
onChange={(event) => setDraft((current) => ({ ...current, oauthScopes: event.target.value }))} />
</label>
+ <label className="block sm:col-span-2">
+ <span className={LABEL}>{t("mcp.oauth.redirectUri")}</span>
+ <input value={draft.oauthRedirectUri} placeholder={savedOAuth?.redirectUri ?? "https://maus.example/mcp-oauth/callback"} spellCheck={false} autoComplete="off" className={cn(FIELD, "font-mono text-[12px]")}
+ onChange={(event) => setDraft((current) => ({ ...current, oauthRedirectUri: event.target.value }))} />
+ <span className="mt-1.5 block text-[11px] text-ink-secondary">{t("mcp.oauth.redirectHint")}</span>
+ </label>
</div>
</div>
</>
diff --git a/src/components/McpServersPanel.add.test.ts b/src/components/McpServersPanel.add.test.ts
index 6121e327cb..296161b84a 100644
--- a/src/components/McpServersPanel.add.test.ts
+++ b/src/components/McpServersPanel.add.test.ts
@@ -356,6 +356,28 @@ describe("Adding an MCP server on a Team Cloud", () => {
expect(host.querySelector("[data-mcp-editor]")).toBeNull();
});
+ it("shows the sign-in app's return address, copies it, and saves an edited one", async () => {
+ fixture.servers = [{
+ name: "mail", type: "http", url: "https://mail.example.com/mcp", headerKeys: [], enabled: true,
+ oauth: { clientId: "fixture-client-id", scopes: [], clientSecretConfigured: false, redirectUri: "https://maus.example/mcp-oauth/callback", redirectUriDefault: false },
+ }];
+ await act(async () => host.querySelector<HTMLButtonElement>("[aria-label='Refresh MCP servers']")!.click());
+ await settle();
+ await act(async () => host.querySelector<HTMLButtonElement>("[aria-label='Edit mail']")!.click());
+ await settle();
+ const writeText = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined);
+ await click("Copy");
+ expect(writeText).toHaveBeenCalledWith("https://maus.example/mcp-oauth/callback");
+
+ const field = "input[placeholder='https://maus.example/mcp-oauth/callback']";
+ expect(host.querySelector<HTMLInputElement>(field)!.value).toBe("https://maus.example/mcp-oauth/callback");
+ await type(field, "https://new.example/mcp-oauth/callback");
+ await click("Save");
+ expect(calls("PUT", "/api/mcp/servers/mail")[0]!.body).toMatchObject({
+ oauth: { clientId: "fixture-client-id", redirectUri: "https://new.example/mcp-oauth/callback" },
+ });
+ });
+
it.each([
["edit", ""], ["fix", ""],
["edit", "Bearer replacement-key"], ["fix", "Bearer replacement-key"],
diff --git a/src/components/McpServersPanel.test.ts b/src/components/McpServersPanel.test.ts
index 2d316ab746..b856c476bb 100644
--- a/src/components/McpServersPanel.test.ts
+++ b/src/components/McpServersPanel.test.ts
@@ -74,7 +74,7 @@ describe("MCP server form", () => {
});
it("sends a sign-in app only with a client id, keeping a saved secret behind a blank", () => {
- const blank = { clientId: "", clientSecret: "", scopes: "", forgetSecret: false };
+ const blank = { clientId: "", clientSecret: "", scopes: "", redirectUri: "", forgetSecret: false };
expect(parseMcpOAuthClient(blank)).toBeUndefined();
expect(parseMcpOAuthClient({ ...blank, clientId: " corp-app ", scopes: "offline_access, api://x/read " })).toEqual({
clientId: "corp-app",
@@ -85,6 +85,15 @@ describe("MCP server form", () => {
expect(parseMcpOAuthClient({ ...blank, clientId: "corp-app", clientSecret: "new" }, { clientSecretConfigured: true })).toEqual({ clientId: "corp-app", clientSecret: "new" });
});
+ it("sends a typed redirect URI, and an emptied one only when the app named its own", () => {
+ const blank = { clientId: "corp-app", clientSecret: "", scopes: "", redirectUri: "", forgetSecret: false };
+ const uri = "https://maus.example/mcp-oauth/callback";
+ expect(parseMcpOAuthClient({ ...blank, redirectUri: ` ${uri} ` })).toEqual({ clientId: "corp-app", redirectUri: uri });
+ expect(parseMcpOAuthClient(blank, { clientSecretConfigured: false })).toEqual({ clientId: "corp-app" });
+ expect(parseMcpOAuthClient(blank, { clientSecretConfigured: false, redirectUriDefault: true })).toEqual({ clientId: "corp-app" });
+ expect(parseMcpOAuthClient(blank, { clientSecretConfigured: false, redirectUriDefault: false })).toEqual({ clientId: "corp-app", redirectUri: "" });
+ });
+
it("retains the offending name while an existing error changes language", () => {
setLocale("de");
const result = rowsBody([secretRow({ name: "TOKEN WITH SPACE", value: "v" })], "env");
diff --git a/src/components/mcp-draft.ts b/src/components/mcp-draft.ts
index ca29083bc3..ae9eed67f1 100644
--- a/src/components/mcp-draft.ts
+++ b/src/components/mcp-draft.ts
@@ -24,6 +24,7 @@ export interface McpOAuthClientListing {
scopes: string[];
clientSecretConfigured: boolean;
redirectUri: string;
+ redirectUriDefault?: boolean;
}
export type McpServerListing = (StdioMcpListing | RemoteMcpListing) & {
scope?: "team" | "person"; managedBy?: string; runsOn?: { environmentId: string; label: string }; apps?: boolean;
@@ -61,6 +62,7 @@ export interface McpDraft extends McpResultBudgetDraft {
oauthClientId: string;
oauthClientSecret: string;
oauthScopes: string;
+ oauthRedirectUri: string;
oauthForgetSecret: boolean;
}
@@ -73,7 +75,7 @@ export function secretRow(row: Omit<SecretRow, "id"> = { name: "", value: "" }):
export function emptyDraft(): McpDraft {
return {
name: "", transport: "remote", command: "", args: "", env: [secretRow()], type: "http", url: "", headers: [secretRow()],
- oauthClientId: "", oauthClientSecret: "", oauthScopes: "", oauthForgetSecret: false, resultBudget: "",
+ oauthClientId: "", oauthClientSecret: "", oauthScopes: "", oauthRedirectUri: "", oauthForgetSecret: false, resultBudget: "",
};
}
@@ -90,6 +92,7 @@ export function draftFor(server: McpServerListing): McpDraft {
headers: savedRows(server.headerKeys),
oauthClientId: server.oauth?.clientId ?? "",
oauthScopes: server.oauth?.scopes.join(" ") ?? "",
+ oauthRedirectUri: server.oauth && !server.oauth.redirectUriDefault ? server.oauth.redirectUri : "",
resultBudget: resultBudgetDraft(server),
};
}
@@ -158,17 +161,20 @@ export function parseMcpArguments(value: string): string[] {
}
export function parseMcpOAuthClient(
- input: { clientId: string; clientSecret: string; scopes: string; forgetSecret: boolean },
- saved?: { clientSecretConfigured: boolean },
-): { clientId: string; clientSecret?: string | true; scopes?: string[] } | undefined {
+ input: { clientId: string; clientSecret: string; scopes: string; redirectUri: string; forgetSecret: boolean },
+ saved?: { clientSecretConfigured: boolean; redirectUriDefault?: boolean },
+): { clientId: string; clientSecret?: string | true; scopes?: string[]; redirectUri?: string } | undefined {
const clientId = input.clientId.trim();
if (!clientId) return undefined;
const secret = input.clientSecret.trim();
const scopes = input.scopes.split(/[\s,]+/).filter(Boolean);
+ const redirectUri = input.redirectUri.trim();
return {
clientId,
...(secret ? { clientSecret: secret } : saved?.clientSecretConfigured && !input.forgetSecret ? { clientSecret: true as const } : {}),
...(scopes.length ? { scopes } : {}),
+ // A cleared field on an app that named a return address goes back to the default loopback one.
+ ...(redirectUri ? { redirectUri } : saved?.redirectUriDefault === false ? { redirectUri: "" } : {}),
};
}
@@ -184,7 +190,7 @@ export function draftBody(
const headers = rowsBody(draft.headers, "header");
if (!headers.ok) return headers;
const oauth = parseMcpOAuthClient(
- { clientId: draft.oauthClientId, clientSecret: draft.oauthClientSecret, scopes: draft.oauthScopes, forgetSecret: draft.oauthForgetSecret },
+ { clientId: draft.oauthClientId, clientSecret: draft.oauthClientSecret, scopes: draft.oauthScopes, redirectUri: draft.oauthRedirectUri, forgetSecret: draft.oauthForgetSecret },
existing && isRemoteMcpListing(existing) ? existing.oauth : undefined,
);
return { ok: true, body: { type: draft.type, url, headers: headers.values, ...(oauth ? { oauth } : {}) } };
diff --git a/src/locales/en.json b/src/locales/en.json
index cf38252006..0070467c7e 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -6302,6 +6302,11 @@
"mcp.oauth.secretSaved": "Saved · leave blank to keep it",
"mcp.oauth.removeSecret": "Remove saved secret",
"mcp.oauth.scopes": "Scopes · separated by spaces",
+ "mcp.oauth.redirectUri": "Redirect URI · optional",
+ "mcp.oauth.redirectHint": "Where the provider returns after sign-in. Leave blank to use this computer's default address. Only an https address ending in /mcp-oauth/callback is accepted, so use this server's public address when the browser cannot reach its loopback.",
+ "mcp.oauth.copy": "Copy",
+ "mcp.oauth.copied": "Copied",
+ "mcp.oauth.copyFailed": "Could not copy",
"mcp.oauth.saved": "Sign-in app: {clientId}",
"mcp.oauth.savedWithSecret": "Sign-in app: {clientId} · secret saved",
"mcp.claude.title": "Also use my Claude Code MCP servers",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 0dd3959498..75ee4509a3 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -5931,6 +5931,11 @@
"mcp.oauth.secretSaved": "Salvo · deixe em branco para manter",
"mcp.oauth.removeSecret": "Remover o segredo salvo",
"mcp.oauth.scopes": "Escopos · separados por espaços",
+ "mcp.oauth.redirectUri": "URI de redirecionamento · opcional",
+ "mcp.oauth.redirectHint": "Para onde o provedor retorna após o login. Deixe em branco para usar o endereço padrão deste computador. Só é aceito um endereço https terminado em /mcp-oauth/callback, então use o endereço público deste servidor quando o navegador não conseguir alcançar o loopback dele.",
+ "mcp.oauth.copy": "Copiar",
+ "mcp.oauth.copied": "Copiado",
+ "mcp.oauth.copyFailed": "Não foi possível copiar",
"mcp.oauth.saved": "App de login: {clientId}",
"mcp.oauth.savedWithSecret": "App de login: {clientId} · segredo salvo",
"mcp.claude.title": "Usar também meus servidores MCP do Claude Code",