1919
2020
2121class ServerConfig (BaseModel ):
22+ """General server settings (name, transport, host/port, logging, drain)."""
23+
2224 name : str = "matlab-mcp-server"
2325 transport : Literal ["stdio" , "sse" ] = "stdio"
2426 host : str = "0.0.0.0"
@@ -30,6 +32,8 @@ class ServerConfig(BaseModel):
3032
3133
3234class PoolConfig (BaseModel ):
35+ """MATLAB engine pool sizing, timeouts, and auto-scaling thresholds."""
36+
3337 min_engines : int = 2
3438 max_engines : int = 10
3539 scale_down_idle_timeout : int = 900
@@ -41,6 +45,8 @@ class PoolConfig(BaseModel):
4145
4246
4347class ExecutionConfig (BaseModel ):
48+ """Code execution timeouts, workspace isolation, and temp directory."""
49+
4450 sync_timeout : int = 30
4551 max_execution_time : int = 86400
4652 workspace_isolation : bool = True
@@ -50,20 +56,28 @@ class ExecutionConfig(BaseModel):
5056
5157
5258class WorkspaceConfig (BaseModel ):
59+ """MATLAB workspace setup: default paths and startup commands."""
60+
5361 default_paths : List [str ] = Field (default_factory = list )
5462 startup_commands : List [str ] = Field (default_factory = lambda : ["format long" ])
5563
5664
5765class ToolboxesConfig (BaseModel ):
66+ """Toolbox visibility: whitelist, blacklist, or expose all."""
67+
5868 mode : Literal ["whitelist" , "blacklist" , "all" ] = "whitelist"
5969 list : List [str ] = Field (default_factory = list )
6070
6171
6272class CustomToolsConfig (BaseModel ):
73+ """Path to the YAML file defining user-provided custom MCP tools."""
74+
6375 config_file : str = "./custom_tools.yaml"
6476
6577
6678class SecurityConfig (BaseModel ):
79+ """Security controls: blocked MATLAB functions, upload limits, proxy auth."""
80+
6781 blocked_functions_enabled : bool = True
6882 blocked_functions : List [str ] = Field (
6983 default_factory = lambda : [
@@ -77,12 +91,16 @@ class SecurityConfig(BaseModel):
7791
7892
7993class CodeCheckerConfig (BaseModel ):
94+ """Code linting (checkcode/mlint) toggle and severity filter."""
95+
8096 enabled : bool = True
8197 auto_check_before_execute : bool = False
8298 severity_levels : List [str ] = Field (default_factory = lambda : ["error" , "warning" ])
8399
84100
85101class OutputConfig (BaseModel ):
102+ """Output formatting: Plotly conversion, image format, thumbnails, truncation."""
103+
86104 plotly_conversion : bool = True
87105 static_image_format : Literal ["png" , "jpg" , "svg" ] = "png"
88106 static_image_dpi : int = 150
@@ -93,12 +111,16 @@ class OutputConfig(BaseModel):
93111
94112
95113class SessionsConfig (BaseModel ):
114+ """Session limits, idle timeout, and finished-job retention."""
115+
96116 max_sessions : int = 50
97117 session_timeout : int = 3600
98118 job_retention_seconds : int = 86400
99119
100120
101121class MonitoringConfig (BaseModel ):
122+ """Monitoring subsystem: sampling interval, retention, DB path, dashboard."""
123+
102124 enabled : bool = True
103125 sample_interval : int = 10
104126 retention_days : int = 7
@@ -108,6 +130,12 @@ class MonitoringConfig(BaseModel):
108130
109131
110132class AppConfig (BaseModel ):
133+ """Top-level application configuration aggregating all sub-configs.
134+
135+ Relative filesystem paths are resolved to absolute paths via
136+ :meth:`resolve_paths` after loading.
137+ """
138+
111139 server : ServerConfig = Field (default_factory = ServerConfig )
112140 pool : PoolConfig = Field (default_factory = PoolConfig )
113141 execution : ExecutionConfig = Field (default_factory = ExecutionConfig )
@@ -125,6 +153,12 @@ class AppConfig(BaseModel):
125153
126154 @model_validator (mode = "after" )
127155 def validate_pool (self ) -> "AppConfig" :
156+ """Validate pool constraints after model construction.
157+
158+ Raises ``ValueError`` if ``min_engines > max_engines`` and emits a
159+ warning on macOS when ``max_engines > 4`` due to known stability
160+ limitations.
161+ """
128162 if self .pool .min_engines > self .pool .max_engines :
129163 raise ValueError (
130164 f"pool.min_engines ({ self .pool .min_engines } ) must not exceed "
@@ -191,7 +225,10 @@ def _apply_env_overrides(data: dict) -> dict:
191225def load_config (path : Optional [Path ] = None ) -> AppConfig :
192226 """Load application config from a YAML file with env var overrides.
193227
194- If *path* is None or the file does not exist, default values are used.
228+ If *path* is ``None`` or the file does not exist, default values are
229+ used. After parsing, ``MATLAB_MCP_*`` environment variables are
230+ applied (see :func:`_apply_env_overrides`) and relative paths are
231+ resolved against the config file's parent directory.
195232 """
196233 data : dict = {}
197234 config_dir = Path .cwd ()
0 commit comments