StackConfig¶
StackConfig
¶
Configuration container for MCPStack.
Holds logging configuration, environment variables, and computed paths used by tools and the MCP server.
Scope
Stores env vars and I/O paths used by tools and the MCP server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_level
|
str
|
Logging level name (e.g., |
'INFO'
|
env_vars
|
Optional[Dict[str, str]]
|
Mapping of environment variables to set/merge. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
log_level |
str
|
Active logging level. |
env_vars |
dict[str, str]
|
Environment variables tracked by the stack. |
project_root |
Path
|
Detected project root (see |
data_dir |
Path
|
Base data directory (see |
databases_dir |
Path
|
|
raw_files_dir |
Path
|
|
When is logging applied?
Logging is initialized and env_vars exported to os.environ during
construction via :meth:_apply_config.
Source code in src/MCPStack/core/config.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
from_dict(data)
classmethod
¶
Construct a :class:StackConfig from a mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
A mapping containing optional keys |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StackConfig |
StackConfig
|
New instance populated from |
Tip
Missing keys default to log_level="INFO" and an empty env_vars.
Source code in src/MCPStack/core/config.py
get_env_var(key, default=None, raise_if_missing=False)
¶
Retrieve an environment variable with fallback and validation.
Lookup order: self.env_vars[key] → os.getenv(key) → default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Environment variable name. |
required |
default
|
Optional[Any]
|
Value to return if not found in config or process env. |
None
|
raise_if_missing
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The resolved value, or |
Raises:
| Type | Description |
|---|---|
MCPStackConfigError
|
If |
Note
A debug log is emitted indicating whether the key was set or unset.
Source code in src/MCPStack/core/config.py
merge_env(new_env, prefix='')
¶
Merge environment variables with optional key prefix and conflict checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_env
|
Dict[str, str]
|
Mapping to merge into |
required |
prefix
|
str
|
String to preprend to each key (namespacing). |
''
|
Raises:
| Type | Description |
|---|---|
MCPStackConfigError
|
If a key exists with a different value. |
Namespacing
Use prefix (e.g., "MYTOOL_") to avoid collisions between tools.
Source code in src/MCPStack/core/config.py
to_dict()
¶
Serialize the configuration to a plain dictionary.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Any]
|
A shallow copy with |
Source code in src/MCPStack/core/config.py
validate_for_tools(tools)
¶
Ensure all tools' required environment variables are present.
Inspects each tool's required_env_vars (a mapping of name -> default)
and verifies that values are available via :meth:get_env_var. When a
default is None, the key is considered required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
|
List
|
Iterable of tool instances to validate against this config. |
required |
Raises:
| Type | Description |
|---|---|
MCPStackConfigError
|
Aggregated errors if any requirement is missing. |
Common pitfalls
- No value provided for a required key (
default=None). - Typos in environment variable names.
- Forgot to merge preset/tool-provided env.