Spaces:
Paused
Paused
| """Pure runtime-configuration policies used by the Space boot process.""" | |
| from __future__ import annotations | |
| from typing import Any | |
| def apply_optional_mcp_policy( | |
| config: dict[str, Any], | |
| *, | |
| linear_enabled: bool, | |
| linear_tokens_available: bool, | |
| unreal_enabled: bool, | |
| ) -> dict[str, Any]: | |
| """Park unavailable optional MCP entries without touching other servers. | |
| The returned dictionary describes what changed and why. ``config`` is | |
| mutated intentionally so the caller can persist the same authoritative | |
| state that every Hermes child process will subsequently load. | |
| """ | |
| result: dict[str, Any] = {"removed": [], "linear_unconfigured": False} | |
| servers = config.get("mcp_servers") | |
| if not isinstance(servers, dict): | |
| return result | |
| for name in list(servers): | |
| normalized = str(name).strip().lower() | |
| if normalized == "unreal-engine" and not unreal_enabled: | |
| servers.pop(name, None) | |
| result["removed"].append(str(name)) | |
| elif normalized == "linear": | |
| if not linear_enabled: | |
| servers.pop(name, None) | |
| result["removed"].append(str(name)) | |
| elif not linear_tokens_available: | |
| servers.pop(name, None) | |
| result["removed"].append(str(name)) | |
| result["linear_unconfigured"] = True | |
| return result | |