diff --git a/tests/test_setup.py b/tests/test_setup.py index 5e39fed..7730d7e 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -69,3 +69,22 @@ def test_settings_apply_runtime_config_updates_module_globals(): os.environ.pop("UNRAID_API_KEY", None) else: 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" diff --git a/unraid_mcp/server.py b/unraid_mcp/server.py index adac5cb..9c151c7 100644 --- a/unraid_mcp/server.py +++ b/unraid_mcp/server.py @@ -80,11 +80,10 @@ def run_server() -> None: # Validate required configuration before anything else is_valid, missing = validate_required_config() if not is_valid: - logger.critical( - f"Missing required configuration: {', '.join(missing)}. " - "Set these environment variables or add them to your .env file." + logger.warning( + f"Missing configuration: {', '.join(missing)}. " + "Server will prompt for credentials on first tool call via elicitation." ) - sys.exit(1) # Log configuration (delegated to shared function) from .config.logging import log_configuration_status