pub struct Config {
pub schema_path: Option<PathBuf>,
pub db_path: Option<PathBuf>,
pub user_dir: Option<PathBuf>,
pub project_dir: Option<PathBuf>,
pub backup_retention: Option<usize>,
pub snapshot_retention: Option<usize>,
}Expand description
Runtime configuration for the mini-app-mcp server.
Constructed exclusively via Config::load; there is no public constructor
so callers always go through the validated loading path.
§Fields
schema_path/db_path: legacy single-table paths (set whenMINI_APP_SCHEMAandMINI_APP_DBare present).user_dir: base directory for User-scope tables (~/.mini-app/by default, overridden byMINI_APP_USER_DIR).project_dir: override directory for Project-scope tables (./.mini-app/by default, overridden byMINI_APP_PROJECT_DIR).
Fields§
§schema_path: Option<PathBuf>Path to the schema.yaml file that defines the table’s field schema.
Set via the MINI_APP_SCHEMA environment variable.
None when only directory-based multi-table configuration is used.
db_path: Option<PathBuf>Path to the SQLite database file.
Set via the MINI_APP_DB environment variable.
None when only directory-based multi-table configuration is used.
user_dir: Option<PathBuf>Base directory for User-scope table definitions.
Defaults to ~/.mini-app/ when MINI_APP_USER_DIR is not set.
Each subdirectory <table>/ is expected to contain schema.yaml and
<table>.db.
project_dir: Option<PathBuf>Override directory for Project-scope table definitions.
Defaults to ./.mini-app/ (current working directory) when
MINI_APP_PROJECT_DIR is not set.
Same subdirectory layout as user_dir; Project entries override
User entries with the same table name (file-level swap, not
field-level merge).
backup_retention: Option<usize>Number of backup pairs ({table}.{ts}.yaml + {table}.{ts}.db) to
retain in _backup/ before the oldest are purged.
Defaults to 10 when MINI_APP_BACKUP_RETENTION is not set.
Set via the MINI_APP_BACKUP_RETENTION environment variable
(must be a positive integer; non-parsable values are silently ignored
and the default of 10 is used).
snapshot_retention: Option<usize>Number of snapshot files ({table}.{ts}.db) to retain in _snapshots/
before the oldest are purged.
Defaults to 10 when MINI_APP_SNAPSHOT_RETENTION is not set.
Set via the MINI_APP_SNAPSHOT_RETENTION environment variable
(must be a positive integer; non-parsable values are silently ignored
and the default of 10 is used).
This field is intentionally separate from backup_retention to enforce
the snapshot retention isolation Crux constraint: snapshot and backup
lifecycles are managed independently.
Implementations§
Source§impl Config
impl Config
Sourcepub fn load() -> Result<Self, MiniAppError>
pub fn load() -> Result<Self, MiniAppError>
Load configuration from the environment.
Attempts to read .mini-app-mcp.env from the current directory first
(via dotenvy). Variables already set in the process environment take
precedence over values from the file (dotenvy’s default behaviour).
§Environment variables
| Variable | Required | Description |
|---|---|---|
MINI_APP_SCHEMA | Legacy mode only | Path to schema.yaml |
MINI_APP_DB | Legacy mode only | Path to the SQLite database file |
MINI_APP_USER_DIR | Optional | User-scope table directory (default ~/.mini-app/) |
MINI_APP_PROJECT_DIR | Optional | Project-scope table directory (default ./.mini-app/) |
MINI_APP_BACKUP_RETENTION | Optional | Number of backup pairs to keep (default 10) |
MINI_APP_SNAPSHOT_RETENTION | Optional | Number of snapshot files to keep (default 10) |
At least one of the legacy pair (MINI_APP_SCHEMA + MINI_APP_DB) or
a directory env must resolve to a usable table configuration. When
neither legacy env vars nor a discoverable directory exist the server
can still start (directory scan skips missing dirs with a warning).
§Returns
A Config on success. The presence of legacy fields vs directory
fields determines which mode the server operates in.
§Errors
Returns MiniAppError::Config only if an env var is present but
cannot be read (which is unusual — the standard env API only fails on
invalid UTF-8). Does not panic.
Sourcepub fn has_legacy_env(&self) -> bool
pub fn has_legacy_env(&self) -> bool
Returns true when both legacy single-table env vars (MINI_APP_SCHEMA
and MINI_APP_DB) are present in this config.
§Returns
true if and only if both schema_path and db_path are Some.
Sourcepub fn backup_retention(&self) -> usize
pub fn backup_retention(&self) -> usize
Returns the number of backup pairs to keep per table.
Uses the value of backup_retention when set, otherwise defaults to
10. This default is documented in MINI_APP_BACKUP_RETENTION.
§Returns
The retention limit as a usize. Always at least 1 (a value of 0
would delete all backups on every write).
Sourcepub fn snapshot_retention(&self) -> usize
pub fn snapshot_retention(&self) -> usize
Returns the number of snapshot files to keep per table.
Uses the value of snapshot_retention when set, otherwise defaults to
10. This default is documented in MINI_APP_SNAPSHOT_RETENTION.
This getter is intentionally separate from backup_retention to
enforce snapshot retention isolation: snapshot and backup lifecycles are
managed via independent environment variables and independent retention
counters (Crux: snapshot retention isolation).
§Returns
The retention limit as a usize. Always at least 1 (a value of 0
would delete all snapshots on every write).