Skip to main content

Config

Struct Config 

Source
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 when MINI_APP_SCHEMA and MINI_APP_DB are present).
  • user_dir: base directory for User-scope tables (~/.mini-app/ by default, overridden by MINI_APP_USER_DIR).
  • project_dir: override directory for Project-scope tables (./.mini-app/ by default, overridden by MINI_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

Source

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
VariableRequiredDescription
MINI_APP_SCHEMALegacy mode onlyPath to schema.yaml
MINI_APP_DBLegacy mode onlyPath to the SQLite database file
MINI_APP_USER_DIROptionalUser-scope table directory (default ~/.mini-app/)
MINI_APP_PROJECT_DIROptionalProject-scope table directory (default ./.mini-app/)
MINI_APP_BACKUP_RETENTIONOptionalNumber of backup pairs to keep (default 10)
MINI_APP_SNAPSHOT_RETENTIONOptionalNumber 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.

Source

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.

Source

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).

Source

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).

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more