{"record":{"id":"17f478d686e1c249","repo":"microsoft/aspire","slug":"the-global-mcp-approval-mode-is-not-supported","errorCode":null,"errorMessage":"The global MCP approval mode is not supported.","messagePattern":"The global MCP approval mode is not supported\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Toolbox/FoundryToolboxToolDefinition.cs","lineNumber":243,"sourceCode":"        if (policy.Global is not null && (always is not null || never is not null))\n        {\n            throw new ArgumentException(\n                \"A global MCP approval policy cannot be combined with custom filters.\",\n                nameof(policy));\n        }\n\n        if (policy.Global is null && always is null && never is null)\n        {\n            throw new ArgumentException(\n                \"An MCP approval policy must specify a global mode or at least one custom filter.\",\n                nameof(policy));\n        }\n\n        if (policy.Global is not null &&\n            policy.Global is not FoundryToolboxMcpGlobalApprovalMode.Never &&\n            policy.Global is not FoundryToolboxMcpGlobalApprovalMode.Always)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(policy),\n                policy.Global,\n                \"The global MCP approval mode is not supported.\");\n        }\n\n        var overlap = always?.ToolNames\n            .Intersect(never?.ToolNames ?? [], StringComparer.Ordinal)\n            .FirstOrDefault();\n        if (overlap is not null)\n        {\n            throw new ArgumentException(\n                $\"MCP tool '{overlap}' cannot both always and never require approval.\",\n                nameof(policy));\n        }\n\n        if (always?.ReadOnly is { } alwaysReadOnly && never?.ReadOnly == alwaysReadOnly)\n        {\n            throw new ArgumentException(","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Toolbox/FoundryToolboxToolDefinition.cs#L225-L261","documentation":"Only FoundryToolboxMcpGlobalApprovalMode.Never and .Always are valid global modes (they map to the wire values \"never\"/\"always\"). Any other enum member passed as Global fails this ArgumentOutOfRangeException at policy creation, before any JSON is emitted.","triggerScenarios":"Passing an enum value outside the Never/Always set as the policy's Global property — e.g. an undefined or future enum value, or a value cast from an integer.","commonSituations":"Binding Global from configuration or user input where an unvalidated integer/number was cast to the enum; SDK version changes adding enum members the integration doesn't support yet.","solutions":["Use FoundryToolboxMcpGlobalApprovalMode.Never or .Always only.","If the value comes from config/input, parse and validate it against the supported set before assigning.","Use Enum.IsDefined(typeof(FoundryToolboxMcpGlobalApprovalMode), value) plus a Never/Always check.","Catch ArgumentOutOfRangeException from policy creation and report the offending value."],"exampleFix":"// before\nvar mode = (FoundryToolboxMcpGlobalApprovalMode)request.RawValue;\npolicy.Global = mode;\n// after\nvar mode = request.RawValue is \"always\" ? FoundryToolboxMcpGlobalApprovalMode.Always : FoundryToolboxMcpGlobalApprovalMode.Never;\npolicy.Global = mode;","handlingStrategy":"validation","validationCode":"if (mode is not (FoundryToolboxMcpGlobalApprovalMode.Never or FoundryToolboxMcpGlobalApprovalMode.Always))\n    throw new ArgumentOutOfRangeException(nameof(mode), $\"Unsupported global mode {mode}.\");","typeGuard":"static bool IsSupportedMode(FoundryToolboxMcpGlobalApprovalMode m) =>\n    m is FoundryToolboxMcpGlobalApprovalMode.Never or FoundryToolboxMcpGlobalApprovalMode.Always;","tryCatchPattern":"try { toolDefinition = CreateMcpTool(...); }\ncatch (ArgumentOutOfRangeException ex)\n{ logger.LogError(ex, \"Global approval mode {Mode} is not supported; use Never or Always.\", mode); }","preventionTips":["Only assign the Never or Always enum members","Validate any enum values parsed from integers/config before assignment","Re-check supported modes after upgrading packages that own the enum"],"tags":["foundry","mcp","approval-policy","enum","argument-out-of-range","aspire"],"backgroundTag":"invalid-enum-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}