From 8a2f98b23cad5ad72d4c656d4489db5c21117c7f Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Tue, 10 Feb 2026 12:55:35 +0400 Subject: [PATCH] fix(mcp): Fix discover_tools test mock and credential auto-unselect - Add missing `refresh_if_needed` mock to test_discover_tools_auto_uses_stored_credential so it returns the stored credential instead of a MagicMock - Fix credential auto-unselect clearing MCP credentials on initial render: skip the "unselect if not available" check when the saved credentials list is empty (empty list means not loaded yet, not invalid) --- .../backend/backend/api/features/mcp/test_routes.py | 1 + .../contextual/CredentialsInput/useCredentialsInput.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/autogpt_platform/backend/backend/api/features/mcp/test_routes.py b/autogpt_platform/backend/backend/api/features/mcp/test_routes.py index 825931649d..92cc2f332b 100644 --- a/autogpt_platform/backend/backend/api/features/mcp/test_routes.py +++ b/autogpt_platform/backend/backend/api/features/mcp/test_routes.py @@ -108,6 +108,7 @@ class TestDiscoverTools: patch("backend.api.features.mcp.routes.creds_manager") as mock_cm, ): mock_cm.store.get_creds_by_provider = AsyncMock(return_value=[stored_cred]) + mock_cm.refresh_if_needed = AsyncMock(return_value=stored_cred) instance = MockClient.return_value instance.initialize = AsyncMock( return_value={"serverInfo": {}, "protocolVersion": "2025-03-26"} diff --git a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/useCredentialsInput.ts b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/useCredentialsInput.ts index 3ef594f5c2..715c6fbe60 100644 --- a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/useCredentialsInput.ts +++ b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/useCredentialsInput.ts @@ -88,11 +88,14 @@ export function useCredentialsInput({ } }, [credentials, onLoaded]); - // Unselect credential if not available + // Unselect credential if not available in the loaded credential list. + // Skip when no credentials have been loaded yet (empty list could mean + // the provider data hasn't finished loading, not that the credential is invalid). useEffect(() => { if (readOnly) return; if (!credentials || !("savedCredentials" in credentials)) return; const availableCreds = credentials.savedCredentials; + if (availableCreds.length === 0) return; if ( selectedCredential && !availableCreds.some((c) => c.id === selectedCredential.id)