pub struct ConfigManager { /* private fields */ }Expand description
§Lock Ordering Invariant
To prevent deadlock, ALL methods acquiring multiple locks MUST respect this canonical ordering:
1. reload_mutex (coarse-grained serialization)
2. config (fine-grained data access)CRITICAL: Never hold config write lock while requesting reload_mutex.
§Atomic Operation Ordering
Atomic operations follow happens-before relationships:
set_value() → increment generation → send SaveRequest
↓
background_saver receives → read config + generation → write diskSequential consistency (Ordering::SeqCst) ensures all threads see
generation increments in the same order.
§Concurrent Safety
config: RwLock allows multiple concurrent readers, single writergeneration: AtomicU64 provides lock-free incrementsaving: AtomicBool prevents file watcher self-triggerreload_mutex: Serializes reload operationssave_sender: UnboundedSender is lock-free
Implementations§
Source§impl ConfigManager
impl ConfigManager
pub fn new() -> Self
Sourcepub async fn init(&self) -> Result<(), McpError>
pub async fn init(&self) -> Result<(), McpError>
Initialize configuration from disk and environment variables
§Errors
Returns error if config directory cannot be created or config file cannot be read/written
Sourcepub async fn reload(&self) -> Result<(), McpError>
pub async fn reload(&self) -> Result<(), McpError>
Reload configuration from disk
Re-reads the config file and updates in-memory state. Serialized with mutex to prevent concurrent reloads (Race #3). Uses the same recovery cascade as init() to handle corruption. Environment variable overrides (KODEGEN_ALLOWED_DIRS, KODEGEN_DENIED_DIRS) are preserved and re-applied after loading.
§Errors
Returns error if config file cannot be read or parsed
Sourcepub async fn enable_file_watching(&mut self) -> Result<(), McpError>
pub async fn enable_file_watching(&mut self) -> Result<(), McpError>
Enable automatic config file watching
Starts monitoring the config file for changes. When changes are detected
(after 1-second debounce), automatically calls reload().
This is optional and should be enabled via CLI flag (e.g., --watch-config).
§Errors
Returns error if file watching cannot be initialized
pub fn get_config(&self) -> ServerConfig
pub fn get_file_read_line_limit(&self) -> usize
pub fn get_file_write_line_limit(&self) -> usize
pub fn get_blocked_commands(&self) -> Vec<String>
pub fn get_fuzzy_search_threshold(&self) -> f64
pub fn get_http_connection_timeout_secs(&self) -> u64
pub fn get_path_validation_timeout_ms(&self) -> u64
pub fn get_value(&self, key: &str) -> Option<ConfigValue>
Sourcepub async fn set_value(
&self,
key: &str,
value: ConfigValue,
) -> Result<(), McpError>
pub async fn set_value( &self, key: &str, value: ConfigValue, ) -> Result<(), McpError>
Set a configuration value by key
Thread-safe with generation tracking to prevent lost updates. Increments generation counter atomically after modification.
§Errors
Returns error if the key is unknown, value type is invalid, or config cannot be saved
Sourcepub async fn set_client_info(&self, client_info: ClientInfo)
pub async fn set_client_info(&self, client_info: ClientInfo)
Store client information from MCP initialization
Updates in-memory state immediately and queues async save to disk.
Disk write errors are logged but not propagated (fire-and-forget pattern).
Use get_save_error_count() to check for save failures.
Sourcepub fn get_client_info(&self) -> Option<ClientInfo>
pub fn get_client_info(&self) -> Option<ClientInfo>
Get current client information
Sourcepub fn get_client_history(&self) -> Vec<ClientRecord>
pub fn get_client_history(&self) -> Vec<ClientRecord>
Get client connection history
Sourcepub fn get_save_error_count() -> usize
pub fn get_save_error_count() -> usize
Get total count of config save failures since server start
This counter tracks background save failures (disk write errors). Used for observability and monitoring config persistence issues.
Trait Implementations§
Source§impl Clone for ConfigManager
impl Clone for ConfigManager
Source§fn clone(&self) -> ConfigManager
fn clone(&self) -> ConfigManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more