Skip to content

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

fix(mcp): fail loudly when a server has no DCR endpoint

muzimu21799bd282a4191
diff --git a/apps/desktop/electron/main/mcp-oauth.ts b/apps/desktop/electron/main/mcp-oauth.ts
index 4b702213c..099df47ca 100644
--- a/apps/desktop/electron/main/mcp-oauth.ts
+++ b/apps/desktop/electron/main/mcp-oauth.ts
@@ -677,7 +677,18 @@ export class McpOAuthManager {
clientSecret = registered.clientSecret;
redirectUrisToStore = registered.redirectUris;
} else {
- clientId = "pi-desktop";
+ // #1782: no Dynamic Client Registration endpoint means this
+ // server expects a pre-registered client id, and the app has
+ // none to give. The previous fallback opened the authorize URL
+ // with a literal `client_id=pi-desktop`, which no authorization
+ // server ever registered — the browser landed on a bare 404 and
+ // the user was left with no way forward and no explanation.
+ // 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.`,
+ );
}
const authUrl = new URL(metadata.authorizationEndpoint);
diff --git a/apps/desktop/test/mcp-oauth.test.mjs b/apps/desktop/test/mcp-oauth.test.mjs
index a7446670b..2465f4ac2 100644
--- a/apps/desktop/test/mcp-oauth.test.mjs
+++ b/apps/desktop/test/mcp-oauth.test.mjs
@@ -90,11 +90,16 @@ function createMockFetch(options = {}) {
}
if (url.pathname === "/.well-known/oauth-authorization-server") {
+ // A server that expects a pre-registered client advertises no
+ // registration endpoint (#1782).
+ const registration = options.withoutRegistration
+ ? {}
+ : { registration_endpoint: "https://notion.test/register" };
return new Response(JSON.stringify({
issuer: "https://notion.test",
authorization_endpoint: "https://notion.test/authorize",
token_endpoint: "https://notion.test/token",
- registration_endpoint: "https://notion.test/register",
+ ...registration,
code_challenge_methods_supported: ["S256"],
response_types_supported: ["code"],
}), {
@@ -984,3 +989,36 @@ test("McpOAuthManager: onAuthorized receives the server record", async (t) => {
assert.equal(authorized.serverId, record.id);
assert.equal(authorized.record, record);
});
+
+test("McpOAuthManager: a server without DCR fails loudly instead of opening a dead client_id (#1782)", async (t) => {
+ const host = fakeHost();
+ const { mockFetch } = createMockFetch({ withoutRegistration: true });
+ const { mockCreateServer } = createMockServerFactory();
+ const opened = [];
+ const manager = new McpOAuthManager({
+ call: host.call,
+ fetchImpl: mockFetch,
+ openExternal: async (url) => {
+ opened.push(url);
+ },
+ createServer: mockCreateServer,
+ emit: () => {},
+ });
+ t.after(() => manager.disposeAll());
+
+ await assert.rejects(
+ () => manager.startLogin("no-dcr-test", "https://notion.test/mcp"),
+ (error) => {
+ // The message has to name the missing capability and both real ways
+ // 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/);
+ return true;
+ },
+ );
+
+ // 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");
+});