slave 0.13.1

CLI for slave, a Laravel-inspired Rust framework for MCP-first apps: scaffold an MCP backend with auth, roles, teams and SurrealDB migrations, add server-rendered web apps, and route them by domain or path
use slave_framework::database::DatabaseConfig;
use slave_framework::env;

/// Used when `APP_NAME` is not set.
const DEFAULT_NAME: &str = "{{ name }}";

/// Application settings, read from the environment (and `.env`, if present).
#[derive(Debug, Clone)]
pub struct Config {
    pub name: String,
    pub host: String,
    pub port: u16,
    /// The database (`SURREAL_URL`, `SURREAL_NS`, `SURREAL_DB`, ...).
    pub database: DatabaseConfig,
    /// `Host` header values the MCP endpoint accepts (DNS rebinding protection).
    pub mcp_allowed_hosts: Vec<String>,
}

impl Config {
    pub fn from_env() -> slave_framework::Result<Self> {
        Ok(Self {
            name: env::var_or("APP_NAME", DEFAULT_NAME),
            host: env::var_or("APP_HOST", "127.0.0.1"),
            port: env::parse_or("APP_PORT", 3000)?,
            database: DatabaseConfig::from_env()?,
            mcp_allowed_hosts: env::var_or("MCP_ALLOWED_HOSTS", "localhost,127.0.0.1,::1")
                .split(',')
                .map(str::trim)
                .filter(|host| !host.is_empty())
                .map(str::to_owned)
                .collect(),
        })
    }
}