Skip to content

Commit 8a062ba

Browse files
committed
fix(ui): gated toggle reads addon-config flag, not Policy.enabled (#966)
The per-tool 'security gated' toggle was grayed out even when the user had enable_tool_security_policies turned ON in the addon config + the Server Settings tab toggle, because the JS was reading Policy.enabled (the file field) instead of the addon-config feature flag — which is the single source of truth for whether the middleware is active. loadPolicyState now reads enable_tool_security_policies from /api/settings/features (same place renderFeatureFlags consumes from).
1 parent d093f67 commit 8a062ba

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

src/ha_mcp/settings_ui.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,19 +956,34 @@ def apply_tool_visibility(
956956
};
957957
958958
async function loadPolicyState() {
959+
// policyState.enabled mirrors the addon-config flag
960+
// (enable_tool_security_policies) — the single source of truth for
961+
// whether the middleware is active. Read it from /api/settings/features
962+
// (where it appears via FEATURE_FLAG_FIELDS) rather than Policy.enabled
963+
// in tool_policy.json, which has no UI surface and would always look
964+
// false even when the addon-config flag is on.
965+
try {
966+
const fresp = await fetch('./api/settings/features');
967+
if (fresp.ok) {
968+
const fdata = await fresp.json();
969+
const flag = (fdata.flags || {})['enable_tool_security_policies'];
970+
policyState.enabled = !!(flag && flag.value);
971+
} else {
972+
policyState.enabled = false;
973+
}
974+
} catch (_e) {
975+
policyState.enabled = false;
976+
}
959977
try {
960978
const r = await fetch('./api/policy/config');
961979
if (!r.ok) {
962-
policyState.enabled = false;
963980
policyState.gatedTools = new Set();
964981
return;
965982
}
966983
const p = await r.json();
967-
policyState.enabled = !!p.enabled;
968984
policyState.gatedTools = new Set((p.rules || []).map(rule => rule.tool_name));
969985
} catch (_e) {
970986
// Policy endpoint unavailable (sidecar stub) — leave gatedTools empty.
971-
policyState.enabled = false;
972987
policyState.gatedTools = new Set();
973988
}
974989
}

0 commit comments

Comments
 (0)