@@ -121,17 +121,20 @@ impl Default for ReferenceConfig {
121
121
122
122
// Example function to load config (will be used in main.rs)
123
123
pub fn load_config ( ) -> Result < McpConfig > {
124
- // Support MCP_CONFIG_PATH env var for config file path
125
- let config_path_env = std:: env:: var ( "MCP_CONFIG_PATH" ) . ok ( ) ;
126
- let config_path = config_path_env. clone ( ) . unwrap_or_else ( || "mcp_config.toml" . to_string ( ) ) ;
127
-
128
- if let Some ( ref env_path) = config_path_env {
129
- if !std:: path:: Path :: new ( env_path) . exists ( ) {
130
- return Err ( anyhow:: anyhow!( "Config file not found at MCP_CONFIG_PATH: {}" , env_path) ) ;
131
- }
132
- log:: info!( "MCP_CONFIG_PATH is set: {}" , env_path) ;
124
+ // Always use MC_PROJECT_ROOT for config path
125
+ let project_root = std:: env:: var ( "MC_PROJECT_ROOT" )
126
+ . map_err ( |_| anyhow:: anyhow!( "MC_PROJECT_ROOT is not set. Please set MC_PROJECT_ROOT to your project root directory." ) ) ?;
127
+ let project_root_path = std:: path:: Path :: new ( & project_root) ;
128
+ if !project_root_path. exists ( ) {
129
+ return Err ( anyhow:: anyhow!( "MC_PROJECT_ROOT does not exist: {}" , project_root) ) ;
130
+ }
131
+ let config_path = project_root_path. join ( "mcp_config.toml" ) ;
132
+ let config_file_exists = config_path. exists ( ) ;
133
+ if config_file_exists {
134
+ log:: info!( "MC_PROJECT_ROOT is set: {}" , project_root_path. display( ) ) ;
135
+ log:: info!( "Loading config from: {}" , config_path. display( ) ) ;
133
136
} else {
134
- log:: info !( "MCP_CONFIG_PATH not set, falling back to default : {}" , config_path) ;
137
+ log:: warn !( "Config file not found at : {}. Using defaults. " , config_path. display ( ) ) ;
135
138
}
136
139
// Use ReferenceConfig::default() to get defaults including calculated paths
137
140
let default_config = McpConfig {
@@ -140,13 +143,13 @@ pub fn load_config() -> Result<McpConfig> {
140
143
setup : SetupConfig :: default ( ) ,
141
144
} ;
142
145
143
- let figment = Figment :: new ( )
146
+ let mut figment = Figment :: new ( )
144
147
// Start with our programmatically defined defaults
145
- . merge ( Serialized :: defaults ( default_config) ) // Use our instance
146
- // Merge TOML file if it exists
147
- . merge ( Toml :: file ( & config_path) )
148
- // Merge environment variables prefixed with MCP_
149
- . merge ( Env :: prefixed ( "MCP_" ) . split ( "__" ) ) ;
148
+ . merge ( Serialized :: defaults ( default_config) ) ; // Use our instance
149
+ if config_file_exists {
150
+ figment = figment . merge ( Toml :: file ( & config_path) ) ;
151
+ }
152
+ figment = figment . merge ( Env :: prefixed ( "MCP_" ) . split ( "__" ) ) ;
150
153
151
154
let config: McpConfig = figment. extract ( ) . context ( "Failed to extract McpConfig" ) ?;
152
155
validate_config ( & config) ?;
0 commit comments