forked from HomeLab/unraid-mcp
feat(elicitation): degrade gracefully when credentials are missing at startup
This commit is contained in:
@@ -69,3 +69,22 @@ def test_settings_apply_runtime_config_updates_module_globals():
|
|||||||
os.environ.pop("UNRAID_API_KEY", None)
|
os.environ.pop("UNRAID_API_KEY", None)
|
||||||
else:
|
else:
|
||||||
os.environ["UNRAID_API_KEY"] = original_env_key
|
os.environ["UNRAID_API_KEY"] = original_env_key
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_server_does_not_exit_when_creds_missing(monkeypatch):
|
||||||
|
"""Server should not sys.exit(1) when credentials are absent."""
|
||||||
|
import unraid_mcp.config.settings as settings_mod
|
||||||
|
|
||||||
|
monkeypatch.setattr(settings_mod, "UNRAID_API_URL", None)
|
||||||
|
monkeypatch.setattr(settings_mod, "UNRAID_API_KEY", None)
|
||||||
|
|
||||||
|
# Patch the actual mcp.run so we don't spin up a real server
|
||||||
|
from unraid_mcp import server as server_mod
|
||||||
|
|
||||||
|
with patch.object(server_mod, "mcp") as mock_mcp:
|
||||||
|
mock_mcp.run.side_effect = SystemExit(0)
|
||||||
|
try:
|
||||||
|
server_mod.run_server()
|
||||||
|
except SystemExit as e:
|
||||||
|
# Only the mocked mcp.run exit (code 0) is acceptable
|
||||||
|
assert e.code == 0, f"Unexpected sys.exit({e.code}) — server crashed on missing creds"
|
||||||
|
|||||||
@@ -80,11 +80,10 @@ def run_server() -> None:
|
|||||||
# Validate required configuration before anything else
|
# Validate required configuration before anything else
|
||||||
is_valid, missing = validate_required_config()
|
is_valid, missing = validate_required_config()
|
||||||
if not is_valid:
|
if not is_valid:
|
||||||
logger.critical(
|
logger.warning(
|
||||||
f"Missing required configuration: {', '.join(missing)}. "
|
f"Missing configuration: {', '.join(missing)}. "
|
||||||
"Set these environment variables or add them to your .env file."
|
"Server will prompt for credentials on first tool call via elicitation."
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Log configuration (delegated to shared function)
|
# Log configuration (delegated to shared function)
|
||||||
from .config.logging import log_configuration_status
|
from .config.logging import log_configuration_status
|
||||||
|
|||||||
Reference in New Issue
Block a user