From 4db27ca1123ecb1e2066aaea999ae6124b43be08 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Tue, 10 Feb 2026 11:25:06 +0400 Subject: [PATCH] fix(mcp): Auto-select credential and gracefully handle stale IDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Auto-select credential when exactly one match exists (even for optional fields). Only skip auto-select for optional fields with multiple choices. - In executor, catch ValueError from creds_manager.acquire() for optional credential fields — fall back to running without credentials instead of crashing when stale IDs reference deleted credentials. --- .../backend/backend/executor/manager.py | 16 +++++++++++++++- .../CredentialsInput/useCredentialsInput.ts | 4 +++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/autogpt_platform/backend/backend/executor/manager.py b/autogpt_platform/backend/backend/executor/manager.py index d58a9fae7c..317be53d55 100644 --- a/autogpt_platform/backend/backend/executor/manager.py +++ b/autogpt_platform/backend/backend/executor/manager.py @@ -280,7 +280,21 @@ async def execute_node( # Write normalized values back so JSON schema validation also passes # (model_validator may have fixed legacy formats like "ProviderName.MCP") input_data[field_name] = credentials_meta.model_dump(mode="json") - credentials, lock = await creds_manager.acquire(user_id, credentials_meta.id) + try: + credentials, lock = await creds_manager.acquire( + user_id, credentials_meta.id + ) + except ValueError: + # Credential was deleted or doesn't exist. + # If the field has a default, run without credentials. + if input_model.model_fields[field_name].default is not None: + log_metadata.warning( + f"Credentials #{credentials_meta.id} not found, " + "running without (field has default)" + ) + input_data[field_name] = input_model.model_fields[field_name].default + continue + raise creds_locks.append(lock) extra_exec_kwargs[field_name] = credentials diff --git a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/useCredentialsInput.ts b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/useCredentialsInput.ts index bc22c8c673..3ef594f5c2 100644 --- a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/useCredentialsInput.ts +++ b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/useCredentialsInput.ts @@ -117,7 +117,9 @@ export function useCredentialsInput({ if (hasAttemptedAutoSelect.current) return; hasAttemptedAutoSelect.current = true; - if (isOptional) return; + // Auto-select if exactly one credential matches. + // For optional fields with multiple options, let the user choose. + if (isOptional && savedCreds.length > 1) return; const cred = savedCreds[0]; onSelectCredential({