Skip to content

🙌 OpenHands: AI-Driven Development

fix(mcp): say the sign-in was not completed when an OAuth install pop-up is abandoned

Alona09bf92394878
diff --git a/__tests__/utils/mcp-test-error-message.test.ts b/__tests__/utils/mcp-test-error-message.test.ts
index e5d63e9c33..f5dd928970 100644
--- a/__tests__/utils/mcp-test-error-message.test.ts
+++ b/__tests__/utils/mcp-test-error-message.test.ts
@@ -49,6 +49,20 @@ describe("makeMcpTestErrorMessage", () => {
},
);
+ it("tells the user to finish the sign-in when an OAuth authorization was not completed", () => {
+ const message = makeMcpTestErrorMessage(
+ t,
+ "authorization",
+ "OAuth authorization was not completed",
+ "shttp",
+ );
+
+ expect(message).toBe(
+ "Sign-in was not completed. Finish signing in from the pop-up window, then try again.",
+ );
+ expect(message).not.toContain("URL");
+ });
+
it("leaves timeout and credentials failures unchanged for stdio servers", () => {
expect(makeMcpTestErrorMessage(t, "timeout", "late", "stdio")).toBe(
"Connection timed out. Check the URL and try again.",
diff --git a/src/api/mcp-service/mcp-service.api.test.ts b/src/api/mcp-service/mcp-service.api.test.ts
index 0eddfc4888..c3b5689fcd 100644
--- a/src/api/mcp-service/mcp-service.api.test.ts
+++ b/src/api/mcp-service/mcp-service.api.test.ts
@@ -983,12 +983,88 @@ describe("McpService.testServer", () => {
expect(result).toEqual({
ok: false,
- error: "OAuth authorization timed out",
- error_kind: "timeout",
+ error: "OAuth authorization was not completed",
+ error_kind: "authorization",
});
expect(getOAuthStatus).toHaveBeenCalledTimes(141);
expect(close).toHaveBeenCalledOnce();
});
+
+ it("reports a plain timeout when no sign-in pop-up was ever shown", async () => {
+ vi.useFakeTimers();
+ vi.spyOn(window, "open").mockReturnValue(null);
+ // No authorization URL: the app server probes the stored tokens itself.
+ startOAuth.mockResolvedValueOnce({ ok: true, job_id: "job-1" });
+ getOAuthStatus.mockResolvedValue({
+ ok: true,
+ status: "pending",
+ job_id: "job-1",
+ callback_ready: false,
+ });
+
+ const authorization = McpService.authorizeOAuth(oauthServer());
+ await vi.runAllTimersAsync();
+
+ await expect(authorization).resolves.toEqual({
+ ok: false,
+ error: "OAuth authorization timed out",
+ error_kind: "timeout",
+ });
+ });
+
+ it("treats the backend probe giving up after the sign-in started as an incomplete sign-in", async () => {
+ vi.useFakeTimers();
+ vi.spyOn(window, "open").mockReturnValue(null);
+ getOAuthStatus
+ .mockResolvedValueOnce({
+ ok: true,
+ status: "authorizing",
+ job_id: "job-1",
+ authorization_url: "https://auth.example/authorize",
+ callback_ready: true,
+ })
+ .mockResolvedValueOnce({
+ ok: false,
+ status: "failed",
+ job_id: "job-1",
+ authorization_url: "https://auth.example/authorize",
+ callback_ready: true,
+ error: "MCP tool listing timed out after 120.0 seconds.",
+ error_kind: "timeout",
+ });
+
+ const authorization = McpService.authorizeOAuth(oauthServer());
+ await vi.runAllTimersAsync();
+
+ await expect(authorization).resolves.toEqual({
+ ok: false,
+ error: "MCP tool listing timed out after 120.0 seconds.",
+ error_kind: "authorization",
+ });
+ });
+
+ it("keeps a backend timeout before any sign-in started as a timeout", async () => {
+ vi.useFakeTimers();
+ vi.spyOn(window, "open").mockReturnValue(null);
+ startOAuth.mockResolvedValueOnce({ ok: true, job_id: "job-1" });
+ getOAuthStatus.mockResolvedValueOnce({
+ ok: false,
+ status: "failed",
+ job_id: "job-1",
+ callback_ready: false,
+ error: "MCP tool listing timed out after 120.0 seconds.",
+ error_kind: "timeout",
+ });
+
+ const authorization = McpService.authorizeOAuth(oauthServer());
+ await vi.runAllTimersAsync();
+
+ await expect(authorization).resolves.toEqual({
+ ok: false,
+ error: "MCP tool listing timed out after 120.0 seconds.",
+ error_kind: "timeout",
+ });
+ });
});
describe("McpService.authorizeOAuth on cloud backends", () => {
diff --git a/src/api/mcp-service/mcp-service.api.ts b/src/api/mcp-service/mcp-service.api.ts
index 697cc7dafa..b8de9b1561 100644
--- a/src/api/mcp-service/mcp-service.api.ts
+++ b/src/api/mcp-service/mcp-service.api.ts
@@ -183,6 +183,16 @@ function oauthStatusToTestResponse(
}),
};
}
+ // The backend's probe gives up after its own budget. When it had already
+ // handed out an authorization URL, that budget ran out waiting for the
+ // person to finish the sign-in, not for the server.
+ if (status.error_kind === "timeout" && status.authorization_url) {
+ return {
+ ok: false,
+ error: status.error || "OAuth authorization was not completed",
+ error_kind: "authorization",
+ };
+ }
return {
ok: false,
error: status.error || "OAuth authorization did not complete",
@@ -362,6 +372,16 @@ class McpService {
}
}
+ // With a pop-up, nothing on the server timed out: the person did not
+ // finish the sign-in. Without one, the app server was still probing the
+ // stored tokens, which is a plain timeout.
+ if (start.authorization_url) {
+ return {
+ ok: false,
+ error: "OAuth authorization was not completed",
+ error_kind: "authorization",
+ };
+ }
return {
ok: false,
error: "OAuth authorization timed out",
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 9f5f289d5e..c6c6d1e615 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -18989,6 +18989,24 @@
"uk": "Час очікування з'єднання вичерпано. Перевірте URL-адресу та спробуйте ще раз.",
"id": "Koneksi kehabisan waktu. Periksa URL dan coba lagi."
},
+ "MCP$TEST_ERROR_AUTHORIZATION": {
+ "en": "Sign-in was not completed. Finish signing in from the pop-up window, then try again.",
+ "ja": "サインインが完了しませんでした。ポップアップウィンドウでサインインを完了してから、もう一度お試しください。",
+ "zh-CN": "登录未完成。请在弹出窗口中完成登录,然后重试。",
+ "zh-TW": "登入未完成。請在彈出視窗中完成登入,然後再試一次。",
+ "ko-KR": "로그인이 완료되지 않았습니다. 팝업 창에서 로그인을 완료한 후 다시 시도하세요.",
+ "no": "Innloggingen ble ikke fullført. Fullfør innloggingen i popup-vinduet og prøv igjen.",
+ "ar": "لم يتم إكمال تسجيل الدخول. أكمل تسجيل الدخول من النافذة المنبثقة ثم حاول مرة أخرى.",
+ "de": "Die Anmeldung wurde nicht abgeschlossen. Schließen Sie die Anmeldung im Pop-up-Fenster ab und versuchen Sie es erneut.",
+ "fr": "La connexion n'a pas été terminée. Terminez la connexion dans la fenêtre contextuelle, puis réessayez.",
+ "it": "L'accesso non è stato completato. Completa l'accesso nella finestra pop-up, quindi riprova.",
+ "pt": "O login não foi concluído. Conclua o login na janela pop-up e tente novamente.",
+ "es": "El inicio de sesión no se completó. Completa el inicio de sesión en la ventana emergente e inténtalo de nuevo.",
+ "ca": "L'inici de sessió no s'ha completat. Completa l'inici de sessió a la finestra emergent i torna-ho a provar.",
+ "tr": "Oturum açma tamamlanmadı. Açılır pencerede oturum açmayı tamamlayın ve tekrar deneyin.",
+ "uk": "Вхід не завершено. Завершіть вхід у спливаючому вікні та спробуйте ще раз.",
+ "id": "Proses masuk belum selesai. Selesaikan proses masuk di jendela pop-up, lalu coba lagi."
+ },
"MCP$TEST_ERROR_CONNECTION": {
"en": "Could not reach the server (check the URL and server type): {{-error}}",
"ja": "サーバーに接続できませんでした(URLとサーバーの種類を確認してください): {{-error}}",
diff --git a/src/types/mcp-server.ts b/src/types/mcp-server.ts
index c63394ddc5..927bda0b9b 100644
--- a/src/types/mcp-server.ts
+++ b/src/types/mcp-server.ts
@@ -31,7 +31,11 @@ export interface MCPServerConfig {
export type MCPTestToolCall = AgentServerMCPToolCall;
export type MCPTestToolResult = AgentServerMCPToolCallResult;
-export type ExtendedMCPTestFailureKind = MCPTestFailureKind | "credentials";
+// `authorization`: the user did not finish an OAuth sign-in in time.
+export type ExtendedMCPTestFailureKind =
+ | MCPTestFailureKind
+ | "credentials"
+ | "authorization";
type GeneratedMCPTestSuccess = Extract<
AgentServerMCPTestResponse,
diff --git a/src/utils/mcp-test-error-message.ts b/src/utils/mcp-test-error-message.ts
index ab9e02a469..19c48a7caa 100644
--- a/src/utils/mcp-test-error-message.ts
+++ b/src/utils/mcp-test-error-message.ts
@@ -21,6 +21,8 @@ export function makeMcpTestErrorMessage(
switch (errorKind) {
case "timeout":
return t(I18nKey.MCP$TEST_ERROR_TIMEOUT);
+ case "authorization":
+ return t(I18nKey.MCP$TEST_ERROR_AUTHORIZATION);
case "connection":
return serverType === "stdio"
? t(I18nKey.MCP$TEST_ERROR_STDIO_START, { error })