Skip to content
Open
20 changes: 19 additions & 1 deletion packages/a2a-server/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ export async function loadConfig(
}
}

// Admin settings should be able to override existing mcpEnablement settings
// and extensionEnabled settings.
// By default, these should be undefined if not set by an admin so as to not
// override any existing defaults.
const getAdminBooleanOverride = (envVar: string): boolean | undefined => {
const value = process.env[envVar];
return value !== undefined ? value === 'true' : undefined;
};

const mcpEnabledAdminOverride = getAdminBooleanOverride('MCP_ADMIN_ENABLED');
const extensionsEnabledAdminOverride = getAdminBooleanOverride(
'EXTENSIONS_ADMIN_ENABLED',
);
const secureModeAdminEnabled =
getAdminBooleanOverride('SECURE_MODE_ADMIN_ENABLED') === true;

const configParams: ConfigParameters = {
sessionId: taskId,
model: settings.general?.previewFeatures
Expand All @@ -70,9 +86,11 @@ export async function loadConfig(
excludeTools: settings.excludeTools || undefined,
showMemoryUsage: settings.showMemoryUsage || false,
approvalMode:
process.env['GEMINI_YOLO_MODE'] === 'true'
process.env['GEMINI_YOLO_MODE'] === 'true' && !secureModeAdminEnabled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Gemini CLI if YOLO mode is disabled but this is passed anyway we throw a FatalConfigErrro.

Can we just do a logger.warn() here. WE shouldn't fail but we should log

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for raising this point, @adamfweidman. I understand your concern about the FatalConfigError in the Gemini CLI when YOLO mode is unexpectedly disabled. While the a2a-server itself doesn't throw an error in this scenario, it's indeed a good practice to inform the user if their GEMINI_YOLO_MODE setting is being overridden by secureModeAdminEnabled.

To improve clarity and prevent potential confusion for users, I suggest adding a logger.warn() message when GEMINI_YOLO_MODE is set to true but the effective approvalMode becomes DEFAULT due to secureModeAdminEnabled. This would provide valuable feedback without causing a fatal error.

Here's how the relevant section could be updated:

    excludeTools: settings.excludeTools || undefined,
    showMemoryUsage: settings.showMemoryUsage || false,
    approvalMode: (() => {
      const isYoloModeRequested = process.env['GEMINI_YOLO_MODE'] === 'true';
      const effectiveApprovalMode =
        isYoloModeRequested && !secureModeAdminEnabled
          ? ApprovalMode.YOLO
          : ApprovalMode.DEFAULT;

      if (isYoloModeRequested && effectiveApprovalMode === ApprovalMode.DEFAULT) {
        logger.warn(
          'GEMINI_YOLO_MODE is enabled, but it is being overridden by secureModeAdminEnabled.',
        );
      }
      return effectiveApprovalMode;
    })(),

This change would ensure that users are aware of the override, aligning with the principle of providing clear feedback.
Severity: medium

Suggested change
process.env['GEMINI_YOLO_MODE'] === 'true' && !secureModeAdminEnabled
null

? ApprovalMode.YOLO
: ApprovalMode.DEFAULT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there an explicit disableYoloMode setting which we should also set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a bit confusing in the current state but both disableYoloMode and secureModeEnabled end up resulting in the same behavior- secure mode enabled corresponds to the admin setting (I wanted to nest all admin settings under the same obj so I didn't reuse disableYoloMode)

mcpEnabled: mcpEnabledAdminOverride,
extensionsEnabled: extensionsEnabledAdminOverride,
mcpServers: settings.mcpServers,
cwd: workspaceDir,
telemetry: {
Expand Down
Loading