Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(mcp): localize missing DCR recovery

vastsaa1427526710b
diff --git a/apps/desktop/electron/main/mcp-oauth.ts b/apps/desktop/electron/main/mcp-oauth.ts
index 099df47ca..68c5158eb 100644
--- a/apps/desktop/electron/main/mcp-oauth.ts
+++ b/apps/desktop/electron/main/mcp-oauth.ts
@@ -3,6 +3,7 @@ import { createServer, type Server } from "node:http";
import type { AddressInfo } from "node:net";
import {
isUserSuppliedHostname,
+ type McpOAuthLoginErrorCode,
type McpOAuthLoginEvent,
type McpServerRecord,
type McpServerStatus,
@@ -42,6 +43,18 @@ export type McpOAuthDeps = {
newId?: () => string;
};
+class McpOAuthError extends Error {
+ readonly errorCode: McpOAuthLoginErrorCode;
+
+ constructor(
+ errorCode: McpOAuthLoginErrorCode,
+ message: string,
+ ) {
+ super(message);
+ this.errorCode = errorCode;
+ }
+}
+
export function secretRefForMcpOAuth(serverId: string): string {
return `secret:mcp:${serverId}:oauth`;
}
@@ -686,8 +699,9 @@ export class McpOAuthManager {
// Fail here, before opening anything, saying what is missing.
// The message must not promise a settings field that does not
// exist yet: it names the two real ways forward.
- throw new Error(
- `MCP server "${session.serverId}" does not support Dynamic Client Registration, and PI-Desktop has no client id registered with ${metadata.authorizationEndpoint}. Ask the server operator for a client id, or use a server that supports DCR.`,
+ throw new McpOAuthError(
+ "MCP_OAUTH_DCR_UNAVAILABLE",
+ `MCP server "${session.serverId}" has no registered client id and does not support Dynamic Client Registration.`,
);
}
@@ -775,6 +789,7 @@ export class McpOAuthManager {
serverId: session.serverId,
kind: "error",
message,
+ ...(error instanceof McpOAuthError ? { errorCode: error.errorCode } : {}),
});
}
} finally {
diff --git a/apps/desktop/src/components/settings/AgentMcpPage.tsx b/apps/desktop/src/components/settings/AgentMcpPage.tsx
index 98f57b45e..45e1b909e 100644
--- a/apps/desktop/src/components/settings/AgentMcpPage.tsx
+++ b/apps/desktop/src/components/settings/AgentMcpPage.tsx
@@ -9,6 +9,7 @@ import {
import { api } from "../../lib/api";
import { useAppStore } from "../../stores/app-store";
import { useHostCollection } from "../../hooks/use-host-collection";
+import { mcpOAuthErrorTranslationKey } from "../../lib/mcp-oauth-error";
import {
AgentCapabilityPage,
AgentProjectPicker,
@@ -295,7 +296,11 @@ export function AgentMcpPage() {
});
cleanup();
} else if (event.kind === "error") {
- showToast(event.message || t("extensions.mcp.authFailed"), { variant: "error" });
+ const errorKey = mcpOAuthErrorTranslationKey(event.errorCode);
+ showToast(
+ (errorKey && t(errorKey)) || event.message || t("extensions.mcp.authFailed"),
+ { variant: "error" },
+ );
cleanup();
} else if (event.kind === "cancelled") {
cleanup();
diff --git a/apps/desktop/src/lib/mcp-oauth-error.ts b/apps/desktop/src/lib/mcp-oauth-error.ts
new file mode 100644
index 000000000..9b7622a88
--- /dev/null
+++ b/apps/desktop/src/lib/mcp-oauth-error.ts
@@ -0,0 +1,14 @@
+import type { McpOAuthLoginErrorCode } from "@pi-desktop/shared";
+
+type McpOAuthErrorTranslationKey = "extensions.mcp.authDcrUnavailable";
+
+export function mcpOAuthErrorTranslationKey(
+ errorCode: McpOAuthLoginErrorCode | undefined,
+): McpOAuthErrorTranslationKey | undefined {
+ switch (errorCode) {
+ case "MCP_OAUTH_DCR_UNAVAILABLE":
+ return "extensions.mcp.authDcrUnavailable";
+ default:
+ return undefined;
+ }
+}
diff --git a/apps/desktop/test/agent-capability-settings.test.mjs b/apps/desktop/test/agent-capability-settings.test.mjs
index a194886e3..35cc31330 100644
--- a/apps/desktop/test/agent-capability-settings.test.mjs
+++ b/apps/desktop/test/agent-capability-settings.test.mjs
@@ -470,3 +470,8 @@ test("MCP OAuth subscribe is owned by a ref cleaned up on unmount", () => {
assert.match(mcp, /api\.onMcpOAuth\(/);
assert.match(mcpIpc, /oauth\.start\(server\.id, server\.url, server\)/);
});
+
+test("MCP OAuth error events use localized recovery copy when available", () => {
+ assert.match(mcp, /mcpOAuthErrorTranslationKey\(event\.errorCode\)/);
+ assert.match(mcp, /\(errorKey && t\(errorKey\)\) \|\| event\.message/);
+});
diff --git a/apps/desktop/test/mcp-oauth-error.test.mjs b/apps/desktop/test/mcp-oauth-error.test.mjs
new file mode 100644
index 000000000..20cc3e60a
--- /dev/null
+++ b/apps/desktop/test/mcp-oauth-error.test.mjs
@@ -0,0 +1,12 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { mcpOAuthErrorTranslationKey } from "../src/lib/mcp-oauth-error.ts";
+
+test("the no-DCR OAuth error selects localized recovery guidance", () => {
+ assert.equal(
+ mcpOAuthErrorTranslationKey("MCP_OAUTH_DCR_UNAVAILABLE"),
+ "extensions.mcp.authDcrUnavailable",
+ );
+ assert.equal(mcpOAuthErrorTranslationKey(undefined), undefined);
+});
diff --git a/apps/desktop/test/mcp-oauth.test.mjs b/apps/desktop/test/mcp-oauth.test.mjs
index 2465f4ac2..9b07cc9fd 100644
--- a/apps/desktop/test/mcp-oauth.test.mjs
+++ b/apps/desktop/test/mcp-oauth.test.mjs
@@ -995,6 +995,7 @@ test("McpOAuthManager: a server without DCR fails loudly instead of opening a de
const { mockFetch } = createMockFetch({ withoutRegistration: true });
const { mockCreateServer } = createMockServerFactory();
const opened = [];
+ const events = [];
const manager = new McpOAuthManager({
call: host.call,
fetchImpl: mockFetch,
@@ -1002,7 +1003,7 @@ test("McpOAuthManager: a server without DCR fails loudly instead of opening a de
opened.push(url);
},
createServer: mockCreateServer,
- emit: () => {},
+ emit: (event) => events.push(event),
});
t.after(() => manager.disposeAll());
@@ -1013,7 +1014,8 @@ test("McpOAuthManager: a server without DCR fails loudly instead of opening a de
// forward; a bare "failed" leaves the user where the 404 did.
assert.match(error.message, /Dynamic Client Registration/);
assert.match(error.message, /client id/);
- assert.match(error.message, /https:\/\/notion\.test\/authorize/);
+ assert.equal(error.errorCode, "MCP_OAUTH_DCR_UNAVAILABLE");
+ assert.doesNotMatch(error.message, /https:\/\/notion\.test\/authorize/);
return true;
},
);
@@ -1021,4 +1023,7 @@ test("McpOAuthManager: a server without DCR fails loudly instead of opening a de
// The whole point: no browser tab, so no dead authorization page. Before
// this change the app opened `?client_id=pi-desktop` and the user saw a 404.
assert.deepEqual(opened, [], "no authorization URL may be opened without a usable client id");
+ assert.ok(events.some((event) =>
+ event.kind === "error" && event.errorCode === "MCP_OAUTH_DCR_UNAVAILABLE",
+ ));
});
diff --git a/docs/spec/03-runtime/01-ipc-protocol.md b/docs/spec/03-runtime/01-ipc-protocol.md
index bfb555136..8eea0bc40 100644
--- a/docs/spec/03-runtime/01-ipc-protocol.md
+++ b/docs/spec/03-runtime/01-ipc-protocol.md
@@ -1759,11 +1759,13 @@ type McpOAuthLoginEvent = {
| { kind: "authUrl"; url: string; instructions?: string; opened: boolean }
| { kind: "progress"; message: string }
| { kind: "done"; status: McpServerStatus }
- | { kind: "error"; message: string }
+ | { kind: "error"; message: string; errorCode?: "MCP_OAUTH_DCR_UNAVAILABLE" }
| { kind: "cancelled" }
);
```
+When authorization-server metadata has no `registration_endpoint` and no reusable client is available, login fails before opening the external browser. The error event carries `MCP_OAUTH_DCR_UNAVAILABLE`; the renderer shows localized recovery guidance. The main-process message remains diagnostic and must not include discovered authorization endpoint URLs.
+
#### Status and Token Storage
- `McpServerStatus` includes:
- `hasOauth: boolean` — whether the server has an encrypted OAuth secret stored in host-core (`secret:mcp:<serverId>:oauth`).
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index e351bd066..ced0b4975 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -8512,6 +8512,7 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.
6. Settings UI updates status to `Ready` with discovered tools, shows localized success toast, and displays `OAuth` badge.
7. When access token expires, `UserMcpRuntime` transparently uses refresh token to obtain a fresh access token without user prompt.
8. Moving the server via `mcp.transfer` preserves and re-keys the OAuth token secret under the destination ID.
+- **No-DCR case**: When authorization-server metadata omits `registration_endpoint` and there is no reusable client, Authorize does not open a browser. The error event contains `MCP_OAUTH_DCR_UNAVAILABLE` and Settings shows localized recovery guidance to request a client ID from the server operator or use a DCR-capable server.
- **Specs linked**: `03-runtime/01-ipc-protocol.md`, ADR 0283, ADR 0142
- **Acceptance**: E (tools & permissions), Security
- **Milestone**: M5
diff --git a/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md b/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
index 09c5c014f..a2bf727ed 100644
--- a/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
+++ b/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
@@ -1321,11 +1321,13 @@ type McpOAuthLoginEvent = {
| { kind: "authUrl"; url: string; instructions?: string; opened: boolean }
| { kind: "progress"; message: string }
| { kind: "done"; status: McpServerStatus }
- | { kind: "error"; message: string }
+ | { kind: "error"; message: string; errorCode?: "MCP_OAUTH_DCR_UNAVAILABLE" }
| { kind: "cancelled" }
);
```
+如果授权服务器元数据没有 `registration_endpoint`,且没有可复用的客户端,登录会在打开外部浏览器前失败。错误事件携带 `MCP_OAUTH_DCR_UNAVAILABLE`,渲染层显示本地化的恢复指引。主进程错误消息用于诊断,不应包含发现到的授权端点 URL。
+
#### 状态与凭证存储
- `McpServerStatus` 包含:
- `hasOauth: boolean` — 服务是否在 host-core 加密凭据库存储有 OAuth 凭据(`secret:mcp:<serverId>:oauth`)。
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index e81de2283..d6b118154 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -5146,6 +5146,7 @@ eleven-tool-round desktop paths are verified by
6. 设置界面状态更新为已连接及工具数量,弹出成功提示,并显示 OAuth 徽标。
7. 访问令牌过期时,`UserMcpRuntime` 透明使用 refresh token 换取新令牌,无需用户重新交互。
8. 通过 `mcp.transfer` 迁移服务器时,自动将 OAuth 令牌迁移至新 ID 下。
+- **无 DCR 的情况**:如果授权服务器元数据缺少 `registration_endpoint`,且没有可复用的客户端,点击“授权”不会打开浏览器。错误事件包含 `MCP_OAUTH_DCR_UNAVAILABLE`,设置页会显示本地化恢复指引,建议向服务器运营方索取客户端 ID,或改用支持 DCR 的服务器。
- **链接规格**:`03-runtime/01-ipc-protocol.md`、ADR 0283、ADR 0142
- **验收**:E(工具和权限)、安全性
- **里程碑**:M5
diff --git a/packages/i18n/src/locales/de/index.ts b/packages/i18n/src/locales/de/index.ts
index 2a4354cfd..9345e590c 100644
--- a/packages/i18n/src/locales/de/index.ts
+++ b/packages/i18n/src/locales/de/index.ts
@@ -2522,6 +2522,7 @@ sklm: {
"authReady_one": "Autorisiert · 1 Tool",
"authReady_other": "Autorisiert · {{count}} Tools",
"authFailed": "Autorisierung fehlgeschlagen",
+ "authDcrUnavailable": "Dieser MCP-Server unterstützt keine dynamische Clientregistrierung. Bitte frage den Serverbetreiber nach einer Client-ID oder verwende einen Server mit DCR-Unterstützung.",
"oauthBadge": "OAuth",
"transport": "Wie wird eine Verbindung hergestellt",
"transportStdio": "Lokales Programm",
diff --git a/packages/i18n/src/locales/en/index.ts b/packages/i18n/src/locales/en/index.ts
index a82506d83..405e9ea7c 100644
--- a/packages/i18n/src/locales/en/index.ts
+++ b/packages/i18n/src/locales/en/index.ts
@@ -2565,6 +2565,8 @@ importConfirm: "Imported extensions run inside the agent process with the same a
authReady_one: "Authorized · 1 tool",
authReady_other: "Authorized · {{count}} tools",
authFailed: "Authorization failed",
+ authDcrUnavailable:
+ "This MCP server does not support Dynamic Client Registration. Ask the server operator for a client ID, or use a server that supports DCR.",
oauthBadge: "OAuth",
transport: "How it connects",
transportStdio: "Local program",
diff --git a/packages/i18n/src/locales/es/index.ts b/packages/i18n/src/locales/es/index.ts
index a235bc818..a035c89eb 100644
--- a/packages/i18n/src/locales/es/index.ts
+++ b/packages/i18n/src/locales/es/index.ts
@@ -2522,6 +2522,7 @@ sklm: {
"authReady_one": "Autorizado · 1 herramienta",
"authReady_other": "Autorizado · {{count}} herramientas",
"authFailed": "Error de autorización",
+ "authDcrUnavailable": "Este servidor MCP no admite el registro dinámico de clientes. Pide al operador del servidor un ID de cliente o usa un servidor compatible con DCR.",
"oauthBadge": "OAuth",
"transport": "Cómo se conecta",
"transportStdio": "Programa local",
diff --git a/packages/i18n/src/locales/fr/index.ts b/packages/i18n/src/locales/fr/index.ts
index ed45c0db0..8e868e16d 100644
--- a/packages/i18n/src/locales/fr/index.ts
+++ b/packages/i18n/src/locales/fr/index.ts
@@ -2522,6 +2522,7 @@ sklm: {
"authReady_one": "Autorisé · 1 outil",
"authReady_other": "Autorisé · {{count}} outils",
"authFailed": "Échec de l'autorisation",
+ "authDcrUnavailable": "Ce serveur MCP ne prend pas en charge l’inscription dynamique des clients. Demandez à l’opérateur du serveur un identifiant client ou utilisez un serveur compatible avec DCR.",
"oauthBadge": "OAuth",
"transport": "Comment il se connecte",
"transportStdio": "Programme local",
diff --git a/packages/i18n/src/locales/ko/index.ts b/packages/i18n/src/locales/ko/index.ts
index fbfe5c79c..29135c06c 100644
--- a/packages/i18n/src/locales/ko/index.ts
+++ b/packages/i18n/src/locales/ko/index.ts
@@ -2557,6 +2557,8 @@ importConfirm: "가져온 확장은 에이전트 프로세스 안에서 에이
authReady_one: "인증됨 · 도구 1개",
authReady_other: "인증됨 · 도구 {{count}}개",
authFailed: "인증 실패",
+ authDcrUnavailable:
+ "이 MCP 서버는 동적 클라이언트 등록을 지원하지 않습니다. 서버 운영자에게 클라이언트 ID를 요청하거나 DCR을 지원하는 서버를 사용하세요.",
oauthBadge: "OAuth",
transport: "연결 방식",
transportStdio: "로컬 프로그램",
diff --git a/packages/i18n/src/locales/pt-BR/index.ts b/packages/i18n/src/locales/pt-BR/index.ts
index eacfa53f9..9035d3609 100644
--- a/packages/i18n/src/locales/pt-BR/index.ts
+++ b/packages/i18n/src/locales/pt-BR/index.ts
@@ -2486,6 +2486,7 @@ export const ptBR = {
authReady_one: "Autorizado · 1 ferramenta",
authReady_other: "Autorizado · {{count}} ferramentas",
authFailed: "Falha na autorização",
+ authDcrUnavailable: "Este servidor MCP não oferece suporte ao registro dinâmico de clientes. Peça ao operador do servidor um ID de cliente ou use um servidor compatível com DCR.",
oauthBadge: "OAuth",
transport: "Como se conecta",
transportStdio: "Programa local",
diff --git a/packages/i18n/src/locales/tr/index.ts b/packages/i18n/src/locales/tr/index.ts
index 26b8f4015..d64f99d0a 100644
--- a/packages/i18n/src/locales/tr/index.ts
+++ b/packages/i18n/src/locales/tr/index.ts
@@ -2551,6 +2551,7 @@ importConfirm: "İçe aktarılan uzantılar ajan sürecinde, ajanın kendi araç
authReady_one: "Yetkilendirildi · 1 araç",
authReady_other: "Yetkilendirildi · {{count}} araç",
authFailed: "Yetkilendirme başarısız",
+ authDcrUnavailable: "Bu MCP sunucusu Dinamik İstemci Kaydı'nı desteklemiyor. Sunucu operatöründen bir istemci kimliği isteyin veya DCR destekleyen bir sunucu kullanın.",
oauthBadge: "OAuth",
transport: "Nasıl bağlanır",
transportStdio: "Yerel program",
diff --git a/packages/i18n/src/locales/zh-CN/index.ts b/packages/i18n/src/locales/zh-CN/index.ts
index c1c7cc373..f2552173e 100644
--- a/packages/i18n/src/locales/zh-CN/index.ts
+++ b/packages/i18n/src/locales/zh-CN/index.ts
@@ -2519,6 +2519,7 @@ sklm: {
authReady_one: "已授权 · 1 个工具",
authReady_other: "已授权 · {{count}} 个工具",
authFailed: "授权失败",
+ authDcrUnavailable: "此 MCP 服务器不支持动态客户端注册。请向服务器运营方索取客户端 ID,或改用支持 DCR 的服务器。",
oauthBadge: "OAuth",
transport: "连接方式",
transportStdio: "本地程序",
diff --git a/packages/i18n/src/locales/zh-TW/index.ts b/packages/i18n/src/locales/zh-TW/index.ts
index 434bfa416..6c5f1f13a 100644
--- a/packages/i18n/src/locales/zh-TW/index.ts
+++ b/packages/i18n/src/locales/zh-TW/index.ts
@@ -2518,6 +2518,7 @@ sklm: {
authReady_one: "已授權 · 1 個工具",
authReady_other: "已授權 · {{count}} 個工具",
authFailed: "授權失敗",
+ authDcrUnavailable: "此 MCP 伺服器不支援動態用戶端註冊。請向伺服器管理員索取用戶端 ID,或改用支援 DCR 的伺服器。",
oauthBadge: "OAuth",
transport: "連線方式",
transportStdio: "本地程式",
diff --git a/packages/i18n/test/catalogs.test.mjs b/packages/i18n/test/catalogs.test.mjs
index 85b25c021..50048b556 100644
--- a/packages/i18n/test/catalogs.test.mjs
+++ b/packages/i18n/test/catalogs.test.mjs
@@ -75,6 +75,16 @@ test("Live Voice preparation and call recovery copy is localized in every shippe
assert.match(english["liveVoice.enableDetail"], /switch sessions by voice/);
});
+test("MCP OAuth no-DCR recovery guidance is localized in every shipped catalog", () => {
+ const key = "extensions.mcp.authDcrUnavailable";
+ for (const [id, catalog] of Object.entries(catalogs)) {
+ const value = flattenCatalog(catalog)[key];
+ assert.equal(typeof value, "string", `${id} ${key}`);
+ assert.notEqual(value.trim(), "", `${id} ${key}`);
+ if (id !== "en") assert.notEqual(value, english[key], `${id} ${key} must not fall back to English`);
+ }
+});
+
test("canonical thinking levels are not translated catalog entries", () => {
const levels = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
const effortKeys = [
diff --git a/packages/shared/src/types/capabilities.ts b/packages/shared/src/types/capabilities.ts
index 402f50fbd..20d3c300a 100644
--- a/packages/shared/src/types/capabilities.ts
+++ b/packages/shared/src/types/capabilities.ts
@@ -110,6 +110,8 @@ export type McpServerView = McpServerRecord & {
};
/** Progress of one MCP OAuth login attempt, pushed to the renderer. */
+export type McpOAuthLoginErrorCode = "MCP_OAUTH_DCR_UNAVAILABLE";
+
export type McpOAuthLoginEvent = {
loginId: string;
serverId: string;
@@ -117,7 +119,7 @@ export type McpOAuthLoginEvent = {
| { kind: "authUrl"; url: string; instructions?: string; opened: boolean }
| { kind: "progress"; message: string }
| { kind: "done"; status: McpServerStatus }
- | { kind: "error"; message: string }
+ | { kind: "error"; message: string; errorCode?: McpOAuthLoginErrorCode }
| { kind: "cancelled" }
);