From 81fba1dd5301f3380bb490732de2c176ea010f9b Mon Sep 17 00:00:00 2001 From: Erik Costlow Date: Thu, 19 Nov 2026 10:20:54 -0500 Subject: [PATCH] MCP sign-in: a refused client registration names its fix, and an ask card's failed start lands on Integrations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a service's registration endpoint refuses the dynamic client registration - the real case is Harness's Keycloak answering 403 insufficient_scope from its "DCR Trusted hosts" policy - the sign-in route already says registration_refused, but no UI message existed for that code, so the member saw the bare "The sign-in failed. Try again." and retrying could never help. signInErrorText now has its own message for it, in all four catalogs, pointing to the client ID from the service's documentation, in the server's settings on Integrations → MCP. The secret-request card's OAuth save started the sign-in with the failure swallowed, and the save closes the ask, so a refused start left the member with nothing at all - no page ever opened. A refused start now sends the browser to /integrations?mcpSignIn=, where the callback would have gone, with the usual note of whose server it was, so the server's row shows the reason and offers the sign-in again. The registration stub can answer a refusal with another status than 400 (dcrStatus), so the tests cover the 403 case end to end. --- server/mcp-oauth.test.ts | 16 ++++++++++++ server/test-support/mcp-oauth-stub.ts | 5 +++- shared/i18n/ca.ts | 2 ++ shared/i18n/en.ts | 2 ++ shared/i18n/es.ts | 2 ++ shared/i18n/zh.ts | 2 ++ ui/integrations/McpSection.dom.test.tsx | 34 +++++++++++++++++++++++++ ui/integrations/McpSection.tsx | 2 ++ ui/integrations/sign-in-return.ts | 23 ++++++++++++++++- ui/log-view/SecretAskCard.dom.test.tsx | 34 +++++++++++++++++++++++++ ui/log-view/SecretAskCard.tsx | 14 +++++++--- 11 files changed, 130 insertions(+), 6 deletions(-) diff --git a/server/mcp-oauth.test.ts b/server/mcp-oauth.test.ts index 9dbed08d6..945d56a32 100644 --- a/server/mcp-oauth.test.ts +++ b/server/mcp-oauth.test.ts @@ -229,6 +229,22 @@ describe("the sign-in", () => { }); }); + it("names a registration the authorization server refuses with any other answer", async () => { + // The real case (Harness's Keycloak): a 403 whose policy rejects the + // registration, which the member must answer with a pasted client ID. + const context = setup({ dcrError: "insufficient_scope", dcrStatus: 403 }); + register(context.oauth); + expect(await context.oauth.startSignIn(member, "mail", "u1")).toEqual({ + ok: false, + reason: "registration_refused", + }); + // Nothing of a client is stored: the sign-in left the server as it was. + expect(context.sources.servers.list(member)[0].oauth).toEqual({ + clientId: null, + signedIn: false, + }); + }); + it("refuses metadata whose resource is not the registered URL", async () => { const context = setup({ resource: "https://other.example.test/mcp" }); register(context.oauth); diff --git a/server/test-support/mcp-oauth-stub.ts b/server/test-support/mcp-oauth-stub.ts index 172d7e92c..89363eb68 100644 --- a/server/test-support/mcp-oauth-stub.ts +++ b/server/test-support/mcp-oauth-stub.ts @@ -16,6 +16,8 @@ export interface StubOptions { tokenEndpoint?: string; registration?: boolean; dcrError?: string; + // The status the registration refusal answers with (400 by default). + dcrStatus?: number; } export function stubRig(options: StubOptions = {}) { @@ -105,7 +107,8 @@ export function stubRig(options: StubOptions = {}) { if (url === `${ISSUER}/register`) { const body = JSON.parse(typeof init.body === "string" ? init.body : ""); rig.registeredRedirects.push(...body.redirect_uris); - if (options.dcrError) return json({ error: options.dcrError }, 400); + if (options.dcrError) + return json({ error: options.dcrError }, options.dcrStatus ?? 400); return json({ client_id: "client-dcr-1" }, 201); } if (url === `${ISSUER}/token`) { diff --git a/shared/i18n/ca.ts b/shared/i18n/ca.ts index fdfec93ef..9ed0e5299 100644 --- a/shared/i18n/ca.ts +++ b/shared/i18n/ca.ts @@ -1328,6 +1328,8 @@ Coses que pots fer per ell: "No s'ha pogut iniciar la sessió. Torna-ho a provar.", "settings.mcpServers.signInError.clientNeeded": "Aquest servidor no registra clients. Introdueix un ID de client.", + "settings.mcpServers.signInError.registrationRefused": + "El servei ha rebutjat registrar un client automàticament. Introdueix l'ID de client de la documentació del servei a la configuració del servidor, a Integracions → MCP.", "settings.mcpServers.signInError.redirectRefused": "El servidor d'autorització ha rebutjat l'adreça d'aquesta oficina. Alguns servidors només accepten adreces https o localhost.", "settings.mcpServers.signInError.metadata": diff --git a/shared/i18n/en.ts b/shared/i18n/en.ts index 578c4692a..9b5159749 100644 --- a/shared/i18n/en.ts +++ b/shared/i18n/en.ts @@ -1304,6 +1304,8 @@ Never ask for or repeat secrets (API keys, tokens, passwords). Point people to t "settings.mcpServers.signInFailed": "The sign-in failed. Try again.", "settings.mcpServers.signInError.clientNeeded": "This server does not register clients. Enter a client ID.", + "settings.mcpServers.signInError.registrationRefused": + "The service refused to register a client automatically. Enter the client ID from the service's documentation in the server's settings, in Integrations → MCP.", "settings.mcpServers.signInError.redirectRefused": "The authorization server refused this office's address. Some servers accept only https or localhost addresses.", "settings.mcpServers.signInError.metadata": diff --git a/shared/i18n/es.ts b/shared/i18n/es.ts index c611a53dd..a6319bdcb 100644 --- a/shared/i18n/es.ts +++ b/shared/i18n/es.ts @@ -1332,6 +1332,8 @@ Cosas que puedes hacer por él: "No se pudo iniciar sesión. Inténtalo de nuevo.", "settings.mcpServers.signInError.clientNeeded": "Este servidor no registra clientes. Introduce un ID de cliente.", + "settings.mcpServers.signInError.registrationRefused": + "El servicio rechazó registrar un cliente automáticamente. Introduce el ID de cliente de la documentación del servicio en los ajustes del servidor, en Integraciones → MCP.", "settings.mcpServers.signInError.redirectRefused": "El servidor de autorización rechazó la dirección de esta oficina. Algunos servidores solo aceptan direcciones https o localhost.", "settings.mcpServers.signInError.metadata": diff --git a/shared/i18n/zh.ts b/shared/i18n/zh.ts index 09c1a9365..444b3126b 100644 --- a/shared/i18n/zh.ts +++ b/shared/i18n/zh.ts @@ -1183,6 +1183,8 @@ export const zh: Catalog = { "settings.mcpServers.signInFailed": "登录失败。请重试。", "settings.mcpServers.signInError.clientNeeded": "此服务器不注册客户端。请输入客户端 ID。", + "settings.mcpServers.signInError.registrationRefused": + "此服务拒绝了自动注册客户端。请在“集成 → MCP”中该服务器的设置里输入服务文档提供的客户端 ID。", "settings.mcpServers.signInError.redirectRefused": "授权服务器拒绝了此办公室的地址。有些服务器只接受 https 或 localhost 地址。", "settings.mcpServers.signInError.metadata": diff --git a/ui/integrations/McpSection.dom.test.tsx b/ui/integrations/McpSection.dom.test.tsx index 503136438..3655992fd 100644 --- a/ui/integrations/McpSection.dom.test.tsx +++ b/ui/integrations/McpSection.dom.test.tsx @@ -244,6 +244,40 @@ it("explains a refused sign-in redirect by its code", async () => { ); }); +// A service that refuses the automatic client registration (a 403 from its +// registration endpoint) gets its own message, not the bare failure - it +// tells the member to paste the client ID the service's docs name. The +// notice of a code that came back to the page says the same. +it("explains a registration the service refused, in the form and in the returned notice", async () => { + setApiShim(async (method, path) => { + if (path === "/api/me/connections") return EMPTY_CONNECTIONS; + if (path.endsWith("/secrets")) return { secrets: [] }; + if (method === "GET") + return { + servers: [ + server("mail", { oauth: { clientId: "c1", signedIn: true } }), + ], + }; + throw new ApiError(502, "sign_in_failed", "x", { + reason: "registration_refused", + }); + }); + const view = await mount(); + await click(view.container.querySelector("[data-mcp-edit]")); + await click(view.container.querySelector("[data-mcp-sign-in-again]")); + const text = t("settings.mcpServers.signInError.registrationRefused"); + expect(view.getByRole("alert").textContent).toBe(text); + expect(text).not.toBe(t("settings.mcpServers.signInFailed")); + view.unmount(); + const notice = render( + createElement(SignInNotice, { + code: "registration_refused", + server: "mail", + }), + ); + expect(notice.getByRole("alert").textContent).toBe(text); +}); + // AGENTS.md "UI rules" (task ea76bd44): the secret a sign-in would make, // named in its refusal, is Data. it("names the secret in the way of a sign-in as data", async () => { diff --git a/ui/integrations/McpSection.tsx b/ui/integrations/McpSection.tsx index 61d4a68ff..812a5820d 100644 --- a/ui/integrations/McpSection.tsx +++ b/ui/integrations/McpSection.tsx @@ -163,6 +163,8 @@ export function signInErrorText( switch (reason) { case "client_needed": return t("settings.mcpServers.signInError.clientNeeded"); + case "registration_refused": + return t("settings.mcpServers.signInError.registrationRefused"); case "redirect_refused": return t("settings.mcpServers.signInError.redirectRefused"); case "discovery_failed": diff --git a/ui/integrations/sign-in-return.ts b/ui/integrations/sign-in-return.ts index 56431c004..9d9dfa147 100644 --- a/ui/integrations/sign-in-return.ts +++ b/ui/integrations/sign-in-return.ts @@ -6,7 +6,7 @@ // sessionStorage, is read once, and goes stale after 15 minutes. import type { McpServerSignInRes } from "../../shared/contract-shapes.ts"; -import { apiFetch } from "../api.ts"; +import { apiFetch, ApiError } from "../api.ts"; import { basePath, type Target } from "./target.ts"; const KEY = "isomux:mcpSignIn"; @@ -69,3 +69,24 @@ export async function startMcpSignIn( if (!askId) rememberSignIn({ server, target }); window.location.assign(authorizationUrl); } + +// A sign-in the office refused to start, for a caller whose card the save +// already closed (an ask card): there is no card left to show the reason on, +// so the browser goes where the callback would have gone. The Integrations +// page shows the reason on the server's row, which offers the sign-in again. +// The code is the office's own fixed reason, never the authorization +// server's text. +export function failMcpSignIn( + target: Target, + server: string, + caught: unknown, +): void { + const reason = + caught instanceof ApiError && typeof caught.detail?.reason === "string" + ? caught.detail.reason + : "unexpected"; + rememberSignIn({ server, target }); + window.location.assign( + `/integrations?mcpSignIn=${encodeURIComponent(reason)}`, + ); +} diff --git a/ui/log-view/SecretAskCard.dom.test.tsx b/ui/log-view/SecretAskCard.dom.test.tsx index bdfaae870..c8f803ab6 100644 --- a/ui/log-view/SecretAskCard.dom.test.tsx +++ b/ui/log-view/SecretAskCard.dom.test.tsx @@ -565,6 +565,40 @@ it("an office OAuth request signs in to the office server", async () => { } }); +// A sign-in the office refuses to start (a service that refuses the +// automatic client registration): the save closed the ask, so no card is +// left to say why. The browser goes to the Integrations page with the +// reason instead, where the server's row shows it and offers the sign-in. +it("a refused sign-in start sends the browser to the Integrations page with the reason", async () => { + answer = async (path) => { + if (path.endsWith("/sign-in")) + throw new ApiError(502, "sign_in_failed", "refused", { + reason: "registration_refused", + }); + return { name: "docs" }; + }; + const assign = spyOn(window.location, "assign").mockImplementation(() => {}); + try { + const view = await mount(false, OAUTH_ASK("personal")); + await act(async () => { + fireEvent.click(saveAndSignIn(view)); + }); + await waitFor(() => + expect(assign).toHaveBeenCalledWith( + "/integrations?mcpSignIn=registration_refused", + ), + ); + // The note names the server and its owner, as after a started sign-in. + expect(takeSignIn()).toEqual({ + server: "docs", + target: { kind: "self", username: "alice" }, + }); + view.unmount(); + } finally { + assign.mockRestore(); + } +}); + it("the request's OAuth is only the starting choice: with None the save makes a plain server and no sign-in starts", async () => { signInAnswers(); const assign = spyOn(window.location, "assign").mockImplementation(() => {}); diff --git a/ui/log-view/SecretAskCard.tsx b/ui/log-view/SecretAskCard.tsx index 0da9adfff..5492c5a02 100644 --- a/ui/log-view/SecretAskCard.tsx +++ b/ui/log-view/SecretAskCard.tsx @@ -34,7 +34,10 @@ import { } from "../integrations/DiscordSection.tsx"; import { DISCORD_BOTS_MAX } from "../../shared/discord.ts"; import { Choice } from "../integrations/kit.tsx"; -import { startMcpSignIn } from "../integrations/sign-in-return.ts"; +import { + startMcpSignIn, + failMcpSignIn, +} from "../integrations/sign-in-return.ts"; import type { Target } from "../integrations/target.ts"; import { timeSince } from "../../shared/i18n/time.ts"; import { @@ -250,10 +253,13 @@ export function SecretAskCard({ setValue(""); dispatch({ type: "ask_removed", id: entry.id }); // The save closed the ask, so the card can be gone by now: nothing - // here waits on it. A sign-in that does not start leaves the server - // signed out, and its Integrations row offers the sign-in. + // here waits on it. A sign-in that does not start sends the browser + // to the Integrations page with the reason, where the server's row + // shows it and offers the sign-in again. if (kind === "save" && isMcp && auth === "oauth" && target) - startMcpSignIn(target, secret.name).catch(() => {}); + startMcpSignIn(target, secret.name).catch((caught) => { + failMcpSignIn(target, secret.name, caught); + }); } catch (caught) { // 404: the request closed elsewhere (another owner, the agent's // withdraw); the push removes it too.